x86: rework UWRMSR operand swapping
authorJan Beulich <jbeulich@suse.com>
Thu, 9 Nov 2023 11:55:52 +0000 (12:55 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 9 Nov 2023 11:55:52 +0000 (12:55 +0100)
As indicated during review already, doing the swapping early is overall
cheaper than doing it only after operand matching.

gas/config/tc-i386.c
opcodes/i386-opc.tbl
opcodes/i386-tbl.h

index a351897c7949eb74f4415bfc2fbedae0fc5e2a27..235e41e7918f9a7d4b95c712e7a2d6db1ef8ce35 100644 (file)
@@ -5188,10 +5188,14 @@ md_assemble (char *line)
           && operand_type_check (i.types[1], imm)))
     swap_operands ();
 
-  /* The order of the immediates should be reversed
-     for 2 immediates extrq and insertq instructions */
-  if (i.imm_operands == 2
-      && (t->mnem_off == MN_extrq || t->mnem_off == MN_insertq))
+  /* The order of the immediates should be reversed for 2-immediates EXTRQ
+     and INSERTQ instructions.  Also UWRMSR wants its immediate to be in the
+     "canonical" place (first), despite it appearing last (in AT&T syntax, or
+     because of the swapping above) in the incoming set of operands.  */
+  if ((i.imm_operands == 2
+       && (t->mnem_off == MN_extrq || t->mnem_off == MN_insertq))
+      || (t->mnem_off == MN_uwrmsr && i.imm_operands
+         && i.operands > i.imm_operands))
       swap_2_operands (0, 1);
 
   if (i.imm_operands)
@@ -7544,17 +7548,6 @@ match_template (char mnem_suffix)
       break;
     }
 
-  /* This pattern aims to put the unusually placed imm operand to a usual
-     place. The constraints are currently only adapted to uwrmsr, and may
-     need further tweaking when new similar instructions become available.  */
-  if (i.imm_operands && i.imm_operands < i.operands
-      && operand_type_check (operand_types[i.operands - 1], imm))
-    {
-      i.tm.operand_types[0] = operand_types[i.operands - 1];
-      i.tm.operand_types[i.operands - 1] = operand_types[0];
-      swap_2_operands(0, i.operands - 1);
-    }
-
   return t;
 }
 
index 7020ca104887937a5ea3b6901c1581531b5c0ac3..c31bf20f2e6c4845f2c7513bb4da0a191d88bb92 100644 (file)
@@ -3356,6 +3356,8 @@ eretu, 0xf30f01ca, FRED, NoSuf, {}
 urdmsr, 0xf20f38f8, USER_MSR, RegMem|NoSuf|NoRex64, { Reg64, Reg64 }
 urdmsr, 0xf2f8/0, USER_MSR, Modrm|Vex128|VexMap7|VexW0|NoSuf, { Imm32, Reg64 }
 uwrmsr, 0xf30f38f8, USER_MSR, Modrm|NoSuf|NoRex64, { Reg64, Reg64 }
-uwrmsr, 0xf3f8/0, USER_MSR, Modrm|Vex128|VexMap7|VexW0|NoSuf, { Reg64, Imm32 }
+// Immediates want to be first; md_assemble() takes care of swapping operands
+// accordingly.
+uwrmsr, 0xf3f8/0, USER_MSR, Modrm|Vex128|VexMap7|VexW0|NoSuf, { Imm32, Reg64 }
 
 // USER_MSR instructions end.
index 5117bda3209d5577122046eb576f134154a8ee97..527793c5bf6591129bf1764f2b4916ac4cab28b3 100644 (file)
@@ -39668,9 +39668,9 @@ static const insn_template i386_optab[] =
       0 },
     { { 98, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 } },
     { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
-    { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+    { { { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 0 } },
-      { { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
          0, 0, 0, 0, 0, 0 } } } },
 };