mirror of https://github.com/xemu-project/xemu.git
target/i386: fix operand order for PDEP and PEXT
For PDEP and PEXT, the mask is provided in the memory (mod+r/m) operand, and therefore is loaded in s->T0 by gen_ldst_modrm. The source is provided in the second source operand (VEX.vvvv) and therefore is loaded in s->T1. Fix the order in which they are passed to the helpers. Reported-by: Lenard Szolnoki <blog@lenardszolnoki.com> Analyzed-by: Lenard Szolnoki <blog@lenardszolnoki.com> Fixes: https://bugs.launchpad.net/qemu/+bug/1605123 Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
379e9eaed4
commit
75b208c283
|
@ -3936,14 +3936,14 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
|
|||
}
|
||||
ot = mo_64_32(s->dflag);
|
||||
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0);
|
||||
/* Note that by zero-extending the mask operand, we
|
||||
/* Note that by zero-extending the source operand, we
|
||||
automatically handle zero-extending the result. */
|
||||
if (ot == MO_64) {
|
||||
tcg_gen_mov_tl(s->T1, cpu_regs[s->vex_v]);
|
||||
} else {
|
||||
tcg_gen_ext32u_tl(s->T1, cpu_regs[s->vex_v]);
|
||||
}
|
||||
gen_helper_pdep(cpu_regs[reg], s->T0, s->T1);
|
||||
gen_helper_pdep(cpu_regs[reg], s->T1, s->T0);
|
||||
break;
|
||||
|
||||
case 0x2f5: /* pext Gy, By, Ey */
|
||||
|
@ -3954,14 +3954,14 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
|
|||
}
|
||||
ot = mo_64_32(s->dflag);
|
||||
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0);
|
||||
/* Note that by zero-extending the mask operand, we
|
||||
/* Note that by zero-extending the source operand, we
|
||||
automatically handle zero-extending the result. */
|
||||
if (ot == MO_64) {
|
||||
tcg_gen_mov_tl(s->T1, cpu_regs[s->vex_v]);
|
||||
} else {
|
||||
tcg_gen_ext32u_tl(s->T1, cpu_regs[s->vex_v]);
|
||||
}
|
||||
gen_helper_pext(cpu_regs[reg], s->T0, s->T1);
|
||||
gen_helper_pext(cpu_regs[reg], s->T1, s->T0);
|
||||
break;
|
||||
|
||||
case 0x1f6: /* adcx Gy, Ey */
|
||||
|
|
|
@ -18,6 +18,9 @@ test-i386-pcmpistri: CFLAGS += -msse4.2
|
|||
run-test-i386-pcmpistri: QEMU_OPTS += -cpu max
|
||||
run-plugin-test-i386-pcmpistri-%: QEMU_OPTS += -cpu max
|
||||
|
||||
run-test-i386-bmi2: QEMU_OPTS += -cpu max
|
||||
run-plugin-test-i386-bmi2-%: QEMU_OPTS += -cpu max
|
||||
|
||||
#
|
||||
# hello-i386 is a barebones app
|
||||
#
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/* See if various BMI2 instructions give expected results */
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
uint64_t ehlo = 0x202020204f4c4845ull;
|
||||
uint64_t mask = 0xa080800302020001ull;
|
||||
uint32_t result32;
|
||||
|
||||
#ifdef __x86_64
|
||||
uint64_t result64;
|
||||
|
||||
/* 64 bits */
|
||||
asm volatile ("pextq %2, %1, %0" : "=r"(result64) : "r"(ehlo), "m"(mask));
|
||||
assert(result64 == 133);
|
||||
|
||||
asm volatile ("pdepq %2, %1, %0" : "=r"(result64) : "r"(result64), "m"(mask));
|
||||
assert(result64 == (ehlo & mask));
|
||||
|
||||
asm volatile ("pextq %2, %1, %0" : "=r"(result64) : "r"(-1ull), "m"(mask));
|
||||
assert(result64 == 511); /* mask has 9 bits set */
|
||||
|
||||
asm volatile ("pdepq %2, %1, %0" : "=r"(result64) : "r"(-1ull), "m"(mask));
|
||||
assert(result64 == mask);
|
||||
#endif
|
||||
|
||||
/* 32 bits */
|
||||
asm volatile ("pextl %2, %k1, %k0" : "=r"(result32) : "r"((uint32_t) ehlo), "m"(mask));
|
||||
assert(result32 == 5);
|
||||
|
||||
asm volatile ("pdepl %2, %k1, %k0" : "=r"(result32) : "r"(result32), "m"(mask));
|
||||
assert(result32 == (uint32_t)(ehlo & mask));
|
||||
|
||||
asm volatile ("pextl %2, %k1, %k0" : "=r"(result32) : "r"(-1ull), "m"(mask));
|
||||
assert(result32 == 7); /* mask has 3 bits set */
|
||||
|
||||
asm volatile ("pdepl %2, %k1, %k0" : "=r"(result32) : "r"(-1ull), "m"(mask));
|
||||
assert(result32 == (uint32_t)mask);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue