Commit 75b2b67e6a for qemu.org

commit 75b2b67e6a950f731fb7c44ff1f48a7ebd455e89
Author: Paolo Bonzini <pbonzini@redhat.com>
Date:   Tue Nov 3 15:27:48 2026 +0100

    tests/tcg: fix load/restore for test-avx and test-mmx

    If "r"(&result) uses %rsp, which GCC16 seems eager to do,
    the comparison fails because run_test()'s assembly block
    moves %rsp below the red zone.  Use fixed registers instead.

    Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

diff --git a/tests/tcg/i386/test-avx.c b/tests/tcg/i386/test-avx.c
index 80fe363cfc..bb37f7953d 100644
--- a/tests/tcg/i386/test-avx.c
+++ b/tests/tcg/i386/test-avx.c
@@ -150,9 +150,10 @@ static void run_test(const TestDef *t)
             "push rbx\n\t"
             "push rcx\n\t"
             "push rdx\n\t"
-            "push %1\n\t"
-            "push %2\n\t"
-            "mov rax, %0\n\t"
+            "push rsi\n\t"
+            "push rdi\n\t"
+            "push rsi\n\t" // result
+            "push rdi\n\t" // fn
             "pushf\n\t"
             "pop rbx\n\t"
             "shr rbx, 8\n\t"
@@ -165,19 +166,21 @@ static void run_test(const TestDef *t)
             REG(LOADREG)
             "mov rax, 0x240[rax]\n\t"
             "call [rsp]\n\t"
-            "mov [rsp], rax\n\t"
-            "mov rax, 8[rsp]\n\t"
+            "mov [rsp], rax\n\t" // save rax
+            "mov rax, 8[rsp]\n\t" // get back result
             REG(STOREREG)
             "mov rbx, [rsp]\n\t"
-            "mov 0x240[rax], rbx\n\t"
+            "mov 0x240[rax], rbx\n\t"  // rax
             "mov rbx, 0\n\t"
-            "mov 0x270[rax], rbx\n\t"
-            "mov 0x278[rax], rbx\n\t"
+            "mov 0x270[rax], rbx\n\t"  // rsp
+            "mov 0x278[rax], rbx\n\t"  // rbp
             "pushf\n\t"
             "pop rbx\n\t"
             "and rbx, 0xff\n\t"
             "mov 0x2c0[rax], rbx\n\t"
             "add rsp, 16\n\t"
+            "pop rdi\n\t"
+            "pop rsi\n\t"
             "pop rdx\n\t"
             "pop rcx\n\t"
             "pop rbx\n\t"
@@ -185,9 +188,8 @@ static void run_test(const TestDef *t)
             "add rsp, 128\n\t"
             MMREG(STOREMM)
             YMMREG(STOREYMM)
-            : : "r"(init), "r"(&result), "r"(t->fn)
+            : : "a"(init), "S"(&result), "D"(t->fn)
             : "memory", "cc",
-            "rsi", "rdi",
             "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
             "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
             "ymm0", "ymm1", "ymm2", "ymm3", "ymm4", "ymm5",
diff --git a/tests/tcg/i386/test-mmx.c b/tests/tcg/i386/test-mmx.c
index 09e5d583ff..1a640f8bbb 100644
--- a/tests/tcg/i386/test-mmx.c
+++ b/tests/tcg/i386/test-mmx.c
@@ -154,9 +154,10 @@ static void run_test(const TestDef *t)
             "push rbx\n\t"
             "push rcx\n\t"
             "push rdx\n\t"
-            "push %1\n\t"
-            "push %2\n\t"
-            "mov rax, %0\n\t"
+            "push rsi\n\t"
+            "push rdi\n\t"
+            "push rsi\n\t" // result
+            "push rdi\n\t" // fn
             "pushf\n\t"
             "pop rbx\n\t"
             "shr rbx, 8\n\t"
@@ -169,19 +170,21 @@ static void run_test(const TestDef *t)
             REG(LOADREG)
             "mov rax, 0xc0[rax]\n\t"
             "call [rsp]\n\t"
-            "mov [rsp], rax\n\t"
-            "mov rax, 8[rsp]\n\t"
+            "mov [rsp], rax\n\t" // save rax
+            "mov rax, 8[rsp]\n\t" // get back result
             REG(STOREREG)
             "mov rbx, [rsp]\n\t"
-            "mov 0xc0[rax], rbx\n\t"
+            "mov 0xc0[rax], rbx\n\t"  // rax
             "mov rbx, 0\n\t"
-            "mov 0xf0[rax], rbx\n\t"
-            "mov 0xf8[rax], rbx\n\t"
+            "mov 0xf0[rax], rbx\n\t"  // rsp
+            "mov 0xf8[rax], rbx\n\t"  // rbp
             "pushf\n\t"
             "pop rbx\n\t"
             "and rbx, 0xff\n\t"
             "mov 0x140[rax], rbx\n\t"
             "add rsp, 16\n\t"
+            "pop rdi\n\t"
+            "pop rsi\n\t"
             "pop rdx\n\t"
             "pop rcx\n\t"
             "pop rbx\n\t"
@@ -190,9 +193,8 @@ static void run_test(const TestDef *t)
             MMREG(STOREMM)
 	    EMMS "\n\t"
             XMMREG(STOREXMM)
-            : : "r"(init), "r"(&result), "r"(t->fn)
+            : : "a"(init), "S"(&result), "D"(t->fn)
             : "memory", "cc",
-            "rsi", "rdi",
             "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
             "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
             "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5",