x86: also refuse data size prefix on SIMD insns
authorJan Beulich <jbeulich@suse.com>
Thu, 25 Jun 2020 07:25:12 +0000 (09:25 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 25 Jun 2020 07:25:12 +0000 (09:25 +0200)
The data size prefix alters the meaning of legacy encoded SIMD insns,
and hence shouldn't be accepted there. Use of it also leads to
inconsistencies in SSE2AVX mode. Don't match insns with data size prefix
against SSE2AVX templates.

gas/ChangeLog
gas/config/tc-i386.c
gas/testsuite/gas/i386/prefix32.l
gas/testsuite/gas/i386/prefix32.s
gas/testsuite/gas/i386/prefix64.l
gas/testsuite/gas/i386/prefix64.s
gas/testsuite/gas/i386/sse2avx.d
gas/testsuite/gas/i386/sse2avx.s

index 83f0e6f42873faafae704ea09629d930197655a7..835a5525d6e8800652efe7f10aa8fd076da6a30e 100644 (file)
@@ -1,3 +1,16 @@
+2020-06-25  Jan Beulich  <jbeulich@suse.com>
+
+       * config/tc-i386.c (cpu_flags_match): Only match SSE2AVX
+       templates when there's no data size prefix.
+       (md_assemble): Reject data size prefix also for legacy encoded
+       SIMD templates.
+       * testsuite/gas/i386/prefix32.s, testsuite/gas/i386/prefix64.s:
+       Uncomment previously not working line.
+       * testsuite/gas/i386/sse2avx.s: Add ldmxcsr/stmxcsr cases with
+       data16 prefix.
+       * testsuite/gas/i386/prefix32.l, testsuite/gas/i386/prefix64.l,
+       testsuite/gas/i386/sse2avx.d: Adjust expectations.
+
 2020-06-25  Jan Beulich  <jbeulich@suse.com>
 
        * config/tc-i386.c (build_evex_prefix): Drop early setting of
index 18f4a243d13c7ec7dd0112f6ad694d6659a13475..5a652a9b9b333273ec4ec20aad495f165b11c284 100644 (file)
@@ -1944,7 +1944,8 @@ cpu_flags_match (const insn_template *t)
            {
              /* We need to check a few extra flags with AVX.  */
              if (cpu.bitfield.cpuavx
-                 && (!t->opcode_modifier.sse2avx || sse2avx)
+                 && (!t->opcode_modifier.sse2avx
+                     || (sse2avx && !i.prefix[DATA_PREFIX]))
                  && (!x.bitfield.cpuaes || cpu.bitfield.cpuaes)
                  && (!x.bitfield.cpugfni || cpu.bitfield.cpugfni)
                  && (!x.bitfield.cpupclmul || cpu.bitfield.cpupclmul))
@@ -4787,8 +4788,11 @@ md_assemble (char *line)
       return;
     }
 
-  /* Check for data size prefix on VEX/XOP/EVEX encoded insns.  */
-  if (i.prefix[DATA_PREFIX] && is_any_vex_encoding (&i.tm))
+  /* Check for data size prefix on VEX/XOP/EVEX encoded and SIMD insns.  */
+  if (i.prefix[DATA_PREFIX]
+      && (is_any_vex_encoding (&i.tm)
+         || i.tm.operand_types[i.imm_operands].bitfield.class >= RegMMX
+         || i.tm.operand_types[i.imm_operands + 1].bitfield.class >= RegMMX))
     {
       as_bad (_("data size prefix invalid with `%s'"), i.tm.name);
       return;
index 09a00cd03d9707b11aabf9f744248f75748404ef..e43abbdc292fd96388696199ee3490824a8df55c 100644 (file)
@@ -5,7 +5,8 @@
 .*:9: Error: invalid .* `vaddss' after `repne'
 .*:14: Error: same type of prefix .*
 .*:15: Error: same type of prefix .*
-.*:19: Error: same type of prefix .*
+.*:18: Error: data size .* `addps'
+.*:19: Error: data size .* `addpd'
 .*:20: Error: data size .* `vaddps'
 .*:21: Error: data size .* `vaddpd'
 .*:25: Error: same type of prefix .*
@@ -28,9 +29,8 @@ GAS LISTING .*
 [      ]*15[   ]+rep bnd ret
 [      ]*16[   ]*
 [      ]*17[   ]+\.Ldata16:
-[      ]*18[   ]+#bogus        data16 addps    %xmm0, %xmm0
-[      ]*19[   ]+\?\?\?\? 660F58C0[    ]+data16 addpd  %xmm0, %xmm0
-\*\*\*\*  Error: .*
+[      ]*18[   ]+data16 addps  %xmm0, %xmm0
+[      ]*19[   ]+data16 addpd  %xmm0, %xmm0
 [      ]*20[   ]+data16 vaddps %xmm0, %xmm0, %xmm0
 [      ]*21[   ]+data16 vaddpd %xmm0, %xmm0, %xmm0
 [      ]*22[   ]*
index a4382a2b616117150205458f45efdba769fb5589..598b0a775b65bc2f8213cd0520f97527c2fd32a5 100644 (file)
@@ -15,7 +15,7 @@ prefix:
        rep bnd ret
 
 .Ldata16:
-#bogus data16 addps    %xmm0, %xmm0
+       data16 addps    %xmm0, %xmm0
        data16 addpd    %xmm0, %xmm0
        data16 vaddps   %xmm0, %xmm0, %xmm0
        data16 vaddpd   %xmm0, %xmm0, %xmm0
index 0659d9c04dec09cb1d34297a52e5a8fea01a7400..712f4e0d688c3b8a735498ce84bdaea2ef41f499 100644 (file)
@@ -5,7 +5,8 @@
 .*:9: Error: invalid .* `vaddss' after `repne'
 .*:14: Error: same type of prefix .*
 .*:15: Error: same type of prefix .*
-.*:19: Error: same type of prefix .*
+.*:18: Error: data size .* `addps'
+.*:19: Error: data size .* `addpd'
 .*:20: Error: data size .* `vaddps'
 .*:21: Error: data size .* `vaddpd'
 GAS LISTING .*
@@ -27,10 +28,9 @@ GAS LISTING .*
 [      ]*15[   ]+rep bnd ret
 [      ]*16[   ]*
 [      ]*17[   ]+\.Ldata16:
-[      ]*18[   ]+#bogus        data16 addps    %xmm0, %xmm0
-[      ]*19[   ]+\?\?\?\? 660F58C0[    ]+data16 addpd  %xmm0, %xmm0
-\*\*\*\*  Error: .*
+[      ]*18[   ]+data16 addps  %xmm0, %xmm0
+[      ]*19[   ]+data16 addpd  %xmm0, %xmm0
 [      ]*20[   ]+data16 vaddps %xmm0, %xmm0, %xmm0
 [      ]*21[   ]+data16 vaddpd %xmm0, %xmm0, %xmm0
 [      ]*22[   ]*
-[      ]*23[   ]*[\?]+ 0+[ \t]+\.p2align       4,0
+#pass
index 39fb4774357c43ce7838b33649dd6cc240cc6224..32091c7c05adba07904fb9644a92c8dc2da4f99b 100644 (file)
@@ -15,7 +15,7 @@ prefix:
        rep bnd ret
 
 .Ldata16:
-#bogus data16 addps    %xmm0, %xmm0
+       data16 addps    %xmm0, %xmm0
        data16 addpd    %xmm0, %xmm0
        data16 vaddps   %xmm0, %xmm0, %xmm0
        data16 vaddpd   %xmm0, %xmm0, %xmm0
index d03549125b65e9ee80fc9ea7004f76d333202a60..1a7df7165b330f57b95e59cc7b1b573779d4b896 100644 (file)
@@ -9,6 +9,8 @@ Disassembly of section .text:
 0+ <_start>:
 [      ]*[a-f0-9]+:    c5 f8 ae 11             vldmxcsr \(%ecx\)
 [      ]*[a-f0-9]+:    c5 f8 ae 19             vstmxcsr \(%ecx\)
+[      ]*[a-f0-9]+:    66 0f ae 11             data16 ldmxcsr \(%ecx\)
+[      ]*[a-f0-9]+:    66 0f ae 19             data16 stmxcsr \(%ecx\)
 [      ]*[a-f0-9]+:    c5 f8 5b f4             vcvtdq2ps %xmm4,%xmm6
 [      ]*[a-f0-9]+:    c5 f8 5b 21             vcvtdq2ps \(%ecx\),%xmm4
 [      ]*[a-f0-9]+:    c5 fb e6 f4             vcvtpd2dq %xmm4,%xmm6
index 00080cf55b4c4ad30f19e1b5283f4d61e84f6311..0ad600c3289d73dcf3a2c1ced0657bd36455d4a6 100644 (file)
@@ -7,6 +7,10 @@ _start:
        ldmxcsr (%ecx)
        stmxcsr (%ecx)
 
+# These should not be converted
+       data16 ldmxcsr (%ecx)
+       data16 stmxcsr (%ecx)
+
 # Tests for op xmm/mem128, xmm
        cvtdq2ps %xmm4,%xmm6
        cvtdq2ps (%ecx),%xmm4
This page took 0.031773 seconds and 4 git commands to generate.