Enhance struct pointer access, by placing scalars at the beginning and arrays as sub-sequent struct members.
Thumb2 instructions encode a limited displacement for memory access. When a struct is accessed via a pointer, scalar variables at the beginning of a struct can be directly accessed. Arrays always require address calculations. Therefore, it is more efficient to place scalar variables at the beginning of a struct
-------------------------------------------------------------------------------------- Frankly speaking, I don't understand above form uvision4 tutorial. English is not my native language.
anybody can help explain its details? why scalar variables at the beginning of a struct will bring more efficiency? Thank you very much.
typedef struct { int x; int arr[10]; } sx; int f (sx xdata *sp, int i) { return sp->arr[i]; }
BR,
Sorry, I'm a bit tired today. For thumb-2 mode, you normally have a limit of +255 instead of +4095. And array indexing can only scale with left-shift 0 to 3 steps, i.e. 1, 2, 4 and 8 byte large array entries can be quick-accessed.
Hi Per Westermark,
Thank you very much.
Fisher