[2/5] x86/SSE2AVX: move checking

Message ID 60c8dd45-52ec-4791-9250-5de996c6a948@suse.com
State New
Headers
Series x86/APX: respect -msse2avx |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed

Commit Message

Jan Beulich March 22, 2024, 9:27 a.m. UTC
  It has always been looking a little odd to me that this was done deep
in cpu_flags_match(). Move it to match_template() itself - there's no
need to do anything complex when encountering such a template while it
cannot possibly be used.
  

Comments

Cui, Lili March 27, 2024, 9:38 a.m. UTC | #1
> It has always been looking a little odd to me that this was done deep in
> cpu_flags_match(). Move it to match_template() itself - there's no need to do
> anything complex when encountering such a template while it cannot possibly
> be used.
> 
> --- a/gas/config/tc-i386.c
> +++ b/gas/config/tc-i386.c
> @@ -1980,17 +1980,7 @@ cpu_flags_match (const insn_template *t)
> 
>        cpu = cpu_flags_and (any, active);
>        if (cpu_flags_all_zero (&any) || !cpu_flags_all_zero (&cpu))
> -	{
> -	  if (all.bitfield.cpuavx)
> -	    {
> -	      /* We need to check SSE2AVX with AVX.  */
> -	      if (!t->opcode_modifier.sse2avx
> -		  || (sse2avx && !i.prefix[DATA_PREFIX]))
> -		match |= CPU_FLAGS_ARCH_MATCH;
> -	    }
> -	  else
> -	    match |= CPU_FLAGS_ARCH_MATCH;
> -	}
> +	match |= CPU_FLAGS_ARCH_MATCH;
>      }
>    return match;
>  }
> @@ -8542,6 +8532,15 @@ match_template (char mnem_suffix)
>        if (i.operands != t->operands)
>  	continue;
> 
> +      /* Skip SSE2AVX templates when inapplicable.  */
> +      if (t->opcode_modifier.sse2avx
> +	  && (!sse2avx || i.prefix[DATA_PREFIX]))
> +	{
> +	  /* Another non-SSE2AVX template has to follow.  */
> +	  gas_assert (t + 1 < current_templates.end);
> +	  continue;
> +	}
> +
>        /* Check processor support.  */
>        specific_error = progress (unsupported);
>        if (cpu_flags_match (t) != CPU_FLAGS_PERFECT_MATCH)

It makes sense to put this together with other checks of whether the input matches the template.

Lili.
  

Patch

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -1980,17 +1980,7 @@  cpu_flags_match (const insn_template *t)
 
       cpu = cpu_flags_and (any, active);
       if (cpu_flags_all_zero (&any) || !cpu_flags_all_zero (&cpu))
-	{
-	  if (all.bitfield.cpuavx)
-	    {
-	      /* We need to check SSE2AVX with AVX.  */
-	      if (!t->opcode_modifier.sse2avx
-		  || (sse2avx && !i.prefix[DATA_PREFIX]))
-		match |= CPU_FLAGS_ARCH_MATCH;
-	    }
-	  else
-	    match |= CPU_FLAGS_ARCH_MATCH;
-	}
+	match |= CPU_FLAGS_ARCH_MATCH;
     }
   return match;
 }
@@ -8542,6 +8532,15 @@  match_template (char mnem_suffix)
       if (i.operands != t->operands)
 	continue;
 
+      /* Skip SSE2AVX templates when inapplicable.  */
+      if (t->opcode_modifier.sse2avx
+	  && (!sse2avx || i.prefix[DATA_PREFIX]))
+	{
+	  /* Another non-SSE2AVX template has to follow.  */
+	  gas_assert (t + 1 < current_templates.end);
+	  continue;
+	}
+
       /* Check processor support.  */
       specific_error = progress (unsupported);
       if (cpu_flags_match (t) != CPU_FLAGS_PERFECT_MATCH)