This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: target/10465: [AIX] allow -mnatural-align option for AIX as well


Hi David and Geoff,

Attached are two small patches that add support for the -malign-natural 
option (and the default -malign-power) for gcc 3.3 for AIX, Darwin, and 
LinuxPPC64 (Linux PPC 32 already uses the natural alignment as default)

The patch itself was simply borrowed from the Apple gcc 3.3 changes and
slightly modified to be implemented in a way that did not use up any target 
flags (as directed by David).

I have tested the Darwin version using gnu gcc 3.3 on MacOSX 10.2.5 and Ken 
has tested the AIX version.  Unfortunately, neither of us has access to a 
Linux PPC64 machine for testing, but the changes are identical to the AIX 
version and so should work fine.

These patches are important to allow building and porting OpenOffice.org to
both AIX and Linux PPC64, and Darwin and for helping to sync up MacOSX gcc
changes back to GNU gcc (MacOSX already has the -malign-natural option). 

Please consider them for inclusion in gcc.

Thanks David for all of the pointers and tips on the best approach.

Hope this helps,

Kevin

--- gcc/gcc/config/rs6000/rs6000.h.~1.237.2.7.~	Tue Apr 15 06:00:30 2003
+++ gcc/gcc/config/rs6000/rs6000.h	Fri Apr 25 23:26:56 2003
@@ -404,6 +404,8 @@
    {"longcall", &rs6000_longcall_switch,				\
     N_("Avoid all range limits on call instructions") },		\
    {"no-longcall", &rs6000_longcall_switch, "" },			\
+   {"align-", &rs6000_alignment_string,                                 \
+    N_("Specify alignment of structure fields default/natural") },      \
    SUBTARGET_OPTIONS							\
 }
 
@@ -442,6 +444,13 @@
 extern int rs6000_altivec_vrsave;
 extern const char *rs6000_longcall_switch;
 extern int rs6000_default_long_calls;
+extern const char* rs6000_alignment_string;
+extern int rs6000_alignment_flags;
+
+/* Alignment options for fields in structures. */
+#define MASK_ALIGN_POWER   0x00000000
+#define MASK_ALIGN_NATURAL 0x00000001
+#define TARGET_ALIGN_NATURAL (rs6000_alignment_flags & MASK_ALIGN_NATURAL)
 
 #define TARGET_LONG_DOUBLE_128 (rs6000_long_double_type_size == 128)
 #define TARGET_ALTIVEC_ABI rs6000_altivec_abi
--- gcc/gcc/config/rs6000/rs6000.c.~1.403.2.6.~	Tue Apr  1 05:14:13 2003
+++ gcc/gcc/config/rs6000/rs6000.c	Fri Apr 25 23:20:40 2003
@@ -154,6 +154,11 @@
 int rs6000_default_long_calls;
 const char *rs6000_longcall_switch;
 
+/* Control alignment for fields within structures. */
+/* String from -malign-XXXXX. */
+const char * rs6000_alignment_string;
+int rs6000_alignment_flags;
+
 struct builtin_description
 {
   /* mask is not const because we're going to alter it below.  This
@@ -257,6 +262,7 @@
 static rtx altivec_expand_stv_builtin PARAMS ((enum insn_code, tree));
 static void rs6000_parse_abi_options PARAMS ((void));
 static void rs6000_parse_vrsave_option PARAMS ((void));
+static void rs6000_parse_alignment_option PARAMS ((void));
 static void rs6000_parse_isel_option PARAMS ((void));
 static int first_altivec_reg_to_save PARAMS ((void));
 static unsigned int compute_vrsave_mask PARAMS ((void));
@@ -655,6 +661,9 @@
   /* Handle -mvrsave= option.  */
   rs6000_parse_vrsave_option ();
 
+  /* Handle -malign-XXXXX option.  */
+  rs6000_parse_alignment_option ();
+
   /* Handle -misel= option.  */
   rs6000_parse_isel_option ();
 
@@ -752,6 +761,21 @@
   else
     error ("unknown -mvrsave= option specified: '%s'",
 	   rs6000_altivec_vrsave_string);
+}
+
+
+/* Handle -malign-XXXXXX options.  */
+static void
+rs6000_parse_alignment_option ()
+{
+  if (rs6000_alignment_string == 0
+      || ! strcmp (rs6000_alignment_string, "power"))
+          rs6000_alignment_flags = MASK_ALIGN_POWER;
+  else if (! strcmp (rs6000_alignment_string, "natural"))
+    rs6000_alignment_flags = MASK_ALIGN_NATURAL;
+  else
+    error ("unknown -malign-XXXXX option specified: '%s'",
+	   rs6000_alignment_string);
 }
 
 /* Handle -mabi= options.  */
--- gcc/gcc/config/rs6000/aix.h.~1.34.~	Mon Nov 25 23:54:49 2002
+++ gcc/gcc/config/rs6000/aix.h	Fri Apr 25 23:11:33 2003
@@ -129,11 +129,14 @@
 %{p:-L/lib/profiled -L/usr/lib/profiled} %{!shared:%{g*:-lg}} -lc"
 
 /* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
+/* This now supports a natural alignment mode. */
 #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
+  (TARGET_ALIGN_NATURAL ? (COMPUTED) : \
   (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
-	      ? get_inner_array_type (FIELD) \
-	      : TREE_TYPE (FIELD)) == DFmode \
-   ? MIN ((COMPUTED), 32) : (COMPUTED))
+              ? get_inner_array_type (FIELD) \
+	      :  TREE_TYPE (FIELD)) == DFmode \
+   ? MIN ((COMPUTED), 32) : (COMPUTED)))
+
 
 /* AIX increases natural record alignment to doubleword if the first
    field is an FP double while the FP fields remain word aligned.  */
