[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 01/23] target/arm: Fix return value from LDSMIN/LDSMAX 8/16 bi
From: |
Peter Maydell |
Subject: |
[PATCH v2 01/23] target/arm: Fix return value from LDSMIN/LDSMAX 8/16 bit atomics |
Date: |
Sun, 11 Jun 2023 17:00:10 +0100 |
The atomic memory operations are supposed to return the old memory
data value in the destination register. This value is not
sign-extended, even if the operation is the signed minimum or
maximum. (In the pseudocode for the instructions the returned data
value is passed to ZeroExtend() to create the value in the register.)
We got this wrong because we were doing a 32-to-64 zero extend on the
result for 8 and 16 bit data values, rather than the correct amount
of zero extension.
Fix the bug by using ext8u and ext16u for the MO_8 and MO_16 data
sizes rather than ext32u.
Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20230602155223.2040685-2-peter.maydell@linaro.org
---
target/arm/tcg/translate-a64.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
index aa93f37e216..246e3c15145 100644
--- a/target/arm/tcg/translate-a64.c
+++ b/target/arm/tcg/translate-a64.c
@@ -3545,8 +3545,22 @@ static void disas_ldst_atomic(DisasContext *s, uint32_t
insn,
*/
fn(tcg_rt, clean_addr, tcg_rs, get_mem_index(s), mop);
- if ((mop & MO_SIGN) && size != MO_64) {
- tcg_gen_ext32u_i64(tcg_rt, tcg_rt);
+ if (mop & MO_SIGN) {
+ switch (size) {
+ case MO_8:
+ tcg_gen_ext8u_i64(tcg_rt, tcg_rt);
+ break;
+ case MO_16:
+ tcg_gen_ext16u_i64(tcg_rt, tcg_rt);
+ break;
+ case MO_32:
+ tcg_gen_ext32u_i64(tcg_rt, tcg_rt);
+ break;
+ case MO_64:
+ break;
+ default:
+ g_assert_not_reached();
+ }
}
}
--
2.34.1
- [PATCH v2 00/23] target/arm: Convert exception, system, loads and stores to decodetree, Peter Maydell, 2023/06/11
- [PATCH v2 03/23] target/arm: Pass memop to gen_mte_check1_mmuidx() in reg_imm9 decode, Peter Maydell, 2023/06/11
- [PATCH v2 01/23] target/arm: Fix return value from LDSMIN/LDSMAX 8/16 bit atomics,
Peter Maydell <=
- [PATCH v2 08/23] target/arm: Convert MSR (immediate) to decodetree, Peter Maydell, 2023/06/11
- [PATCH v2 11/23] target/arm: Convert load/store exclusive and ordered to decodetree, Peter Maydell, 2023/06/11
- [PATCH v2 16/23] target/arm: Convert LDR/STR with 12-bit immediate to decodetree, Peter Maydell, 2023/06/11
- [PATCH v2 22/23] target/arm: Convert load/store single structure to decodetree, Peter Maydell, 2023/06/11
- [PATCH v2 13/23] target/arm: Convert load reg (literal) group to decodetree, Peter Maydell, 2023/06/11
- [PATCH v2 09/23] target/arm: Convert MSR (reg), MRS, SYS, SYSL to decodetree, Peter Maydell, 2023/06/11
- [PATCH v2 07/23] target/arm: Convert CFINV, XAFLAG and AXFLAG to decodetree, Peter Maydell, 2023/06/11
- [PATCH v2 06/23] target/arm: Convert barrier insns to decodetree, Peter Maydell, 2023/06/11