This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, ARM] Align arrays/structs and unions of small data types to a word boundary.
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: gcc patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 22 Jan 2009 11:22:54 +0000
- Subject: [patch, ARM] Align arrays/structs and unions of small data types to a word boundary.
It turns out that by aligning local arrays/structs/unions to a word
boundary we can get improvements to both performance and code size. The
same is true of static data, provided we can see the definition (if we
can't see the definition we can't generate better code, but some memory
operations (such as memcpy, strcmp etc) can exploit the extra alignment
to run more efficently.
This does not change the ABI, the compiler is still conservative if the
declaration is extern.
2009-01-22 Richard Earnshaw <rearnsha@arm.com>
* arm.h (DATA_ALIGNMENT): Align structures, unions and arrays to
a word boundary.
(LOCAL_ALIGNMENT): Similarly.
*** arm.h (revision 143577)
--- arm.h (local)
*************** extern int arm_arch_hwdiv;
*** 564,569 ****
--- 564,582 ----
&& (ALIGN) < BITS_PER_WORD * CONSTANT_ALIGNMENT_FACTOR) \
? BITS_PER_WORD * CONSTANT_ALIGNMENT_FACTOR : (ALIGN))
+ /* Align definitions of arrays, unions and structures so that
+ initializations and copies can be made more efficient. This is not
+ ABI-changing, so it only affects places where we can see the
+ definition. */
+ #define DATA_ALIGNMENT(EXP, ALIGN) \
+ ((((ALIGN) < BITS_PER_WORD) \
+ && (TREE_CODE (EXP) == ARRAY_TYPE \
+ || TREE_CODE (EXP) == UNION_TYPE \
+ || TREE_CODE (EXP) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))
+
+ /* Similarly, make sure that objects on the stack are sensibly aligned. */
+ #define LOCAL_ALIGNMENT(EXP, ALIGN) DATA_ALIGNMENT(EXP, ALIGN)
+
/* Setting STRUCTURE_SIZE_BOUNDARY to 32 produces more efficient code, but the
value set in previous versions of this toolchain was 8, which produces more
compact structures. The command line option -mstructure_size_boundary=<n>