All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] target/riscv: add memory ordering required by RVTSO in ldst_stride_trans
@ 2026-11-21  9:00 WX Chen
  2026-11-24 18:52 ` Daniel Henrique Barboza
  0 siblings, 1 reply; 3+ messages in thread
From: WX Chen @ 2026-11-21  9:00 UTC (permalink / raw)
  To: qemu-devel
  Cc: Tao Tang, Palmer Dabbelt, Alistair Francis, Weiwei Li,
	Daniel Henrique Barboza, Liu Zhiwei, Chao Liu, qemu-riscv,
	WX Chen

RISCV ztso extension provide default memory ordering of:
    R -> R,  R -> W,  W -> W,  without W -> R,
but the current ldst_stride_trans hasn't any ordering listed above. This may
not satisfy the guest requirement on some weak memory ordering hosts.
This patch add the above ordering in ldst_stride_trans, who is in charge of
the following instructions:
vlse8.v, vlse16.v, vlse32.v, vlse64.v
vsse8.v, vsse16.v, vsse32.v, vsse64.v

Signed-off-by: WX Chen <wxchen0913@gmail.com>
---
 target/riscv/tcg/insn_trans/trans_rvv.c.inc | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/target/riscv/tcg/insn_trans/trans_rvv.c.inc b/target/riscv/tcg/insn_trans/trans_rvv.c.inc
index 7e1295f33e7d4b7a2ff26cbf428f6b5d9eb682ff..de6c8ba2a397b12cf0fecbe88936a4798a49bff4 100644
--- a/target/riscv/tcg/insn_trans/trans_rvv.c.inc
+++ b/target/riscv/tcg/insn_trans/trans_rvv.c.inc
@@ -880,7 +880,7 @@ typedef void gen_helper_ldst_stride(TCGv_ptr, TCGv_ptr, TCGv,
 
 static bool ldst_stride_trans(uint32_t vd, uint32_t rs1, uint32_t rs2,
                               uint32_t data, gen_helper_ldst_stride *fn,
-                              DisasContext *s)
+                              DisasContext *s, bool is_store)
 {
     TCGv_ptr dest, mask;
     TCGv base, stride;
@@ -896,10 +896,18 @@ static bool ldst_stride_trans(uint32_t vd, uint32_t rs1, uint32_t rs2,
     tcg_gen_addi_ptr(dest, tcg_env, vreg_ofs(s, vd));
     tcg_gen_addi_ptr(mask, tcg_env, vreg_ofs(s, 0));
 
+    if (is_store && s->ztso) {
+        tcg_gen_mb(TCG_MO_LD_ST | TCG_MO_ST_ST | TCG_BAR_STRL);
+    }
+
     mark_vs_dirty(s);
 
     fn(dest, mask, base, stride, tcg_env, desc);
 
+    if (!is_store && s->ztso) {
+        tcg_gen_mb(TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_BAR_LDAQ);
+    }
+
     finalize_rvv_inst(s);
     return true;
 }
@@ -924,7 +932,7 @@ static bool ld_stride_op(DisasContext *s, arg_rnfvm *a, uint8_t eew)
     data = FIELD_DP32(data, VDATA, NF, a->nf);
     data = FIELD_DP32(data, VDATA, VTA, s->vta);
     data = FIELD_DP32(data, VDATA, VMA, s->vma);
-    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s);
+    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s, false);
 }
 
 static bool ld_stride_check(DisasContext *s, arg_rnfvm* a, uint8_t eew)
@@ -958,7 +966,7 @@ static bool st_stride_op(DisasContext *s, arg_rnfvm *a, uint8_t eew)
         return false;
     }
 
-    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s);
+    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s, true);
 }
 
 static bool st_stride_check(DisasContext *s, arg_rnfvm* a, uint8_t eew)

---
base-commit: 08ed97c33c3818ef51a7c852347a28e9f66807b5
change-id: 20261121-fix-rvtso-vector-stride-39fd6f035f17

Best regards,
-- 
WX Chen <wxchen0913@gmail.com>



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

* Re: [PATCH] target/riscv: add memory ordering required by RVTSO in ldst_stride_trans
  2026-11-21  9:00 [PATCH] target/riscv: add memory ordering required by RVTSO in ldst_stride_trans WX Chen
@ 2026-11-24 18:52 ` Daniel Henrique Barboza
  2026-11-25  2:18   ` WX Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Henrique Barboza @ 2026-11-24 18:52 UTC (permalink / raw)
  To: WX Chen, qemu-devel
  Cc: Tao Tang, Palmer Dabbelt, Alistair Francis, Weiwei Li, Liu Zhiwei,
	Chao Liu, qemu-riscv



On 11/21/2026 6:00 AM, WX Chen wrote:
> RISCV ztso extension provide default memory ordering of:
>      R -> R,  R -> W,  W -> W,  without W -> R,
> but the current ldst_stride_trans hasn't any ordering listed above. This may
> not satisfy the guest requirement on some weak memory ordering hosts.
> This patch add the above ordering in ldst_stride_trans, who is in charge of
> the following instructions:
> vlse8.v, vlse16.v, vlse32.v, vlse64.v
> vsse8.v, vsse16.v, vsse32.v, vsse64.v
> 
> Signed-off-by: WX Chen <wxchen0913@gmail.com>
> ---
>   target/riscv/tcg/insn_trans/trans_rvv.c.inc | 14 +++++++++++---
>   1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/target/riscv/tcg/insn_trans/trans_rvv.c.inc b/target/riscv/tcg/insn_trans/trans_rvv.c.inc
> index 7e1295f33e7d4b7a2ff26cbf428f6b5d9eb682ff..de6c8ba2a397b12cf0fecbe88936a4798a49bff4 100644
> --- a/target/riscv/tcg/insn_trans/trans_rvv.c.inc
> +++ b/target/riscv/tcg/insn_trans/trans_rvv.c.inc
> @@ -880,7 +880,7 @@ typedef void gen_helper_ldst_stride(TCGv_ptr, TCGv_ptr, TCGv,
>   
>   static bool ldst_stride_trans(uint32_t vd, uint32_t rs1, uint32_t rs2,
>                                 uint32_t data, gen_helper_ldst_stride *fn,
> -                              DisasContext *s)
> +                              DisasContext *s, bool is_store)

Any reason to not handle ldst_index_trans, ldff_trans and ldst_whole_trans? They all
fall into the same RVTSO work you're doing here.


>   {
>       TCGv_ptr dest, mask;
>       TCGv base, stride;
> @@ -896,10 +896,18 @@ static bool ldst_stride_trans(uint32_t vd, uint32_t rs1, uint32_t rs2,
>       tcg_gen_addi_ptr(dest, tcg_env, vreg_ofs(s, vd));
>       tcg_gen_addi_ptr(mask, tcg_env, vreg_ofs(s, 0));
>   

In ldst_us_trans() we have a Ztso comment explaining why we're positioning the barriers
around the loop.  We don't need to replicate it here but it would be helpful if we
could add a comment like:

/*
  *  See ztso comment in ldst_us_trans for more info on why
  *  the barriers are put around the loop.
  */

In the helpers we ended up adding these Ztso related barriers.


Thanks,
Daniel

> +    if (is_store && s->ztso) {
> +        tcg_gen_mb(TCG_MO_LD_ST | TCG_MO_ST_ST | TCG_BAR_STRL);
> +    }
> +
>       mark_vs_dirty(s);
>   
>       fn(dest, mask, base, stride, tcg_env, desc);
>   
> +    if (!is_store && s->ztso) {
> +        tcg_gen_mb(TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_BAR_LDAQ);
> +    }
> +
>       finalize_rvv_inst(s);
>       return true;
>   }
> @@ -924,7 +932,7 @@ static bool ld_stride_op(DisasContext *s, arg_rnfvm *a, uint8_t eew)
>       data = FIELD_DP32(data, VDATA, NF, a->nf);
>       data = FIELD_DP32(data, VDATA, VTA, s->vta);
>       data = FIELD_DP32(data, VDATA, VMA, s->vma);
> -    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s);
> +    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s, false);
>   }
>   
>   static bool ld_stride_check(DisasContext *s, arg_rnfvm* a, uint8_t eew)
> @@ -958,7 +966,7 @@ static bool st_stride_op(DisasContext *s, arg_rnfvm *a, uint8_t eew)
>           return false;
>       }
>   
> -    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s);
> +    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s, true);
>   }
>   
>   static bool st_stride_check(DisasContext *s, arg_rnfvm* a, uint8_t eew)
> 
> ---
> base-commit: 08ed97c33c3818ef51a7c852347a28e9f66807b5
> change-id: 20261121-fix-rvtso-vector-stride-39fd6f035f17
> 
> Best regards,



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

* Re: [PATCH] target/riscv: add memory ordering required by RVTSO in ldst_stride_trans
  2026-11-24 18:52 ` Daniel Henrique Barboza
