From 65d528856352715efa5ea8b88ab082a9cb156373 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 25 Feb 2021 23:09:01 -0500 Subject: [PATCH] tcg: Fix do_nonatomic_op_* vs signed operations The smin/smax/umin/umax operations require the operands to be properly sign extended. Do not drop the MO_SIGN bit from the load, and additionally extend the val input. Backports commit 852f933e482518797f7785a2e017a215b88df815 from qemu --- qemu/tcg/tcg-op.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/qemu/tcg/tcg-op.c b/qemu/tcg/tcg-op.c index 33220a59..d530738d 100644 --- a/qemu/tcg/tcg-op.c +++ b/qemu/tcg/tcg-op.c @@ -3201,8 +3201,9 @@ static void do_nonatomic_op_i32(TCGContext *s, memop = tcg_canonicalize_memop(memop, 0, 0); - tcg_gen_qemu_ld_i32(s->uc, t1, addr, idx, memop & ~MO_SIGN); - gen(s, t2, t1, val); + tcg_gen_qemu_ld_i32(s->uc, t1, addr, idx, memop); + tcg_gen_ext_i32(s, t2, val, memop); + gen(s, t2, t1, t2); tcg_gen_qemu_st_i32(s->uc, t2, addr, idx, memop); tcg_gen_ext_i32(s, ret, (new_val ? t2 : t1), memop); @@ -3246,8 +3247,9 @@ static void do_nonatomic_op_i64(TCGContext *s, memop = tcg_canonicalize_memop(memop, 1, 0); - tcg_gen_qemu_ld_i64(s->uc, t1, addr, idx, memop & ~MO_SIGN); - gen(s, t2, t1, val); + tcg_gen_qemu_ld_i64(s->uc, t1, addr, idx, memop); + tcg_gen_ext_i64(s, t2, val, memop); + gen(s, t2, t1, t2); tcg_gen_qemu_st_i64(s->uc, t2, addr, idx, memop); tcg_gen_ext_i64(s, ret, (new_val ? t2 : t1), memop);