@@ -142,6 +145,7 @@
     || TREE_CODE (STRUCT) == UNION_TYPE			\
     || TREE_CODE (STRUCT) == QUAL_UNION_TYPE)		\
    && TYPE_FIELDS (STRUCT) != 0				\
+   && TARGET_ALIGN_NATURAL == 0                         \
    && DECL_MODE (TYPE_FIELDS (STRUCT)) == DFmode	\
    ? MAX (MAX ((COMPUTED), (SPECIFIED)), 64)		\
    : MAX ((COMPUTED), (SPECIFIED)))
--- gcc/gcc/config/rs6000/darwin.h.~1.30.2.1.~	Thu Dec 19 20:49:57 2002
+++ gcc/gcc/config/rs6000/darwin.h	Fri Apr 25 21:13:27 2003
@@ -210,12 +210,14 @@
 /* Fix for emit_group_load (): force large constants to be pushed via regs.  */
 #define ALWAYS_PUSH_CONSTS_USING_REGS_P		1
 
+/* This now supports a natural alignment mode */
 /* Darwin word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
 #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
+  (TARGET_ALIGN_NATURAL ? (COMPUTED) : \
   (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
 	      ? get_inner_array_type (FIELD) \
-	      : TREE_TYPE (FIELD)) == DFmode \
-   ? MIN ((COMPUTED), 32) : (COMPUTED))
+	      :  TREE_TYPE (FIELD)) == DFmode \
+               ? MIN ((COMPUTED), 32) : (COMPUTED)))
 
 /* Darwin increases natural record alignment to doubleword if the first
    field is an FP double while the FP fields remain word aligned.  */
@@ -224,11 +226,13 @@
     || TREE_CODE (STRUCT) == UNION_TYPE			\
     || TREE_CODE (STRUCT) == QUAL_UNION_TYPE)		\
    && TYPE_FIELDS (STRUCT) != 0				\
+   && TARGET_ALIGN_NATURAL == 0                         \
    && DECL_MODE (TYPE_FIELDS (STRUCT)) == DFmode	\
    ? MAX (MAX ((COMPUTED), (SPECIFIED)), 64)		\
    : (TARGET_ALTIVEC && TREE_CODE (STRUCT) == VECTOR_TYPE) \
    ? MAX (MAX ((COMPUTED), (SPECIFIED)), 128)           \
    : MAX ((COMPUTED), (SPECIFIED)))
+
 
 /* XXX: Darwin supports neither .quad, or .llong, but it also doesn't
    support 64 bit PowerPC either, so this just keeps things happy.  */
--- gcc/gcc/config/rs6000/linux64.h.~1.31.~	Sun Nov 10 15:47:44 2002
+++ gcc/gcc/config/rs6000/linux64.h	Fri Apr 25 23:10:59 2003
@@ -73,12 +73,14 @@
 #define USER_LABEL_PREFIX  ""
 
 /* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
+/* This now supports a natural alignment mode. */
 #undef  ADJUST_FIELD_ALIGN
 #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
+  (TARGET_ALIGN_NATURAL ? (COMPUTED) : \
   (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
-	      ? get_inner_array_type (FIELD) \
-	      : TREE_TYPE (FIELD)) == DFmode \
-   ? MIN ((COMPUTED), 32) : (COMPUTED))
+              ? get_inner_array_type (FIELD) \
+	      :  TREE_TYPE (FIELD)) == DFmode \
+   ? MIN ((COMPUTED), 32) : (COMPUTED)))
 
 /* AIX increases natural record alignment to doubleword if the first
    field is an FP double while the FP fields remain word aligned.  */
@@ -88,6 +90,7 @@
     || TREE_CODE (STRUCT) == UNION_TYPE			\
     || TREE_CODE (STRUCT) == QUAL_UNION_TYPE)		\
    && TYPE_FIELDS (STRUCT) != 0				\
+   && TARGET_ALIGN_NATURAL == 0                         \
    && DECL_MODE (TYPE_FIELDS (STRUCT)) == DFmode	\
    ? MAX (MAX ((COMPUTED), (SPECIFIED)), 64)		\
    : MAX ((COMPUTED), (SPECIFIED)))
--- gcc/gcc/doc/invoke.texi.orig	Wed Apr 30 08:23:20 2003
+++ gcc/gcc/doc/invoke.texi	Wed Apr 30 08:27:18 2003
@@ -429,6 +429,7 @@
 -mnew-mnemonics  -mold-mnemonics @gol
 -mfull-toc   -mminimal-toc  -mno-fp-in-toc  -mno-sum-in-toc @gol
 -m64  -m32  -mxl-call  -mno-xl-call  -mpe @gol
+-malign-power -malign-natural (AIX, Darwin, LinuxPPC64 ONLY) @gol
 -msoft-float  -mhard-float  -mmultiple  -mno-multiple @gol
 -mstring  -mno-string  -mupdate  -mno-update @gol
 -mfused-madd  -mno-fused-madd  -mbit-align  -mno-bit-align @gol
@@ -6898,6 +6899,13 @@
 support threads, so the @option{-mpe} option and the @option{-pthread}
 option are incompatible.
 
+@item -malign-power
+@itemx -malign-natural
+The option @option{-malign-power} is the standard alignment
+mode for the PowerPC.  The option @option{-malign-natural} is an
+extension of PowerPC alignment that aligns larger data types such as
+doubles on their natural boundaries. (AIX, Darwin, LinuxPPC64 ONLY)
+
 @item -msoft-float
 @itemx -mhard-float
 @opindex msoft-float

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]