@ 2026-11-25  2:18   ` WX Chen
  0 siblings, 0 replies; 3+ messages in thread
From: WX Chen @ 2026-11-25  2:18 UTC (permalink / raw)
  To: Daniel Henrique Barboza, qemu-devel
  Cc: Tao Tang, Palmer Dabbelt, Alistair Francis, Weiwei Li, Liu Zhiwei,
	Chao Liu, qemu-riscv

Hi Daniel,
     Thanks for the comment!

On 11/25/26 02:52, Daniel Henrique Barboza wrote:
> Any reason to not handle ldst_index_trans, ldff_trans and 
> ldst_whole_trans? They all
> fall into the same RVTSO work you're doing here. 
No technical reason, just not sure if they should be organized as a 
patch series :D
I'll include those paths in the v2 series.

> In ldst_us_trans() we have a Ztso comment explaining why we're 
> positioning the barriers
> around the loop.  We don't need to replicate it here but it would be 
> helpful if we
> could add a comment like:
>
> /*
>  *  See ztso comment in ldst_us_trans for more info on why
>  *  the barriers are put around the loop.
>  */
>
> In the helpers we ended up adding these Ztso related barriers.
>
Indeed. I'll add them in v2.

Thanks,
Chen

>
> Thanks,
> Daniel
>
>> +    if (is_store && s->ztso) {
>> +        tcg_gen_mb(TCG_MO_LD_ST | TCG_MO_ST_ST | TCG_BAR_STRL);
>> +    }
>> +
>>       mark_vs_dirty(s);
>>         fn(dest, mask, base, stride, tcg_env, desc);
>>   +    if (!is_store && s->ztso) {
>> +        tcg_gen_mb(TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_BAR_LDAQ);
>> +    }
>> +
>>       finalize_rvv_inst(s);
>>       return true;
>>   }
>> @@ -924,7 +932,7 @@ static bool ld_stride_op(DisasContext *s, 
>> arg_rnfvm *a, uint8_t eew)
>>       data = FIELD_DP32(data, VDATA, NF, a->nf);
>>       data = FIELD_DP32(data, VDATA, VTA, s->vta);
>>       data = FIELD_DP32(data, VDATA, VMA, s->vma);
>> -    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s);
>> +    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s, 
>> false);
>>   }
>>     static bool ld_stride_check(DisasContext *s, arg_rnfvm* a, 
>> uint8_t eew)
>> @@ -958,7 +966,7 @@ static bool st_stride_op(DisasContext *s, 
>> arg_rnfvm *a, uint8_t eew)
>>           return false;
>>       }
>>   -    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s);
>> +    return ldst_stride_trans(a->rd, a->rs1, a->rs2, data, fn, s, true);
>>   }
>>     static bool st_stride_check(DisasContext *s, arg_rnfvm* a, 
>> uint8_t eew)
>>
>> ---
>> base-commit: 08ed97c33c3818ef51a7c852347a28e9f66807b5
>> change-id: 20261121-fix-rvtso-vector-stride-39fd6f035f17
>>
>> Best regards,
>


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

end of thread, other threads:[~2026-11-25  2:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21  9:00 [PATCH] target/riscv: add memory ordering required by RVTSO in ldst_stride_trans WX Chen
2026-11-24 18:52 ` Daniel Henrique Barboza
2026-11-25  2:18   ` WX Chen

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.