[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 23/30] x86emul: support APX+CMPccXADD insns


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 11 Nov 2026 15:29:48 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID"
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>
  • Delivery-date: Wed, 11 Nov 2026 14:29:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

This group of promoted-from-VEX insns is again handled by transforming
to the VEX counterparts.

In the test harness'es predicates tables also replace the original (VEX)
entries to use the available CND().

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/tools/tests/x86_emulator/evex-disp8.c
+++ b/tools/tests/x86_emulator/evex-disp8.c
@@ -1096,6 +1096,13 @@ static const struct test apx_nci[] = {
 #undef COND
 };
 
+static const struct test cmpccxadd[] = {
+#define COND(c, n) \
+    INSN(cmp##c##xadd, 66, 0f38, e0 | (n), el, dq, no)
+    CONDS(),
+#undef COND
+};
+
 #undef CONDS
 
 static const struct test adx[] = {
@@ -1737,6 +1744,7 @@ void evex_disp8_test(void *instr, struct
         RUN(avx512bw);
         RUN(bmi1);
         RUN(bmi2);
+        RUN(cmpccxadd);
 
 #undef RUN
 
--- a/tools/tests/x86_emulator/predicates.c
+++ b/tools/tests/x86_emulator/predicates.c
@@ -1422,22 +1422,7 @@ static const struct vex {
     { { 0xdd }, 2, T, R, pfx_66, WIG, Ln }, /* vaesenclast */
     { { 0xde }, 2, T, R, pfx_66, WIG, Ln }, /* vaesdec */
     { { 0xdf }, 2, T, R, pfx_66, WIG, Ln }, /* vaesdeclast */
-    { { 0xe0 }, 2, F, W, pfx_66, Wn, L0 }, /* cmpoxadd */
-    { { 0xe1 }, 2, F, W, pfx_66, Wn, L0 }, /* cmpnoxadd */
-    { { 0xe2 }, 2, F, W, pfx_66, Wn, L0 }, /* cmpbxadd */
-    { { 0xe3 }, 2, F, W, pfx_66, Wn, L0 }, /* cmpnbxadd */
-    { { 0xe4 }, 2, F, W, pfx_66, Wn, L0 }, /* cmpexadd */
-    { { 0xe5 }, 2, F, W, pfx_66, Wn, L0 }, /* cmpnexadd */
-    { { 0xe6 }, 2, F, W, pfx_66, Wn, L0 }, /* cmpbexadd */
-    { { 0xe7 }, 2, F, W, pfx_66, Wn, L0 }, /* cmpaxadd */
-    { { 0xe8 }, 2, F, W, pfx_66, Wn, L0 }, /* cmpsxadd */
-    { { 0xe9 }, 2, F, W, pfx_66, Wn, L0 }, /* cmpnsxadd */
-    { { 0xea }, 2, F, W, pfx_66, Wn, L0 }, /* cmppxadd */
-    { { 0xeb }, 2, F, W, pfx_66, Wn, L0 }, /* cmpnpxadd */
-    { { 0xec }, 2, F, W, pfx_66, Wn, L0 }, /* cmplxadd */
-    { { 0xed }, 2, F, W, pfx_66, Wn, L0 }, /* cmpgexadd */
-    { { 0xee }, 2, F, W, pfx_66, Wn, L0 }, /* cmplexadd */
-    { { 0xef }, 2, F, W, pfx_66, Wn, L0 }, /* cmpgxadd */
+    CND(0xe0,   2, F, W, pfx_66, Wn, L0 ), /* cmp<cc>xadd */
     { { 0xf2 }, 2, T, R, pfx_no, Wn, L0 }, /* andn */
     { { 0xf3, 0x08 }, 2, T, R, pfx_no, Wn, L0 }, /* blsr */
     { { 0xf3, 0x10 }, 2, T, R, pfx_no, Wn, L0 }, /* blsmsk */
@@ -2067,6 +2052,7 @@ static const struct evex {
     { { 0xde }, 2, T, R, pfx_66, WIG, Ln }, /* vaesdec */
     { { 0xdf }, 2, T, R, pfx_66, WIG, Ln }, /* vaesdeclast */
 #ifdef __x86_64__
+    CND(0xe0,   2, F, W, pfx_66, Wn, L0 ), /* cmp<cc>xadd */
     { { 0xf2 }, 2, T, R, pfx_no, Wn, L0 }, /* andn */
     { { 0xf3, 0x08 }, 2, T, R, pfx_no, Wn, L0 }, /* blsr */
     { { 0xf3, 0x10 }, 2, T, R, pfx_no, Wn, L0 }, /* blsmsk */
--- a/tools/tests/x86_emulator/test_x86_emulator.c
+++ b/tools/tests/x86_emulator/test_x86_emulator.c
@@ -2293,6 +2293,41 @@ int main(int argc, char **argv)
              (res[2] + 1) )
             goto fail;
         printf("okay\n");
+
+        if ( cpu_has_apx_f )
+        {
+            printf("%-40s", "Testing cmpnpxadd %ebx,%r9d,-4(%r18)...");
+            instr[0] = 0x62; instr[1] = 0x7a; instr[2] = 0x65; instr[3] = 0x08;
+            instr[4] = 0xeb; instr[5] = 0x4a; instr[6] = 0xfc;
+            regs.rip = (unsigned long)&instr[0];
+            load_egpr(18, (unsigned long)(res + 2));
+            rc = x86_emulate(&ctxt, &emulops);
+            if ( (rc != X86EMUL_OKAY) ||
+                 (regs.rip != (unsigned long)&instr[7]) ||
+                 (regs.r9 != 0x13253749) ||
+                 (regs.rbx != 0x02030405) ||
+                 ((regs.eflags & EFLAGS_MASK) !=
+                  (EFLAGS_ALWAYS_SET | X86_EFLAGS_PF)) ||
+                 (res[0] + 1) ||
+                 (res[1] != 0x13253749) ||
+                 (res[2] + 1) )
+                goto fail;
+
+            regs.rip = (unsigned long)&instr[0];
+            regs.r9 <<= 8;
+            rc = x86_emulate(&ctxt, &emulops);
+            if ( (rc != X86EMUL_OKAY) ||
+                 (regs.rip != (unsigned long)&instr[7]) ||
+                 (regs.r9 != 0x13253749) ||
+                 (regs.rbx != 0x02030405) ||
+                 ((regs.eflags & EFLAGS_MASK) !=
+                  (EFLAGS_ALWAYS_SET | X86_EFLAGS(CF, SF))) ||
+                 (res[0] + 1) ||
+                 (res[1] != 0x15283b4e) ||
+                 (res[2] + 1) )
+                goto fail;
+            printf("okay\n");
+        }
     }
     else
         printf("skipped\n");
--- a/xen/arch/x86/x86_emulate/decode.c
+++ b/xen/arch/x86/x86_emulate/decode.c
@@ -1267,6 +1267,8 @@ decode_0f38(struct x86_emulate_state *s,
     case X86EMUL_OPC_VEX_F2(0, 0xf7): /* shrx */
         break;
 
+    case X86EMUL_OPC_EVEX_66(0, 0xe0) ...
+         X86EMUL_OPC_EVEX_66(0, 0xef): /* cmp<cc>xadd */
     case X86EMUL_OPC_EVEX(0, 0xf2):    /* andn */
     case X86EMUL_OPC_EVEX(0, 0xf3):    /* Grp 17 */
     case X86EMUL_OPC_EVEX(0, 0xf5):    /* bzhi */
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -7323,6 +7323,10 @@ x86_emulate(
 
 #endif /* !X86EMUL_NO_SIMD */
 
+    case X86EMUL_OPC_EVEX_66(0x0f38, 0xe0) ...
+         X86EMUL_OPC_EVEX_66(0x0f38, 0xef): /* cmp<cc>xadd r,r,m */
+        generate_exception_if(evex.lr || evex.brs || evex.opmsk, X86_EXC_UD);
+        fallthrough;
     case X86EMUL_OPC_VEX_66(0x0f38, 0xe0) ...
          X86EMUL_OPC_VEX_66(0x0f38, 0xef): /* cmp<cc>xadd r,r,m */
         generate_exception_if(!mode_64bit() || dst.type != OP_MEM || vex.l,
@@ -9355,6 +9359,7 @@ x86_emulate(
 #undef rex_prefix
 #undef lock_prefix
 #undef vex
+#undef evex
 #undef ea
 
 int x86_emul_rmw(
@@ -9443,6 +9448,8 @@ int x86_emul_rmw(
         pvex->b = 1;
         pvex->r = 1;
         pvex->reg = 0xf; /* rAX */
+        if ( s->promoted_evex )
+            pvex->opcx &= 7; /* See copy_VEX(). */
         buf[3] = ctxt->opcode;
         buf[4] = 0x11; /* reg=rDX r/m=(%RCX) */
         place_ret(&buf[5]);




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.