Commit 66f2933c8a for qemu.org
commit 66f2933c8a35b5efe1d4870089adfc5c89d0192f
Author: Paolo Bonzini <pbonzini@redhat.com>
Date: Mon Nov 2 00:20:00 2026 +0100
target/i386/tcg: fix SETCC(zu) optimization
With EVEX.ND=1, SETcc zero extends its result to the whole register, which
validate_evex_apx() requests with EXT_Unsigned. QEMU is trying to
avoid the extension by changing the size of the operand, but it sets
a field of the row that is unused, because op1 is None.
Do it in gen_SETcc() instead. The result of setcc is 0 or 1, so writing
the whole register has the same effect as the zero extension, and
gen_writeback() skips the extension.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.c.inc
index 5b3d772d99..e985b12889 100644
--- a/target/i386/tcg/decode-new.c.inc
+++ b/target/i386/tcg/decode-new.c.inc
@@ -2109,9 +2109,6 @@ static void decode_EVEX4cc(DisasContext *s, CPUX86State *env, X86OpEntry *entry,
if (s->prefix & PREFIX_REPNZ) {
*entry = setcc;
- if (EVEX_APX_ND(s)) {
- entry->s1 = X86_SIZE_q; /* optimization for zu */
- }
} else {
*entry = (EVEX_APX_ND(s) ? cfcmov_nd1 : cfcmov_nd0)[EVEX_APX_NF(s)][mod == 3];
}
diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc
index b3029f6fbb..49d33223f4 100644
--- a/target/i386/tcg/emit.c.inc
+++ b/target/i386/tcg/emit.c.inc
@@ -4136,6 +4136,14 @@ static void gen_SCAS(DisasContext *s, X86DecodedInsn *decode)
static void gen_SETcc(DisasContext *s, X86DecodedInsn *decode)
{
gen_setcc(s, decode->b & 0xf, s->T0);
+
+ /*
+ * With APX ZU, the written value requests zero extension. Since T0 is
+ * 0 or 1, writing the whole register is the same and saves the extension.
+ */
+ if (decode->op[0].ext == X86_EXT_Unsigned && !decode->op[0].has_ea) {
+ decode->op[0].ot = MO_TL;
+ }
}
static void gen_SFENCE(DisasContext *s, X86DecodedInsn *decode)