Skip to contentSkip to conversation

target/i386/tcg: fix SETCC(zu) optimization

PATCH In review Paolo Bonzini 2 participants 2 messages Nov 9 – Nov 13

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.
as bytes.

---
 target/i386/tcg/decode-new.c.inc | 3 ---
 target/i386/tcg/emit.c.inc       | 8 ++++++++
 2 files changed, 8 insertions(+), 3 deletions(-)
target/i386/tcg/decode-new.c.inc +0 -3
index b51b2f1ae9d..f14851d0143 100644
@@ -2107,9 +2107,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];
     }
target/i386/tcg/emit.c.inc +8 -0
index b3029f6fbbe..49d33223f41 100644
@@ -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)
Signature · 1 line
2.56.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Paolo Bonzini

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.
as bytes.

Quoted 5 lines
---
  target/i386/tcg/decode-new.c.inc | 3 ---
  target/i386/tcg/emit.c.inc       | 8 ++++++++
  2 files changed, 8 insertions(+), 3 deletions(-)

r~