[v3,3/2] x86: do away with is_evex_encoding()

Message ID 6871d921-5971-3f39-3d9a-6d216fd06a28@suse.com
State Unresolved
Headers
Series x86: insn template CPU specifier processing |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Jan Beulich Nov. 7, 2023, 4:35 p.m. UTC
  As we have grown more uses of it, it becomes increasingly more desirable
to replace it by a simpler check. Have i386-gen do at build time what so
far was done at runtime: Deal with templates indicating EVEX-encoding by
other than the EVex attribute, and set that to "dynamic" in such cases.

This then allows simplifying a number of other conditionals as well.
---
v3: New.
  

Patch

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -3861,17 +3861,9 @@  build_vex_prefix (const insn_template *t
 }
 
 static INLINE bool
-is_evex_encoding (const insn_template *t)
-{
-  return t->opcode_modifier.evex || t->opcode_modifier.disp8memshift
-	 || t->opcode_modifier.broadcast || t->opcode_modifier.masking
-	 || t->opcode_modifier.sae;
-}
-
-static INLINE bool
 is_any_vex_encoding (const insn_template *t)
 {
-  return t->opcode_modifier.vex || is_evex_encoding (t);
+  return t->opcode_modifier.vex || t->opcode_modifier.evex;
 }
 
 static unsigned int
