Skip to content

Commit 852f933

Browse files
committed
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. Reviewed-by: LIU Zhiwei <[email protected]> Reported-by: LIU Zhiwei <[email protected]> Signed-off-by: Richard Henderson <[email protected]> Message-Id: <[email protected]>
1 parent 94248cf commit 852f933

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tcg/tcg-op.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,8 +3189,9 @@ static void do_nonatomic_op_i32(TCGv_i32 ret, TCGv addr, TCGv_i32 val,
31893189

31903190
memop = tcg_canonicalize_memop(memop, 0, 0);
31913191

3192-
tcg_gen_qemu_ld_i32(t1, addr, idx, memop & ~MO_SIGN);
3193-
gen(t2, t1, val);
3192+
tcg_gen_qemu_ld_i32(t1, addr, idx, memop);
3193+
tcg_gen_ext_i32(t2, val, memop);
3194+
gen(t2, t1, t2);
31943195
tcg_gen_qemu_st_i32(t2, addr, idx, memop);
31953196

31963197
tcg_gen_ext_i32(ret, (new_val ? t2 : t1), memop);
@@ -3232,8 +3233,9 @@ static void do_nonatomic_op_i64(TCGv_i64 ret, TCGv addr, TCGv_i64 val,
32323233

32333234
memop = tcg_canonicalize_memop(memop, 1, 0);
32343235

3235-
tcg_gen_qemu_ld_i64(t1, addr, idx, memop & ~MO_SIGN);
3236-
gen(t2, t1, val);
3236+
tcg_gen_qemu_ld_i64(t1, addr, idx, memop);
3237+
tcg_gen_ext_i64(t2, val, memop);
3238+
gen(t2, t1, t2);
32373239
tcg_gen_qemu_st_i64(t2, addr, idx, memop);
32383240

32393241
tcg_gen_ext_i64(ret, (new_val ? t2 : t1), memop);

0 commit comments

Comments
 (0)