[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/13] target/i386: Fix BZHI instruction
From: |
Paolo Bonzini |
Subject: |
[PULL 01/13] target/i386: Fix BZHI instruction |
Date: |
Mon, 27 Feb 2023 18:55:12 +0100 |
From: Richard Henderson <richard.henderson@linaro.org>
We did not correctly handle N >= operand size.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1374
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230114233206.3118472-1-richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/tcg/emit.c.inc | 14 +++++++-------
tests/tcg/i386/test-i386-bmi2.c | 3 +++
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc
index e61ae9a2e92d..0d01e13002a6 100644
--- a/target/i386/tcg/emit.c.inc
+++ b/target/i386/tcg/emit.c.inc
@@ -1147,20 +1147,20 @@ static void gen_BLSR(DisasContext *s, CPUX86State *env,
X86DecodedInsn *decode)
static void gen_BZHI(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
{
MemOp ot = decode->op[0].ot;
- TCGv bound;
+ TCGv bound = tcg_constant_tl(ot == MO_64 ? 63 : 31);
+ TCGv zero = tcg_constant_tl(0);
+ TCGv mone = tcg_constant_tl(-1);
- tcg_gen_ext8u_tl(s->T1, cpu_regs[s->vex_v]);
- bound = tcg_constant_tl(ot == MO_64 ? 63 : 31);
+ tcg_gen_ext8u_tl(s->T1, s->T1);
/*
* Note that since we're using BMILG (in order to get O
* cleared) we need to store the inverse into C.
*/
- tcg_gen_setcond_tl(TCG_COND_LT, cpu_cc_src, s->T1, bound);
- tcg_gen_movcond_tl(TCG_COND_GT, s->T1, s->T1, bound, bound, s->T1);
+ tcg_gen_setcond_tl(TCG_COND_LEU, cpu_cc_src, s->T1, bound);
- tcg_gen_movi_tl(s->A0, -1);
- tcg_gen_shl_tl(s->A0, s->A0, s->T1);
+ tcg_gen_shl_tl(s->A0, mone, s->T1);
+ tcg_gen_movcond_tl(TCG_COND_LEU, s->A0, s->T1, bound, s->A0, zero);
tcg_gen_andc_tl(s->T0, s->T0, s->A0);
gen_op_update1_cc(s);
diff --git a/tests/tcg/i386/test-i386-bmi2.c b/tests/tcg/i386/test-i386-bmi2.c
index 982d4abda455..0244df798778 100644
--- a/tests/tcg/i386/test-i386-bmi2.c
+++ b/tests/tcg/i386/test-i386-bmi2.c
@@ -123,6 +123,9 @@ int main(int argc, char *argv[]) {
result = bzhiq(mask, 0x1f);
assert(result == (mask & ~(-1 << 30)));
+ result = bzhiq(mask, 0x40);
+ assert(result == mask);
+
result = rorxq(0x2132435465768798, 8);
assert(result == 0x9821324354657687);
--
2.39.1
- [PULL 00/13] build, Python, target/i386 changes for 2023-02-27, Paolo Bonzini, 2023/02/27
- [PULL 01/13] target/i386: Fix BZHI instruction,
Paolo Bonzini <=
- [PULL 02/13] meson: Avoid duplicates in generated config-poison.h again, Paolo Bonzini, 2023/02/27
- [PULL 03/13] meson: stop looking for 'sphinx-build-3', Paolo Bonzini, 2023/02/27
- [PULL 04/13] configure: protect against escaping venv when running Meson, Paolo Bonzini, 2023/02/27
- [PULL 05/13] configure: Look for auxiliary Python installations, Paolo Bonzini, 2023/02/27
- [PULL 06/13] lcitool: update submodule, Paolo Bonzini, 2023/02/27
- [PULL 07/13] docs/devel: update and clarify lcitool instructions, Paolo Bonzini, 2023/02/27
- [PULL 08/13] ci, docker: update CentOS and OpenSUSE Python to non-EOL versions, Paolo Bonzini, 2023/02/27
- [PULL 09/13] MAINTAINERS: Cover RCU documentation, Paolo Bonzini, 2023/02/27
- [PULL 10/13] target/i386: add FSRM to TCG, Paolo Bonzini, 2023/02/27
- [PULL 11/13] target/i386: add FZRM, FSRS, FSRC, Paolo Bonzini, 2023/02/27