This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

[PATCH] don't generate long nops on i686 (only when -march=[intel])


From: Kyle McMartin <kyle@redhat.com>

Hi,

In Fedora, glibc started building itself with -march=i686 flags to
binutils as an "optimization." This exposes issues on the Geode, which
is i686, but for long nops, since they are apparently not an architected
part of the i686 ISA.

Clarify this by only enabling long nops if we're generating 64-bit code
(as far as I can tell, all x86_64 cpus support this) or explicitly
generating code for the pentiumpro and above.

Using this patch prevents people from overambitiously optimizing and
breaking the Geode.

Signed-off-by: Kyle McMartin <kyle@redhat.com>
---
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index f5c249a..1fe2506 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -581,7 +581,7 @@ static const arch_entry cpu_arch[] =
     CPU_I486_FLAGS, 0 },
   { STRING_COMMA_LEN ("i586"), PROCESSOR_PENTIUM,
     CPU_I586_FLAGS, 0 },
-  { STRING_COMMA_LEN ("i686"), PROCESSOR_PENTIUMPRO,
+  { STRING_COMMA_LEN ("i686"), PROCESSOR_I686,
     CPU_I686_FLAGS, 0 },
   { STRING_COMMA_LEN ("pentium"), PROCESSOR_PENTIUM,
     CPU_I586_FLAGS, 0 },
@@ -980,8 +980,8 @@ i386_align_code (fragS *fragP, int count)
   /* We need to decide which NOP sequence to use for 32bit and
      64bit. When -mtune= is used:
 
-     1. For PROCESSOR_I386, PROCESSOR_I486, PROCESSOR_PENTIUM and
-     PROCESSOR_GENERIC32, f32_patt will be used.
+     1. For PROCESSOR_I386, PROCESSOR_I486, PROCESSOR_I686,
+     PROCESSOR_PENTIUM and PROCESSOR_GENERIC32, f32_patt will be used.
      2. For PROCESSOR_PENTIUMPRO, PROCESSOR_PENTIUM4, PROCESSOR_NOCONA,
      PROCESSOR_CORE, PROCESSOR_CORE2, PROCESSOR_COREI7, and
      PROCESSOR_GENERIC64, alt_long_patt will be used.
@@ -989,9 +989,10 @@ i386_align_code (fragS *fragP, int count)
      PROCESSOR_AMDFAM10, and PROCESSOR_BDVER1, alt_short_patt
      will be used.
 
-     When -mtune= isn't used, alt_long_patt will be used if
-     cpu_arch_isa_flags has Cpu686. Otherwise, f32_patt will
-     be used.
+     Geode CPUs implement the i686 instruction set, but do not
+     implement Intel long NOPs. Therefore, we cannot assume that
+     i686 code can use them, unless we are explicitly tuning for
+     pentiumpro or higher.
 
      When -march= or .arch is used, we can't use anything beyond
      cpu_arch_isa_flags.   */
@@ -1019,9 +1020,8 @@ i386_align_code (fragS *fragP, int count)
 	  switch (cpu_arch_tune)
 	    {
 	    case PROCESSOR_UNKNOWN:
-	      /* We use cpu_arch_isa_flags to check if we SHOULD
-		 optimize for Cpu686.  */
-	      if (fragP->tc_frag_data.isa_flags.bitfield.cpui686)
+	      /* use long nops on 64-bit, don't assume we can on 32-bit */
+	      if (flag_code == CODE_64BIT)
 		patt = alt_long_patt;
 	      else
 		patt = f32_patt;
@@ -1045,6 +1045,7 @@ i386_align_code (fragS *fragP, int count)
 	      break;
 	    case PROCESSOR_I386:
 	    case PROCESSOR_I486:
+	    case PROCESSOR_I686:
 	    case PROCESSOR_PENTIUM:
 	    case PROCESSOR_GENERIC32:
 	      patt = f32_patt;
@@ -1063,6 +1064,7 @@ i386_align_code (fragS *fragP, int count)
 
 	    case PROCESSOR_I386:
 	    case PROCESSOR_I486:
+	    case PROCESSOR_I686:
 	    case PROCESSOR_PENTIUM:
 	    case PROCESSOR_K6:
 	    case PROCESSOR_ATHLON:
@@ -1070,12 +1072,7 @@ i386_align_code (fragS *fragP, int count)
 	    case PROCESSOR_AMDFAM10:
 	    case PROCESSOR_BDVER1:
 	    case PROCESSOR_GENERIC32:
-	      /* We use cpu_arch_isa_flags to check if we CAN optimize
-		 for Cpu686.  */
-	      if (fragP->tc_frag_data.isa_flags.bitfield.cpui686)
-		patt = alt_short_patt;
-	      else
-		patt = f32_patt;
+	      patt = f32_patt;
 	      break;
 	    case PROCESSOR_PENTIUMPRO:
 	    case PROCESSOR_PENTIUM4:
diff --git a/gas/config/tc-i386.h b/gas/config/tc-i386.h
index 80824f2..3a9cab3 100644
--- a/gas/config/tc-i386.h
+++ b/gas/config/tc-i386.h
@@ -212,6 +212,7 @@ enum processor_type
   PROCESSOR_UNKNOWN,
   PROCESSOR_I386,
   PROCESSOR_I486,
+  PROCESSOR_I686,
   PROCESSOR_PENTIUM,
   PROCESSOR_PENTIUMPRO,
   PROCESSOR_PENTIUM4,


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