[v5,1/8] x86: introduce Pass2 insn attribute

Message ID b9273ae6-0218-54f8-5374-b265ed13b71a@suse.com
State Accepted
Headers
Series [v5,1/8] x86: introduce Pass2 insn attribute |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Jan Beulich Oct. 25, 2022, 7:25 a.m. UTC
  Subsequently we will want to mark templates for mnemonics which, due to
their last character also possibly being a suffix, are "shadowing" other
templates (and hence may require a second parsing pass). Introduce this
attribute in a standalone patch, largely to ease looking at the actual
later change. To simplify logic the later change is going to look for
the new attribute only on the first template of a group. Make i386-gen
warn about misplaced Pass2 (redundant ones are okay).

While there convert "active_isstring" to bool, matching the new static
variable.
---
As to redundant attributes: An open question is whether - to avoid
surprises when e.g. templates are re-ordered - it wouldn't be desirable
to add Pass2 on all templates of a group.
---
v3: New.
  

Comments

Jan Beulich Oct. 25, 2022, 7:30 a.m. UTC | #1
I'm sorry, I've typo-ed the title of the original submission - this is of
course patch 2/8 (reflected in the subject here).

Jan

On 25.10.2022 09:25, Jan Beulich via Binutils wrote:
> Subsequently we will want to mark templates for mnemonics which, due to
> their last character also possibly being a suffix, are "shadowing" other
> templates (and hence may require a second parsing pass). Introduce this
> attribute in a standalone patch, largely to ease looking at the actual
> later change. To simplify logic the later change is going to look for
> the new attribute only on the first template of a group. Make i386-gen
> warn about misplaced Pass2 (redundant ones are okay).
> 
> While there convert "active_isstring" to bool, matching the new static
> variable.
> ---
> As to redundant attributes: An open question is whether - to avoid
> surprises when e.g. templates are re-ordered - it wouldn't be desirable
> to add Pass2 on all templates of a group.
> ---
> v3: New.
> 
> --- a/opcodes/i386-gen.c
> +++ b/opcodes/i386-gen.c
> @@ -18,6 +18,7 @@
>     MA 02110-1301, USA.  */
>  
>  #include "sysdep.h"
> +#include <stdbool.h>
>  #include <stdio.h>
>  #include <errno.h>
>  #include "getopt.h"
> @@ -702,6 +703,7 @@ static bitfield opcode_modifiers[] =
>    BITFIELD (FWait),
>    BITFIELD (IsString),
>    BITFIELD (RegMem),
> +  BITFIELD (Pass2),
>    BITFIELD (BNDPrefixOk),
>    BITFIELD (RegKludge),
>    BITFIELD (Implicit1stXmm0),
> @@ -800,7 +802,7 @@ static bitfield operand_types[] =
>  
>  static const char *filename;
>  static i386_cpu_flags active_cpu_flags;
> -static int active_isstring;
> +static bool active_isstring, active_pass2;
>  
>  struct template_arg {
>    const struct template_arg *next;
> @@ -1168,7 +1170,8 @@ process_i386_opcode_modifier (FILE *tabl
>    char *str, *next, *last;
>    bitfield modifiers [ARRAY_SIZE (opcode_modifiers)];
>  
> -  active_isstring = 0;
> +  active_isstring = false;
> +  active_pass2 = false;
>  
>    /* Copy the default opcode modifier.  */
>    memcpy (modifiers, opcode_modifiers, sizeof (modifiers));
> @@ -1191,8 +1194,11 @@ process_i386_opcode_modifier (FILE *tabl
>  
>  	      set_bitfield (str, modifiers, val, ARRAY_SIZE (modifiers),
>  			    lineno);
> +
>  	      if (strcasecmp(str, "IsString") == 0)
> -		active_isstring = 1;
> +		active_isstring = true;
> +	      if (strcasecmp(str, "Pass2") == 0)
> +		active_pass2 = true;
>  
>  	      if (strcasecmp(str, "W") == 0)
>  		have_w = 1;
> @@ -1867,6 +1873,7 @@ process_i386_opcodes (FILE *table)
>    for (j = 0; j < i; j++)
>      {
>        struct opcode_hash_entry *next;
> +      bool first_pass2 = false;
>  
>        for (next = opcode_array[j]; next; next = next->next)
>  	{
> @@ -1875,6 +1882,14 @@ process_i386_opcodes (FILE *table)
>  	  lineno = next->lineno;
>  	  last = str + strlen (str);
>  	  output_i386_opcode (table, name, str, last, lineno);
> +
> +	  if (next == opcode_array[j])
> +	    first_pass2 = active_pass2;
> +	  else if (!first_pass2 && active_pass2)
> +	    fprintf (stderr,
> +		     "Warning: %s:%d: %s: "
> +		     "'Pass2' is recognized only on the first template in a group\n",
> +		     filename, lineno, name);
>  	}
>      }
>  
> --- a/opcodes/i386-opc.h
> +++ b/opcodes/i386-opc.h
> @@ -504,6 +504,9 @@ enum
>       Normally, it will be encoded in the reg field. We add a RegMem
>       flag to indicate that it should be encoded in the regmem field.  */
>    RegMem,
> +  /* The (unsuffixed) mnemonic represents itself the suffixed form of another
> +     mnemonic, potentially requiring a second parsing pass.  */
> +  Pass2,
>    /* quick test if branch instruction is MPX supported */
>    BNDPrefixOk,
>    /* fake an extra reg operand for clr, imul and special register
> @@ -730,6 +733,7 @@ typedef struct i386_opcode_modifier
>    unsigned int fwait:1;
>    unsigned int isstring:2;
>    unsigned int regmem:1;
> +  unsigned int pass2:1;
>    unsigned int bndprefixok:1;
>    unsigned int regkludge:1;
>    unsigned int implicit1stxmm0:1;
>
  

Patch

--- a/opcodes/i386-gen.c
+++ b/opcodes/i386-gen.c
@@ -18,6 +18,7 @@ 
    MA 02110-1301, USA.  */
 
 #include "sysdep.h"
+#include <stdbool.h>
 #include <stdio.h>
 #include <errno.h>
 #include "getopt.h"
@@ -702,6 +703,7 @@  static bitfield opcode_modifiers[] =
   BITFIELD (FWait),
   BITFIELD (IsString),
   BITFIELD (RegMem),
+  BITFIELD (Pass2),
   BITFIELD (BNDPrefixOk),
   BITFIELD (RegKludge),
   BITFIELD (Implicit1stXmm0),
@@ -800,7 +802,7 @@  static bitfield operand_types[] =
 
 static const char *filename;
 static i386_cpu_flags active_cpu_flags;
-static int active_isstring;
+static bool active_isstring, active_pass2;
 
 struct template_arg {
   const struct template_arg *next;
@@ -1168,7 +1170,8 @@  process_i386_opcode_modifier (FILE *tabl
   char *str, *next, *last;
   bitfield modifiers [ARRAY_SIZE (opcode_modifiers)];
 
-  active_isstring = 0;
+  active_isstring = false;
+  active_pass2 = false;
 
   /* Copy the default opcode modifier.  */
   memcpy (modifiers, opcode_modifiers, sizeof (modifiers));
@@ -1191,8 +1194,11 @@  process_i386_opcode_modifier (FILE *tabl
 
 	      set_bitfield (str, modifiers, val, ARRAY_SIZE (modifiers),
 			    lineno);
+
 	      if (strcasecmp(str, "IsString") == 0)
-		active_isstring = 1;
+		active_isstring = true;
+	      if (strcasecmp(str, "Pass2") == 0)
+		active_pass2 = true;
 
 	      if (strcasecmp(str, "W") == 0)
 		have_w = 1;
@@ -1867,6 +1873,7 @@  process_i386_opcodes (FILE *table)
   for (j = 0; j < i; j++)
     {
       struct opcode_hash_entry *next;
+      bool first_pass2 = false;
 
       for (next = opcode_array[j]; next; next = next->next)
 	{
@@ -1875,6 +1882,14 @@  process_i386_opcodes (FILE *table)
 	  lineno = next->lineno;
 	  last = str + strlen (str);
 	  output_i386_opcode (table, name, str, last, lineno);
+
+	  if (next == opcode_array[j])
+	    first_pass2 = active_pass2;
+	  else if (!first_pass2 && active_pass2)
+	    fprintf (stderr,
+		     "Warning: %s:%d: %s: "
+		     "'Pass2' is recognized only on the first template in a group\n",
+		     filename, lineno, name);
 	}
     }
 
--- a/opcodes/i386-opc.h
+++ b/opcodes/i386-opc.h
@@ -504,6 +504,9 @@  enum
      Normally, it will be encoded in the reg field. We add a RegMem
      flag to indicate that it should be encoded in the regmem field.  */
   RegMem,
+  /* The (unsuffixed) mnemonic represents itself the suffixed form of another
+     mnemonic, potentially requiring a second parsing pass.  */
+  Pass2,
   /* quick test if branch instruction is MPX supported */
   BNDPrefixOk,
   /* fake an extra reg operand for clr, imul and special register
@@ -730,6 +733,7 @@  typedef struct i386_opcode_modifier
   unsigned int fwait:1;
   unsigned int isstring:2;
   unsigned int regmem:1;
+  unsigned int pass2:1;
   unsigned int bndprefixok:1;
   unsigned int regkludge:1;
   unsigned int implicit1stxmm0:1;