@@ -3891,8 +3883,7 @@  get_broadcast_bytes (const insn_template
 
   gas_assert (op < t->operands);
 
-  if (t->opcode_modifier.evex
-      && t->opcode_modifier.evex != EVEXDYN)
+  if (t->opcode_modifier.evex != EVEXDYN)
     switch (i.broadcast.bytes)
       {
       case 1:
@@ -4040,8 +4031,7 @@  build_evex_prefix (void)
       /* Encode the vector length.  */
       unsigned int vec_length;
 
-      if (!i.tm.opcode_modifier.evex
-	  || i.tm.opcode_modifier.evex == EVEXDYN)
+      if (i.tm.opcode_modifier.evex == EVEXDYN)
 	{
 	  unsigned int op;
 
@@ -4539,7 +4529,7 @@  optimize_encoding (void)
 	   && !i.types[2].bitfield.xmmword
 	   && (i.tm.opcode_modifier.vex
 	       || ((!i.mask.reg || i.mask.zeroing)
-		   && is_evex_encoding (&i.tm)
+		   && i.tm.opcode_modifier.evex
 		   && (i.vec_encoding != vex_encoding_evex
 		       || cpu_arch_isa_flags.bitfield.cpuavx512vl
 		       || is_cpu (&i.tm, CpuAVX512VL)
@@ -4588,7 +4578,7 @@  optimize_encoding (void)
 	     VEX VOP %kM, %kM, %kN
 	       -> VEX kandnw %kM, %kM, %kN
        */
-      if (is_evex_encoding (&i.tm))
+      if (i.tm.opcode_modifier.evex)
 	{
 	  if (i.vec_encoding != vex_encoding_evex)
 	    {
@@ -4624,7 +4614,7 @@  optimize_encoding (void)
 	   && !i.mask.reg
 	   && !i.broadcast.type
 	   && !i.broadcast.bytes
-	   && is_evex_encoding (&i.tm)
+	   && i.tm.opcode_modifier.evex
 	   && ((i.tm.base_opcode & ~Opcode_SIMD_IntD) == 0x6f
 	       || (i.tm.base_opcode & ~4) == 0xdb
 	       || (i.tm.base_opcode & ~4) == 0xeb)
@@ -4703,7 +4693,7 @@  optimize_encoding (void)
 	   && i.op[0].regs == i.op[1].regs
 	   && (!i.tm.opcode_modifier.vex
 	       || !(i.op[0].regs->reg_flags & RegRex))
-	   && !is_evex_encoding (&i.tm))
+	   && !i.tm.opcode_modifier.evex)
     {
       /* Optimize: -Os:
          pcmpeqq %xmmN, %xmmN          -> pcmpeqd %xmmN, %xmmN
@@ -4720,7 +4710,7 @@  optimize_encoding (void)
 		&& i.tm.opcode_space == SPACE_0F38))
 	   && i.operands == i.reg_operands
 	   && i.op[0].regs == i.op[1].regs
-	   && !is_evex_encoding (&i.tm))
+	   && !i.tm.opcode_modifier.evex)
     {
       /* Optimize: -O:
          pcmpgt[bwd] %mmN, %mmN             -> pxor %mmN, %mmN
@@ -6956,7 +6946,7 @@  VEX_check_encoding (const insn_template
       || i.vec_encoding == vex_encoding_evex512)
     {
       /* This instruction must be encoded with EVEX prefix.  */
-      if (!is_evex_encoding (t))
+      if (!t->opcode_modifier.evex)
 	{
 	  i.error = unsupported;
 	  return 1;
@@ -7786,27 +7776,22 @@  process_suffix (void)
 		    {
 		      i.tm.operand_types[op].bitfield.ymmword = 0;
 		      if (i.tm.operand_types[op].bitfield.xmmword
-			  && (i.tm.opcode_modifier.evex == EVEXDYN
-			      || (!i.tm.opcode_modifier.evex
-				  && is_evex_encoding (&i.tm))))
+			  && i.tm.opcode_modifier.evex == EVEXDYN)
 			i.tm.opcode_modifier.evex = EVEX128;
 		    }
 		  else if (i.tm.operand_types[op].bitfield.ymmword
 			   && !i.tm.operand_types[op].bitfield.xmmword
-			   && (i.tm.opcode_modifier.evex == EVEXDYN
-			       || (!i.tm.opcode_modifier.evex
-				   && is_evex_encoding (&i.tm))))
+			   && i.tm.opcode_modifier.evex == EVEXDYN)
 		    i.tm.opcode_modifier.evex = EVEX256;
 		}
-	      else if (is_evex_encoding (&i.tm)
+	      else if (i.tm.opcode_modifier.evex
 		       && !cpu_arch_flags.bitfield.cpuavx512vl)
 		{
 		  if (i.tm.operand_types[op].bitfield.ymmword)
 		    i.tm.operand_types[op].bitfield.xmmword = 0;
 		  if (i.tm.operand_types[op].bitfield.zmmword)
 		    i.tm.operand_types[op].bitfield.ymmword = 0;
-		  if (!i.tm.opcode_modifier.evex
-		      || i.tm.opcode_modifier.evex == EVEXDYN)
+		  if (i.tm.opcode_modifier.evex == EVEXDYN)
 		    i.tm.opcode_modifier.evex = EVEX512;
 		}
 
@@ -7834,7 +7819,7 @@  process_suffix (void)
 		    suffixes |= 1 << 7;
 		  if (i.tm.operand_types[op].bitfield.zmmword)
 		    suffixes |= 1 << 8;
-		  if (is_evex_encoding (&i.tm))
+		  if (i.tm.opcode_modifier.evex)
 		    evex = EVEX512;
 		}
 	    }
@@ -8728,7 +8713,7 @@  build_modrm_byte (void)
 	  exp = i.op[0].imms;
 	}
       exp->X_add_number |= register_number (i.op[reg_slot].regs)
-			   << (3 + !(is_evex_encoding (&i.tm)
+			   << (3 + !(i.tm.opcode_modifier.evex
 				     || i.vec_encoding == vex_encoding_evex));
     }
 
--- a/opcodes/i386-gen.c
+++ b/opcodes/i386-gen.c
@@ -1192,6 +1192,16 @@  process_i386_opcode_modifier (FILE *tabl
   fprintf (table, " SPACE_%s, %s,\n",
 	   spaces[space], extension_opcode ? extension_opcode : "None");
 
+  /* Rather than evaluating multiple conditions at runtime to determine
+     whether an EVEX encoding is being dealt with, derive that information
+     right here.  A missing EVex attribute means "dynamic".  */
+  if (!modifiers[EVex].value
+      && (modifiers[Disp8MemShift].value
+	  || modifiers[Broadcast].value
+	  || modifiers[Masking].value
+	  || modifiers[SAE].value))
+    modifiers[EVex].value = EVEXDYN;
+
   output_opcode_modifier (table, modifiers, ARRAY_SIZE (modifiers));
 }