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,
Hi Per Westermark,
Thanks a lot for your help. I know about what you says.
I have 2 addition questions, could you please help me?
(1)what is the max offset allowed which disable complier to switch to more complex addressing methods when scalars is at the beginning of Struct? how many bytes?
(2)where such description document can be found ?
thanks.
Fisher
infocenter.arm.com/.../QRC0001_UAL.pdf
Page 4 have load and store instructions, and mentions sizes of offsets. So many load/store operations have +/- 4095 as max offset.
Full description of all instructions can be found directly from infocenter.arm.com
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.
Thank you very much.