* [PATCH] target/i386: fix operand size for DATA16 REX.W POPCNT
@ 2024-05-09 15:25 Paolo Bonzini
2024-05-10 9:20 ` Richard Henderson
2024-05-10 11:25 ` Zhao Liu
0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2024-05-09 15:25 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable
According to the manual, 32-bit vs 64-bit is governed by REX.W
and REX ignores the 0x66 prefix. This can be confirmed with this
program:
#include <stdio.h>
int main()
{
int x = 0x12340000;
int y;
asm("popcntl %1, %0" : "=r" (y) : "r" (x)); printf("%x\n", y);
asm("mov $-1, %0; .byte 0x66; popcntl %1, %0" : "+r" (y) : "r" (x)); printf("%x\n", y);
asm("mov $-1, %0; .byte 0x66; popcntq %q1, %q0" : "+r" (y) : "r" (x)); printf("%x\n", y);
}
which prints 5/ffff0000/5 on real hardware and 5/ffff0000/ffff0000
on QEMU.
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/tcg/translate.c | 17 +----------------
1 file changed, 1 insertion(+), 16 deletions(-)
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index 7d9f6b5c55b..5366dc32dd3 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -411,16 +411,6 @@ static inline MemOp mo_stacksize(DisasContext *s)
return CODE64(s) ? MO_64 : SS32(s) ? MO_32 : MO_16;
}
-/* Select only size 64 else 32. Used for SSE operand sizes. */
-static inline MemOp mo_64_32(MemOp ot)
-{
-#ifdef TARGET_X86_64
- return ot == MO_64 ? MO_64 : MO_32;
-#else
- return MO_32;
-#endif
-}
-
/* Select size 8 if lsb of B is clear, else OT. Used for decoding
byte vs word opcodes. */
static inline MemOp mo_b_d(int b, MemOp ot)
@@ -4545,12 +4535,7 @@ static void disas_insn_old(DisasContext *s, CPUState *cpu, int b)
modrm = x86_ldub_code(env, s);
reg = ((modrm >> 3) & 7) | REX_R(s);
- if (s->prefix & PREFIX_DATA) {
- ot = MO_16;
- } else {
- ot = mo_64_32(dflag);
- }
-
+ ot = dflag;
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0);
gen_extu(ot, s->T0);
tcg_gen_mov_tl(cpu_cc_src, s->T0);
--
2.45.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] target/i386: fix operand size for DATA16 REX.W POPCNT
2024-05-09 15:25 [PATCH] target/i386: fix operand size for DATA16 REX.W POPCNT Paolo Bonzini
@ 2024-05-10 9:20 ` Richard Henderson
2024-05-10 11:25 ` Zhao Liu
1 sibling, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2024-05-10 9:20 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: qemu-stable
On 5/9/24 17:25, Paolo Bonzini wrote:
> According to the manual, 32-bit vs 64-bit is governed by REX.W
> and REX ignores the 0x66 prefix. This can be confirmed with this
> program:
>
> #include <stdio.h>
> int main()
> {
> int x = 0x12340000;
> int y;
> asm("popcntl %1, %0" : "=r" (y) : "r" (x)); printf("%x\n", y);
> asm("mov $-1, %0; .byte 0x66; popcntl %1, %0" : "+r" (y) : "r" (x)); printf("%x\n", y);
> asm("mov $-1, %0; .byte 0x66; popcntq %q1, %q0" : "+r" (y) : "r" (x)); printf("%x\n", y);
> }
>
> which prints 5/ffff0000/5 on real hardware and 5/ffff0000/ffff0000
> on QEMU.
>
> Cc:qemu-stable@nongnu.org
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
> ---
> target/i386/tcg/translate.c | 17 +----------------
> 1 file changed, 1 insertion(+), 16 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] target/i386: fix operand size for DATA16 REX.W POPCNT
2024-05-09 15:25 [PATCH] target/i386: fix operand size for DATA16 REX.W POPCNT Paolo Bonzini
2024-05-10 9:20 ` Richard Henderson
@ 2024-05-10 11:25 ` Zhao Liu
1 sibling, 0 replies; 3+ messages in thread
From: Zhao Liu @ 2024-05-10 11:25 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel, qemu-stable
On Thu, May 09, 2024 at 05:25:26PM +0200, Paolo Bonzini wrote:
> Date: Thu, 9 May 2024 17:25:26 +0200
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH] target/i386: fix operand size for DATA16 REX.W POPCNT
> X-Mailer: git-send-email 2.45.0
>
> According to the manual, 32-bit vs 64-bit is governed by REX.W
> and REX ignores the 0x66 prefix. This can be confirmed with this
> program:
>
> #include <stdio.h>
> int main()
> {
> int x = 0x12340000;
> int y;
> asm("popcntl %1, %0" : "=r" (y) : "r" (x)); printf("%x\n", y);
> asm("mov $-1, %0; .byte 0x66; popcntl %1, %0" : "+r" (y) : "r" (x)); printf("%x\n", y);
> asm("mov $-1, %0; .byte 0x66; popcntq %q1, %q0" : "+r" (y) : "r" (x)); printf("%x\n", y);
> }
>
> which prints 5/ffff0000/5 on real hardware and 5/ffff0000/ffff0000
> on QEMU.
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> target/i386/tcg/translate.c | 17 +----------------
> 1 file changed, 1 insertion(+), 16 deletions(-)
Awesome!
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-10 11:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-09 15:25 [PATCH] target/i386: fix operand size for DATA16 REX.W POPCNT Paolo Bonzini
2024-05-10 9:20 ` Richard Henderson
2024-05-10 11:25 ` Zhao Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).