All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] target/arm: Mark LDS{MIN,MAX} as signed operations
@ 2021-06-02  2:07 Richard Henderson
  2021-06-02  9:14 ` Alex Bennée
  2021-06-03  9:22 ` Peter Maydell
  0 siblings, 2 replies; 3+ messages in thread
From: Richard Henderson @ 2021-06-02  2:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-arm

The operands to tcg_gen_atomic_fetch_s{min,max}_i64 must
be signed, so that the inputs are properly extended.
Zero extend the result afterward, as needed.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/364
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/translate-a64.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
index ceac0ee2bd..d6906d9012 100644
--- a/target/arm/translate-a64.c
+++ b/target/arm/translate-a64.c
@@ -3355,8 +3355,9 @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn,
     int o3_opc = extract32(insn, 12, 4);
     bool r = extract32(insn, 22, 1);
     bool a = extract32(insn, 23, 1);
-    TCGv_i64 tcg_rs, clean_addr;
+    TCGv_i64 tcg_rs, tcg_rt, clean_addr;
     AtomicThreeOpFn *fn = NULL;
+    MemOp mop = s->be_data | size | MO_ALIGN;
 
     if (is_vector || !dc_isar_feature(aa64_atomics, s)) {
         unallocated_encoding(s);
@@ -3377,9 +3378,11 @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn,
         break;
     case 004: /* LDSMAX */
         fn = tcg_gen_atomic_fetch_smax_i64;
+        mop |= MO_SIGN;
         break;
     case 005: /* LDSMIN */
         fn = tcg_gen_atomic_fetch_smin_i64;
+        mop |= MO_SIGN;
         break;
     case 006: /* LDUMAX */
         fn = tcg_gen_atomic_fetch_umax_i64;
@@ -3422,6 +3425,7 @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn,
     }
 
     tcg_rs = read_cpu_reg(s, rs, true);
+    tcg_rt = cpu_reg(s, rt);
 
     if (o3_opc == 1) { /* LDCLR */
         tcg_gen_not_i64(tcg_rs, tcg_rs);
@@ -3430,8 +3434,11 @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn,
     /* The tcg atomic primitives are all full barriers.  Therefore we
      * can ignore the Acquire and Release bits of this instruction.
      */
-    fn(cpu_reg(s, rt), clean_addr, tcg_rs, get_mem_index(s),
-       s->be_data | size | MO_ALIGN);
+    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);
+    }
 }
 
 /*
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] target/arm: Mark LDS{MIN,MAX} as signed operations
  2021-06-02  2:07 [PATCH] target/arm: Mark LDS{MIN,MAX} as signed operations Richard Henderson
@ 2021-06-02  9:14 ` Alex Bennée
  2021-06-03  9:22 ` Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Bennée @ 2021-06-02  9:14 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-arm, qemu-devel


Richard Henderson <richard.henderson@linaro.org> writes:

> The operands to tcg_gen_atomic_fetch_s{min,max}_i64 must
> be signed, so that the inputs are properly extended.
> Zero extend the result afterward, as needed.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/364
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] target/arm: Mark LDS{MIN,MAX} as signed operations
  2021-06-02  2:07 [PATCH] target/arm: Mark LDS{MIN,MAX} as signed operations Richard Henderson
  2021-06-02  9:14 ` Alex Bennée
@ 2021-06-03  9:22 ` Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2021-06-03  9:22 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-arm, QEMU Developers

On Wed, 2 Jun 2021 at 03:07, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The operands to tcg_gen_atomic_fetch_s{min,max}_i64 must
> be signed, so that the inputs are properly extended.
> Zero extend the result afterward, as needed.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/364
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  target/arm/translate-a64.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>



Applied to target-arm.next, thanks.

-- PMM


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-03  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02  2:07 [PATCH] target/arm: Mark LDS{MIN,MAX} as signed operations Richard Henderson
2021-06-02  9:14 ` Alex Bennée
2021-06-03  9:22 ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.