Port-i386 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Fix GCC's preferred stack alignment to match psABI



Hi all,
the attached patch consists of two parts. The first part ensures that
GCC honours the SYSV ABI on i386 as used by NetBSD. The second part
adjusts the alignment of stack variables, so that double and complex
double as well as long long are not aligned to 64bit by default, if the
stack alignment is smaller. This avoids triggering unnecessary stack
reliagnments.

Joerg
Index: gcc/config/i386/i386.c
===================================================================
RCS file: 
/home/joerg/repo/netbsd/src/external/gpl3/gcc/dist/gcc/config/i386/i386.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 i386.c
--- gcc/config/i386/i386.c      21 Jun 2011 01:22:07 -0000      1.1.1.1
+++ gcc/config/i386/i386.c      3 Sep 2012 16:53:06 -0000
@@ -20104,7 +20104,9 @@ ix86_local_alignment (tree exp, enum mac
   if (!TARGET_64BIT
       && align == 64
       && ix86_preferred_stack_boundary < 64
-      && (mode == DImode || (type && TYPE_MODE (type) == DImode))
+      && (mode == DImode || (type && TYPE_MODE (type) == DImode)
+          || mode == DFmode || (type && TYPE_MODE (type) == DFmode)
+          || mode == DCmode || (type && TYPE_MODE (type) == DCmode))
       && (!type || !TYPE_USER_ALIGN (type))
       && (!decl || !DECL_USER_ALIGN (decl)))
     align = 32;
@@ -20150,7 +20152,8 @@ ix86_local_alignment (tree exp, enum mac
            || TREE_CODE (type) == QUAL_UNION_TYPE)
           && TYPE_FIELDS (type))
     {
-      if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
+      if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64
+          && (TARGET_64BIT || ix86_preferred_stack_boundary >= 64))
        return 64;
       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
        return 128;
@@ -20159,7 +20162,8 @@ ix86_local_alignment (tree exp, enum mac
           || TREE_CODE (type) == INTEGER_TYPE)
     {
 
-      if (TYPE_MODE (type) == DFmode && align < 64)
+      if (TYPE_MODE (type) == DFmode && align < 64
+          && (TARGET_64BIT || ix86_preferred_stack_boundary >= 64))
        return 64;
       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
        return 128;
Index: gcc/config/i386/netbsd-elf.h
===================================================================
RCS file: 
/home/joerg/repo/netbsd/src/external/gpl3/gcc/dist/gcc/config/i386/netbsd-elf.h,v
retrieving revision 1.2
diff -u -p -r1.2 netbsd-elf.h
--- gcc/config/i386/netbsd-elf.h        2 Feb 2012 13:07:33 -0000       1.2
+++ gcc/config/i386/netbsd-elf.h        11 Sep 2012 20:04:27 -0000
@@ -126,3 +126,7 @@ along with GCC; see the file COPYING3.  
 #undef X87_ENABLE_ARITH
 #define X87_ENABLE_ARITH(MODE) \
   (flag_excess_precision == EXCESS_PRECISION_FAST || (MODE) == DFmode)
+
+/* Preserve i386 psABI  */
+#undef PREFERRED_STACK_BOUNDARY_DEFAULT
+#define PREFERRED_STACK_BOUNDARY_DEFAULT MIN_STACK_BOUNDARY
Index: gcc/config/i386/netbsd64.h
===================================================================
RCS file: 
/home/joerg/repo/netbsd/src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 netbsd64.h
--- gcc/config/i386/netbsd64.h  21 Jun 2011 01:22:04 -0000      1.1.1.1
+++ gcc/config/i386/netbsd64.h  11 Sep 2012 19:34:51 -0000
@@ -70,3 +70,7 @@ along with GCC; see the file COPYING3.  
 #define ENABLE_EXECUTE_STACK NETBSD_ENABLE_EXECUTE_STACK
 
 #define TARGET_VERSION fprintf (stderr, " (NetBSD/x86_64 ELF)");
+
+/* Preserve i386 psABI  */
+#undef PREFERRED_STACK_BOUNDARY_DEFAULT
+#define PREFERRED_STACK_BOUNDARY_DEFAULT MIN_STACK_BOUNDARY


Home | Main Index | Thread Index | Old Index