Le dimanche 13 février 2011 à 10:24 +0200, Blue Swirl a écrit : > On Sun, Feb 13, 2011 at 4:22 AM, Laurent Vivier <laur...@vivier.eu> wrote: > > Datatype alignment can be found using following application: > > > > int main(void) > > { > > printf("alignof(short) %ld\n", __alignof__(short)); > > printf("alignof(int) %ld\n", __alignof__(int)); > > printf("alignof(long) %ld\n", __alignof__(long)); > > printf("alignof(long long) %ld\n", __alignof__(long long)); > > } > > > > This patch includes following alignments: > > > > i386 > > > > alignof(short) 2 > > alignof(int) 4 > > alignof(long) 4 > > alignof(long long) 8 > > > > x86_64 > > > > alignof(short) 2 > > alignof(int) 4 > > alignof(long) 8 > > alignof(long long) 8 > > > > arm > > > > alignof(short) 2 > > alignof(int) 4 > > alignof(long) 4 > > alignof(long long) 4 > > > > m68k (680x0) > > > > alignof(short) 2 > > alignof(int) 2 > > alignof(long) 2 > > alignof(long long) 2 > > > > mips > > > > alignof(short) 2 > > alignof(int) 4 > > alignof(long) 4 > > alignof(long long) 8 > > > > ppc > > > > alignof(short) 2 > > alignof(int) 4 > > alignof(long) 4 > > alignof(long long) 8 > > > > for other targets, use by default (2,4,4,8). > > > > Please, update for your favorite target... > > For Sparc32 (I think also sparc32plus), the default is OK. > > For Sparc64, please use 2, 4, 8, 8. I'd guess other 64 bit platforms > (Alpha, MIPS64, PPC64 etc) should use the same.
OK, I update my patch. > Does GCC produce correct code using the attributes on strictly aligned > host, when the target is less strictly aligned? It seems it is OK. I did some tests into a mips-linux-user chroot (sparc one is broken ;-) ) : mips is a strictly aligned host, from gcc/config/mips/mips.h: #define STRICT_ALIGNMENT 1 aligments are: alignof(short) 2 alignof(int) 4 alignof(long) 4 alignof(long long) 8 We try to align int on 2. #include <stdio.h> typedef int target_int __attribute__((aligned(2))); struct { char Z; target_int A; } B; int main(void) { B.A = 0xdeadbeaf; printf("%d: %x\n", __alignof__(B.A), B.A); } ./test_align 2: deadbeaf disass: lw $2,%got(B)($28) li $3,-559087616 # 0xffffffffdead0000 ori $3,$3,0xbeaf swl $3,2($2) swr $3,5($2) normal case: lw $3,%got(B)($28) li $2,-559087616 # 0xffffffffdead0000 ori $2,$2,0xbeaf sw $2,4($3) So, gcc seems smart enough to split the memory access in several ones compatible with the strict alignment rules. > Should the alignment of floating point variables be specified as well? At the moment it seems useless. > The strict alignment required for doubles is 4, but recommended > alignment is 8, I'm not sure which one is used for structures > containing doubles. if necessary, some tests will be helpfull. Thank you for your comments. Regards, Laurent -- --------------------- laur...@vivier.eu ---------------------- "Tout ce qui est impossible reste à accomplir" Jules Verne "Things are only impossible until they're not" Jean-Luc Picard