[binutils-gdb] x86: Split REX/REX2 old registers judgment.

Lili Cui cuilili@sourceware.org
Wed May 22 02:17:47 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3a8ecbdade82981cd2fb257896b01afd54752491

commit 3a8ecbdade82981cd2fb257896b01afd54752491
Author: Cui, Lili <lili.cui@intel.com>
Date:   Wed May 22 09:18:38 2024 +0800

    x86: Split REX/REX2 old registers judgment.
    
    Split "REX/REX2 old register checking" and "add empty rex prefix"
    into two separate branches.
    
    gas/ChangeLog:
    
            * config/tc-i386.c (establish_rex): Split the judgments.

Diff:
---
 gas/config/tc-i386.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 339e849a971..12af7ceec08 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -4303,22 +4303,20 @@ static void establish_rex (void)
   /* Respect a user-specified REX prefix.  */
   i.rex |= i.prefix[REX_PREFIX] & REX_OPCODE;
 
-  /* For 8 bit registers we need an empty rex prefix.  Also if the
-     instruction already has a prefix, we need to convert old
-     registers to new ones.  */
-
-  if ((i.types[first].bitfield.class == Reg && i.types[first].bitfield.byte
-       && ((i.op[first].regs->reg_flags & RegRex64) != 0 || i.rex != 0
-	   || i.rex2 != 0))
-      || (i.types[last].bitfield.class == Reg && i.types[last].bitfield.byte
-	  && ((i.op[last].regs->reg_flags & RegRex64) != 0 || i.rex != 0
-	      || i.rex2 != 0)))
-    {
-      unsigned int x;
-
-      if (!is_apx_rex2_encoding () && !is_any_vex_encoding(&i.tm))
-	i.rex |= REX_OPCODE;
-      for (x = first; x <= last; x++)
+  /* For 8 bit RegRex64 registers without a prefix, we need an empty rex prefix.  */
+  if (((i.types[first].bitfield.class == Reg && i.types[first].bitfield.byte
+	&& (i.op[first].regs->reg_flags & RegRex64) != 0)
+       || (i.types[last].bitfield.class == Reg && i.types[last].bitfield.byte
+	   && (i.op[last].regs->reg_flags & RegRex64) != 0))
+      && !i.rex && !is_apx_rex2_encoding () && !is_any_vex_encoding (&i.tm))
+    i.rex |= REX_OPCODE;
+
+  /* For REX/REX2/EVEX prefix instructions, we need to convert old registers
+     (AL, CL, DL and BL) to new ones (AXL, CXL, DXL and BXL) and reject AH,
+     CH, DH and BH.  */
+  if (i.rex || i.rex2)
+    {
+      for (unsigned int x = first; x <= last; x++)
 	{
 	  /* Look for 8 bit operand that uses old registers.  */
 	  if (i.types[x].bitfield.class == Reg && i.types[x].bitfield.byte


More information about the Binutils-cvs mailing list