On Wed, Jan 7, 2009 at 8:30 AM, Ian Lance Taylor <i...@google.com> wrote: > "H.J. Lu" <hjl.to...@gmail.com> writes: > >> Fixing BIGGEST_ALIGNMENT to 16 may require extensive changes. >> I am thinking to add DEFAULT_ALIGNMENT with >> >> #ifndef DEFAULT_ALIGNMENT >> #define DEFAULT_ALIGNMENT BIGGEST_ALIGNMENT >> #endif >> >> and use it only for attribute((aligned)). > > This does need to be done, but DEFAULT_ALIGNMENT is a poorly chosen > name. It should be something more like ATTRIBUTE_ALIGNED_VALUE. > > Ian >
Here is a patch to implement ATTRIBUTE_ALIGNED_VALUE. OK for trunk? Thanks. -- H.J. --- gcc/ 2009-01-07 H.J. Lu <hongjiu...@intel.com> PR target/38736 * c-common.c (handle_aligned_attribute): Use ATTRIBUTE_ALIGNED_VALUE instead of ATTRIBUTE_ALIGNED_VALUE for default alignment value. * defaults.h (ATTRIBUTE_ALIGNED_VALUE): New. * config/i386/i386.h (ATTRIBUTE_ALIGNED_VALUE): Likewise. * doc/extend.texi: Update __attribute__ ((aligned)) with ATTRIBUTE_ALIGNED_VALUE. * doc/tm.texi: Document ATTRIBUTE_ALIGNED_VALUE. gcc/testsuite/ 2009-01-07 H.J. Lu <hongjiu...@intel.com> PR target/38736 * g++.dg/other/pr38736-1.C: New. * g++.dg/other/pr38736-2.C: Likewise. * gcc.target/i386/pr38736-1.c: Likewise. * gcc.target/i386/pr38736-2.c: Likewise.
gcc/ 2009-01-07 H.J. Lu <hongjiu...@intel.com> PR target/38736 * c-common.c (handle_aligned_attribute): Use ATTRIBUTE_ALIGNED_VALUE instead of ATTRIBUTE_ALIGNED_VALUE for default alignment value. * defaults.h (ATTRIBUTE_ALIGNED_VALUE): New. * config/i386/i386.h (ATTRIBUTE_ALIGNED_VALUE): Likewise. * doc/extend.texi: Update __attribute__ ((aligned)) with ATTRIBUTE_ALIGNED_VALUE. * doc/tm.texi: Document ATTRIBUTE_ALIGNED_VALUE. gcc/testsuite/ 2009-01-07 H.J. Lu <hongjiu...@intel.com> PR target/38736 * g++.dg/other/pr38736-1.C: New. * g++.dg/other/pr38736-2.C: Likewise. * gcc.target/i386/pr38736-1.c: Likewise. * gcc.target/i386/pr38736-2.c: Likewise. Index: gcc/doc/extend.texi =================================================================== --- gcc/doc/extend.texi (revision 4884) +++ gcc/doc/extend.texi (working copy) @@ -3697,9 +3697,8 @@ that forces the union to be double-word As in the preceding examples, you can explicitly specify the alignment (in bytes) that you wish the compiler to use for a given variable or structure field. Alternatively, you can leave out the alignment factor -and just ask the compiler to align a variable or field to the maximum -useful alignment for the target machine you are compiling for. For -example, you could write: +and use @code{ATTRIBUTE_ALIGNED_VALUE} for the target machine you are +compiling for. For example, you could write: @smallexample short array[3] __attribute__ ((aligned)); @@ -3707,11 +3706,11 @@ short array[3] __attribute__ ((aligned)) Whenever you leave out the alignment factor in an @code{aligned} attribute specification, the compiler automatically sets the alignment for the declared -variable or field to the largest alignment which is ever used for any data -type on the target machine you are compiling for. Doing this can often make -copy operations more efficient, because the compiler can use whatever -instructions copy the biggest chunks of memory when performing copies to -or from the variables or fields that you have aligned this way. +variable or field to @code{ATTRIBUTE_ALIGNED_VALUE}. Doing this can +often make copy operations more efficient, because the compiler can use +whatever instructions copy the biggest chunks of memory aligned at +...@code{attribute_aligned_value} when performing copies to or from the +variables or fields that you have aligned this way. When used on a struct, or struct member, the @code{aligned} attribute can only increase the alignment; in order to decrease it, the @code{packed} Index: gcc/doc/tm.texi =================================================================== --- gcc/doc/tm.texi (revision 4884) +++ gcc/doc/tm.texi (working copy) @@ -1105,6 +1105,11 @@ Alignment, in bits, a C conformant mallo provide. If not defined, the default value is @code{BITS_PER_WORD}. @end defmac +...@defmac ATTRIBUTE_ALIGNED_VALUE +Alignment used by the @code{__attribute__ ((aligned))} construct. If +not defined, the default value is @code{BIGGEST_ALIGNMENT}. +...@end defmac + @defmac MINIMUM_ATOMIC_ALIGNMENT If defined, the smallest alignment, in bits, that can be given to an object that can be referenced in one operation, without disturbing any Index: gcc/defaults.h =================================================================== --- gcc/defaults.h (revision 4884) +++ gcc/defaults.h (working copy) @@ -944,4 +944,9 @@ along with GCC; see the file COPYING3. ((TYPE) ? LOCAL_ALIGNMENT ((TYPE), (ALIGN)) : (ALIGN)) #endif +/* Alignment value for attribute ((aligned)). */ +#ifndef ATTRIBUTE_ALIGNED_VALUE +#define ATTRIBUTE_ALIGNED_VALUE BIGGEST_ALIGNMENT +#endif + #endif /* ! GCC_DEFAULTS_H */ Index: gcc/testsuite/gcc.target/i386/pr38736-2.c =================================================================== --- gcc/testsuite/gcc.target/i386/pr38736-2.c (revision 0) +++ gcc/testsuite/gcc.target/i386/pr38736-2.c (revision 0) @@ -0,0 +1,19 @@ +/* PR target/38736 */ +/* { dg-do run } */ +/* { dg-require-effective-target avx } */ +/* { dg-options "-O2 -mavx" } */ + +extern void abort (void); + +struct alignment_test_struct +{ + char space[4] __attribute__((__aligned__)); +}; + +int +main () +{ + if (__alignof__(struct alignment_test_struct) != 16) + abort (); + return 0; +} Index: gcc/testsuite/gcc.target/i386/pr38736-1.c =================================================================== --- gcc/testsuite/gcc.target/i386/pr38736-1.c (revision 0) +++ gcc/testsuite/gcc.target/i386/pr38736-1.c (revision 0) @@ -0,0 +1,18 @@ +/* PR target/38736 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +extern void abort (void); + +struct alignment_test_struct +{ + char space[4] __attribute__((__aligned__)); +}; + +int +main () +{ + if (__alignof__(struct alignment_test_struct) != 16) + abort (); + return 0; +} Index: gcc/testsuite/g++.dg/other/pr38736-2.C =================================================================== --- gcc/testsuite/g++.dg/other/pr38736-2.C (revision 0) +++ gcc/testsuite/g++.dg/other/pr38736-2.C (revision 0) @@ -0,0 +1,19 @@ +/* PR target/38736 */ +/* { dg-do run { target i?86-*-* x86_64-*-* } } */ +/* { dg-require-effective-target avx } */ +/* { dg-options "-O2 -mavx" } */ + +extern void abort (void); + +struct alignment_test_struct +{ + char space[4] __attribute__((__aligned__)); +}; + +int +main () +{ + if (__alignof__(struct alignment_test_struct) != 16) + abort (); + return 0; +} Index: gcc/testsuite/g++.dg/other/pr38736-1.C =================================================================== --- gcc/testsuite/g++.dg/other/pr38736-1.C (revision 0) +++ gcc/testsuite/g++.dg/other/pr38736-1.C (revision 0) @@ -0,0 +1,18 @@ +/* PR target/38736 */ +/* { dg-do run { target i?86-*-* x86_64-*-* } } */ +/* { dg-options "-O2" } */ + +extern void abort (void); + +struct alignment_test_struct +{ + char space[4] __attribute__((__aligned__)); +}; + +int +main () +{ + if (__alignof__(struct alignment_test_struct) != 16) + abort (); + return 0; +} Index: gcc/c-common.c =================================================================== --- gcc/c-common.c (revision 4884) +++ gcc/c-common.c (working copy) @@ -5906,7 +5906,7 @@ handle_aligned_attribute (tree *node, tr tree *type = NULL; int is_type = 0; tree align_expr = (args ? TREE_VALUE (args) - : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); + : size_int (ATTRIBUTE_ALIGNED_VALUE / BITS_PER_UNIT)); int i; if (DECL_P (*node)) Index: gcc/config/i386/i386.h =================================================================== --- gcc/config/i386/i386.h (revision 4884) +++ gcc/config/i386/i386.h (working copy) @@ -710,6 +710,10 @@ enum target_cpu_default /* Maximum stack alignment. */ #define MAX_STACK_ALIGNMENT MAX_OFILE_ALIGNMENT +/* Alignment value for attribute ((aligned)). It is a constant + since it is the part of the ABI. */ +#define ATTRIBUTE_ALIGNED_VALUE 128 + /* Decide whether a variable of mode MODE should be 128 bit aligned. */ #define ALIGN_MODE_128(MODE) \ ((MODE) == XFmode || SSE_REG_MODE_P (MODE))