]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86/APX: squash REX prefix when REX2 is being emitted
authorJan Beulich <jbeulich@suse.com>
Wed, 30 Oct 2024 11:12:24 +0000 (12:12 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 30 Oct 2024 11:12:24 +0000 (12:12 +0100)
We should not (silently) emit a REX prefix ahead of a REX2-encoded insn;
such encodings are illegal. Best we can do is fold the REX bits into the
REX2 prefix, and then zap the REX one from i.prefix[].

gas/config/tc-i386.c
gas/testsuite/gas/i386/x86-64-apx-rex2.d
gas/testsuite/gas/i386/x86-64-apx-rex2.s

index 9f68a2fb41284c2ed59ddee0d2d04e230307d549..f6a8c30b3796a70f8a6babc5b818d0a10fd42060 100644 (file)
@@ -4527,7 +4527,8 @@ build_rex2_prefix (void)
   i.vex.bytes[0] = 0xd5;
   /* For the W R X B bits, the variables of rex prefix will be reused.  */
   i.vex.bytes[1] = ((i.tm.opcode_space << 7)
-                   | (i.rex2 << 4) | i.rex);
+                   | (i.rex2 << 4)
+                   | ((i.rex | i.prefix[REX_PREFIX]) & 0xf));
 }
 
 /* Build the EVEX prefix (4-byte) for evex insn
@@ -4676,6 +4677,7 @@ static void establish_rex (void)
       build_rex2_prefix ();
       /* The individual REX.RXBW bits got consumed.  */
       i.rex &= REX_OPCODE;
+      i.prefix[REX_PREFIX] = 0;
     }
   else if (i.rex != 0)
     add_prefix (REX_OPCODE | i.rex);
index e3cd534da118ceec9d295ce0062637a170008b1d..0783f9b979c5ff23fa7f86bcdaab42135bb07c72 100644 (file)
@@ -80,4 +80,8 @@ Disassembly of section .text:
 [       ]*[a-f0-9]+:[   ]*d5 76 8d 7c 20 01            lea    0x1\(%r16,%r28,1\),%r31d
 [       ]*[a-f0-9]+:[   ]*d5 12 8d 84 04 81 00 00 00   lea    0x81\(%r20,%r8,1\),%eax
 [       ]*[a-f0-9]+:[   ]*d5 57 8d bc 04 81 00 00 00   lea    0x81\(%r28,%r8,1\),%r31d
+[       ]*[a-f0-9]+:[   ]*d5 14 f7 14 24               \{rex2 0x14\} notl \(%r20\)
+[       ]*[a-f0-9]+:[   ]*d5 12 f7 14 24               notl   \(%r20,%r12,1\)
+[       ]*[a-f0-9]+:[   ]*d5 11 f7 14 24               notl   \(%r28\)
+[       ]*[a-f0-9]+:[   ]*d5 18 f7 14 24               notq   \(%r20\)
 #pass
index eaaaaa77dd73aa4ed9d0b6fcbc78a815aa4dd4dd..5102dc37c27a4815f5563f4c30319fb1fc6bd1b4 100644 (file)
@@ -83,3 +83,9 @@ _start:
          leal  1(%r16, %r28), %r31d
          leal  129(%r20, %r8), %eax
          leal  129(%r28, %r8), %r31d
+
+## explicit REX prefix
+         rex.r notl (%r20)
+         rex.x notl (%r20)
+         rex.b notl (%r20)
+         rex.w not (%r20)