B
BartC
I know this is considered off-topic but perhaps someone's got some ideas.
I have a struct like this with elements all packed:
#pragma pack(1)
typedef struct s {
short int a;
char b;
char c;
int d;
} V;
V *p;
When using gcc to access the field p->d, then it seems to assume that it's
an unaligned access (and generates atrocious code which loads or stores the
field a byte at a time). The offset of 'd' is 4 bytes.
The problem goes away when pack(1) is removed (even though the possibility
of p being misaligned, if that's what it's worried about, is the same).
This is for an ARM processor where alignment seems to be important, but
which already has performance issues. Perhaps there is a gcc option to turn
off this behaviour?
(I think a workaround is to not use pack(1) since I already define the
fields optimally - in my view. But I need to ensure no extra padding is
inserted in the the actual struct which is much more complex than the
example.)
Thanks.
I have a struct like this with elements all packed:
#pragma pack(1)
typedef struct s {
short int a;
char b;
char c;
int d;
} V;
V *p;
When using gcc to access the field p->d, then it seems to assume that it's
an unaligned access (and generates atrocious code which loads or stores the
field a byte at a time). The offset of 'd' is 4 bytes.
The problem goes away when pack(1) is removed (even though the possibility
of p being misaligned, if that's what it's worried about, is the same).
This is for an ARM processor where alignment seems to be important, but
which already has performance issues. Perhaps there is a gcc option to turn
off this behaviour?
(I think a workaround is to not use pack(1) since I already define the
fields optimally - in my view. But I need to ensure no extra padding is
inserted in the the actual struct which is much more complex than the
example.)
Thanks.