Source-Changes-HG archive

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

[src/trunk]: src/gnu/dist/toolchain/gas/config Fix the alignment code generat...



details:   https://anonhg.NetBSD.org/src/rev/34c5e8b88bce
branches:  trunk
changeset: 551833:34c5e8b88bce
user:      fvdl <fvdl%NetBSD.org@localhost>
date:      Fri Sep 12 19:51:19 2003 +0000

description:
Fix the alignment code generated for the 64bit case.
This fix was fed back to the FSF and appears in later binutils versions.

diffstat:

 gnu/dist/toolchain/gas/config/tc-i386.c |  49 ++++++++++++++++++++++----------
 1 files changed, 34 insertions(+), 15 deletions(-)

diffs (64 lines):

diff -r 5d779775a4f6 -r 34c5e8b88bce gnu/dist/toolchain/gas/config/tc-i386.c
--- a/gnu/dist/toolchain/gas/config/tc-i386.c   Fri Sep 12 19:02:30 2003 +0000
+++ b/gnu/dist/toolchain/gas/config/tc-i386.c   Fri Sep 12 19:51:19 2003 +0000
@@ -524,26 +524,45 @@
     f32_15, f32_15, f32_15, f32_15, f32_15, f32_15, f32_15
   };
 
-  /* ??? We can't use these fillers for x86_64, since they often kills the
-     upper halves.  Solve later.  */
+  if (count <= 0 || count > 15)
+    return;
+
+  /* The recommended way to pad 64bit code is to use NOPs preceded by
+     maximally four 0x66 prefixes.  Balance the size of nops.  */
   if (flag_code == CODE_64BIT)
-    count = 1;
-
-  if (count > 0 && count <= 15)
     {
-      if (flag_code == CODE_16BIT)
+      int i;
+      int nnops = (count + 3) / 4;
+      int len = count / nnops;
+      int remains = count - nnops * len;
+      int pos = 0;
+
+      for (i = 0; i < remains; i++)
        {
-         memcpy (fragP->fr_literal + fragP->fr_fix,
-                 f16_patt[count - 1], count);
-         if (count > 8)
-           /* Adjust jump offset.  */
-           fragP->fr_literal[fragP->fr_fix + 1] = count - 2;
+         memset (fragP->fr_literal + fragP->fr_fix + pos, 0x66, len);
+         fragP->fr_literal[fragP->fr_fix + pos + len] = 0x90;
+         pos += len + 1;
+       }
+      for (; i < nnops; i++)
+       {
+         memset (fragP->fr_literal + fragP->fr_fix + pos, 0x66, len - 1);
+         fragP->fr_literal[fragP->fr_fix + pos + len - 1] = 0x90;
+         pos += len;
        }
-      else
+    }
+  else
+    if (flag_code == CODE_16BIT)
+      {
        memcpy (fragP->fr_literal + fragP->fr_fix,
-               f32_patt[count - 1], count);
-      fragP->fr_var = count;
-    }
+               f16_patt[count - 1], count);
+       if (count > 8)
+         /* Adjust jump offset.  */
+         fragP->fr_literal[fragP->fr_fix + 1] = count - 2;
+      }
+    else
+      memcpy (fragP->fr_literal + fragP->fr_fix,
+             f32_patt[count - 1], count);
+  fragP->fr_var = count;
 }
 
 static INLINE unsigned int



Home | Main Index | Thread Index | Old Index