target/riscv: vector fixes
PATCH v15 2/10 trans_rvv.c.inc: set vstart = 0 in int scalar move insns
In reply to Daniel Henrique Barbozatrans_vmv_x_s, trans_vmv_s_x, trans_vfmv_f_s and trans_vfmv_s_f aren't setting vstart = 0 after execution. This is usually done by a helper in vector_helper.c but these functions don't use helpers.
We'll set vstart after any potential 'over' brconds, and that will also mandate a mark_vs_dirty() too.
--- target/riscv/insn_trans/trans_rvv.c.inc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +8 -2
@@ -3373,6 +3373,8 @@ static bool trans_vmv_x_s(DisasContext *s, arg_vmv_x_s *a) vec_element_loadi(s, t1, a->rs2, 0, true); tcg_gen_trunc_i64_tl(dest, t1); gen_set_gpr(s, a->rd, dest); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;
@@ -3399,8 +3401,9 @@ static bool trans_vmv_s_x(DisasContext *s, arg_vmv_s_x *a) s1 = get_gpr(s, a->rs1, EXT_NONE); tcg_gen_ext_tl_i64(t1, s1); vec_element_storei(s, a->rd, 0, t1); - mark_vs_dirty(s); gen_set_label(over); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;
@@ -3427,6 +3430,8 @@ static bool trans_vfmv_f_s(DisasContext *s, arg_vfmv_f_s *a) } mark_fs_dirty(s); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;
@@ -3452,8 +3457,9 @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_s_f *a) do_nanbox(s, t1, cpu_fpr[a->rs1]); vec_element_storei(s, a->rd, 0, t1); - mark_vs_dirty(s); gen_set_label(over); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;
Signature · 1 line
2.44.0
PATCH v15 1/10 target/riscv/vector_helper.c: set vstart = 0 in GEN_VEXT_VSLIDEUP_VX()
In reply to Daniel Henrique BarbozaThe helper isn't setting env->vstart = 0 after its execution, as it is expected from every vector instruction that completes successfully.
--- target/riscv/vector_helper.c | 1 + 1 file changed, 1 insertion(+)
target/riscv/vector_helper.c +1 -0
@@ -4781,6 +4781,7 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \ } \ *((ETYPE *)vd +H (i)) = *((ETYPE *)vs2 +H (i - offset)); \ } \ + env->vstart =0 ; \/* set tail elements to 1s */ \vext_set_elems_1s (vd, vta, vl * esz, total_elems * esz); \ }
Signature · 1 line
2.44.0
PATCH v15 8/10 trans_rvv.c.inc: remove redundant mark_vs_dirty() calls
In reply to Daniel Henrique Barbozatrans_vmv_v_i , trans_vfmv_v_f and the trans_##NAME macro from GEN_VMV_WHOLE_TRANS() are calling mark_vs_dirty() in both branches of their 'ifs'. conditionals.
Call it just once in the end like other functions are doing.
--- target/riscv/insn_trans/trans_rvv.c.inc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +3 -8
@@ -2065,7 +2065,6 @@ static bool trans_vmv_v_i(DisasContext *s, arg_vmv_v_i *a) if (s->vl_eq_vlmax && !(s->vta && s->lmul < 0)) { tcg_gen_gvec_dup_imm(s->sew, vreg_ofs(s, a->rd), MAXSZ(s), MAXSZ(s), simm); - mark_vs_dirty(s); } else { TCGv_i32 desc; TCGv_i64 s1;
@@ -2083,9 +2082,8 @@ static bool trans_vmv_v_i(DisasContext *s, arg_vmv_v_i *a) s->cfg_ptr->vlenb, data)); tcg_gen_addi_ptr(dest, tcg_env, vreg_ofs(s, a->rd)); fns[s->sew](dest, s1, tcg_env, desc); - - mark_vs_dirty(s); } + mark_vs_dirty(s); return true; } return false;
@@ -2612,7 +2610,6 @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) tcg_gen_gvec_dup_i64(s->sew, vreg_ofs(s, a->rd), MAXSZ(s), MAXSZ(s), t1); - mark_vs_dirty(s); } else { TCGv_ptr dest; TCGv_i32 desc;
@@ -2635,9 +2632,8 @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) tcg_gen_addi_ptr(dest, tcg_env, vreg_ofs(s, a->rd)); fns[s->sew - 1](dest, t1, tcg_env, desc); - - mark_vs_dirty(s); } + mark_vs_dirty(s); return true; } return false;
@@ -3560,12 +3556,11 @@ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ if (s->vstart_eq_zero) { \ tcg_gen_gvec_mov(s->sew, vreg_ofs(s, a->rd), \ vreg_ofs(s, a->rs2), maxsz, maxsz); \ - mark_vs_dirty(s); \ } else { \ tcg_gen_gvec_2_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs2), \ tcg_env, maxsz, maxsz, 0, gen_helper_vmvr_v); \ - mark_vs_dirty(s); \ } \ + mark_vs_dirty(s); \ return true; \ } \ return false; \
Signature · 1 line
2.44.0
v15 cover target/riscv: vector fixes
Hi,
The series was renamed to reflect that at this point we're fixing more things than just vstart management.
In this new version a couple fixes were added:
- patch 3 (new) fixes the memcpy endianess in 'vmvr_v', as suggested by Richard;
- patch 5 (new) fixes ldst_whole insns to now clear vstart in all cases. The fix was proposed by Max.
Another notable change was made in patch 6 (patch 4 from v14). We're not doing early exits in helpers that are gated by vstart_eq_zero. This was found to cause side-effects with insns that wants to send faults if vl = 0, and for the rest it becomes a moot check since vstart is granted to be zero beforehand.
Series based on master.
Patches missing acks: 3, 4, 5
Changes from v14:
- patch 3 (new):
- make 'vmvr_v' big endian compliant
- patch 5 (new):
- make ldst_whole insns clear vstart in all code paths
- patch 6 (patch 4 from v14):
- do not add early exits on helpers that are gated with vstart_eq_zero
- v14 link: https://lore.kernel.org/qemu-riscv/[email protected]/
Daniel Henrique Barboza (9):
target/riscv/vector_helper.c: set vstart = 0 in GEN_VEXT_VSLIDEUP_VX() trans_rvv.c.inc: set vstart = 0 in int scalar move insns target/riscv/vector_helper.c: fix 'vmvr_v' memcpy endianess target/riscv: always clear vstart in whole vec move insns target/riscv: always clear vstart for ldst_whole insns target/riscv/vector_helpers: do early exit when vstart >= vl target/riscv: remove 'over' brconds from vector trans trans_rvv.c.inc: remove redundant mark_vs_dirty() calls target/riscv/vector_helper.c: optimize loops in ldst helpers
Ivan Klokov (1):
target/riscv: enable 'vstart_eq_zero' in the end of insns
target/riscv/insn_trans/trans_rvbf16.c.inc | 18 +- target/riscv/insn_trans/trans_rvv.c.inc | 244 ++++++--------------- target/riscv/insn_trans/trans_rvvk.c.inc | 30 +-- target/riscv/translate.c | 6 + target/riscv/vcrypto_helper.c | 32 +++ target/riscv/vector_helper.c | 93 +++++++- target/riscv/vector_internals.c | 4 + target/riscv/vector_internals.h | 9 + 8 files changed, 220 insertions(+), 216 deletions(-)
Signature · 1 line
2.44.0
PATCH v15 10/10 target/riscv/vector_helper.c: optimize loops in ldst helpers
Change the for loops in ldst helpers to do a single increment in the counter, and assign it env->vstart, to avoid re-reading from vstart every time.
--- target/riscv/vector_helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/riscv/vector_helper.c +3 -3
@@ -209,7 +209,7 @@ vext_ldst_stride(void *vd, void *v0, target_ulong base,VSTART_CHECK_EARLY_EXIT (env); -for (i = env->vstart; i < env->vl; i++, env->vstart++) { +for (i = env->vstart; i < env->vl; env->vstart = ++i) { k =0 ;while (k < nf) {if (!vm && !vext_elem_mask (v0, i)) {
@@ -277,7 +277,7 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,VSTART_CHECK_EARLY_EXIT (env);/* load bytes from guest memory */ -for (i = env->vstart; i < evl; i++, env->vstart++) { +for (i = env->vstart; i < evl; env->vstart = ++i) { k =0 ;while (k < nf) {target_ulong addr = base + ((i * nf + k) << log2_esz);
@@ -393,7 +393,7 @@ vext_ldst_index(void *vd, void *v0, target_ulong base,VSTART_CHECK_EARLY_EXIT (env);/* load bytes from guest memory */ -for (i = env->vstart; i < env->vl; i++, env->vstart++) { +for (i = env->vstart; i < env->vl; env->vstart = ++i) { k =0 ;while (k < nf) {if (!vm && !vext_elem_mask (v0, i)) {
Signature · 1 line
2.44.0
PATCH v15 3/10 target/riscv/vector_helper.c: fix 'vmvr_v' memcpy endianess
In reply to Daniel Henrique Barbozavmvr_v isn't handling the case where the host might be big endian and the bytes to be copied aren't sequential.
--- target/riscv/vector_helper.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
target/riscv/vector_helper.c +9 -1
@@ -5075,9 +5075,17 @@ void HELPER(vmvr_v)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc)uint32_t startb = env->vstart * sewb;uint32_t i = startb; +if (HOST_BIG_ENDIAN && i %8 !=0 ) { +uint32_t j =ROUND_UP (i,8 ); +memcpy ((uint8_t *)vd +H1 (j -1 ), + (uint8_t *)vs2 +H1 (j -1 ), + j - i); + i = j; + } +memcpy ((uint8_t *)vd +H1 (i), (uint8_t *)vs2 +H1 (i), - maxsz - startb); + maxsz - i); env->vstart =0 ; }
Signature · 1 line
2.44.0
PATCH v15 9/10 target/riscv: enable 'vstart_eq_zero' in the end of insns
In reply to Daniel Henrique BarbozaFrom: Ivan Klokov <[email protected]>
The vstart_eq_zero flag is updated at the beginning of the translation phase from the env->vstart variable. During the execution phase all functions will set env->vstart = 0 after a successful execution, but the vstart_eq_zero flag remains the same as at the start of the block. This will wrongly cause SIGILLs in translations that requires env->vstart = 0 and might be reading vstart_eq_zero = false.
This patch adds a new finalize_rvv_inst() helper that is called at the end of each vector instruction that will both update vstart_eq_zero and do a mark_vs_dirty().
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1976
--- target/riscv/insn_trans/trans_rvbf16.c.inc | 6 +- target/riscv/insn_trans/trans_rvv.c.inc | 83 ++++++++++++---------- target/riscv/insn_trans/trans_rvvk.c.inc | 12 ++-- target/riscv/translate.c | 6 ++ 4 files changed, 59 insertions(+), 48 deletions(-)
target/riscv/insn_trans/trans_rvbf16.c.inc +3 -3
@@ -83,7 +83,7 @@ static bool trans_vfncvtbf16_f_f_w(DisasContext *ctx, arg_vfncvtbf16_f_f_w *a) ctx->cfg_ptr->vlenb, ctx->cfg_ptr->vlenb, data, gen_helper_vfncvtbf16_f_f_w); - mark_vs_dirty(ctx); + finalize_rvv_inst(ctx); return true; } return false;
@@ -108,7 +108,7 @@ static bool trans_vfwcvtbf16_f_f_v(DisasContext *ctx, arg_vfwcvtbf16_f_f_v *a) ctx->cfg_ptr->vlenb, ctx->cfg_ptr->vlenb, data, gen_helper_vfwcvtbf16_f_f_v); - mark_vs_dirty(ctx); + finalize_rvv_inst(ctx); return true; } return false;
@@ -135,7 +135,7 @@ static bool trans_vfwmaccbf16_vv(DisasContext *ctx, arg_vfwmaccbf16_vv *a) ctx->cfg_ptr->vlenb, ctx->cfg_ptr->vlenb, data, gen_helper_vfwmaccbf16_vv); - mark_vs_dirty(ctx); + finalize_rvv_inst(ctx); return true; } return false;
target/riscv/insn_trans/trans_rvv.c.inc +44 -39
343 lines not on this page · raw message
target/riscv/insn_trans/trans_rvvk.c.inc +6 -6
@@ -174,7 +174,7 @@ GEN_OPIVX_GVEC_TRANS_CHECK(vandn_vx, andcs, zvkb_vx_check) vreg_ofs(s, a->rs2), tcg_env, \ s->cfg_ptr->vlenb, s->cfg_ptr->vlenb, \ data, fns[s->sew]); \ - mark_vs_dirty(s); \ + finalize_rvv_inst(s); \ return true; \ } \ return false; \
@@ -266,7 +266,7 @@ GEN_OPIVI_WIDEN_TRANS(vwsll_vi, IMM_ZX, vwsll_vx, vwsll_vx_check) tcg_gen_addi_ptr(rd_v, tcg_env, vreg_ofs(s, a->rd)); \ tcg_gen_addi_ptr(rs2_v, tcg_env, vreg_ofs(s, a->rs2)); \ gen_helper_##NAME(rd_v, rs2_v, tcg_env, desc); \ - mark_vs_dirty(s); \ + finalize_rvv_inst(s); \ return true; \ } \ return false; \
@@ -341,7 +341,7 @@ GEN_V_UNMASKED_TRANS(vaesem_vs, vaes_check_vs, ZVKNED_EGS) tcg_gen_addi_ptr(rd_v, tcg_env, vreg_ofs(s, a->rd)); \ tcg_gen_addi_ptr(rs2_v, tcg_env, vreg_ofs(s, a->rs2)); \ gen_helper_##NAME(rd_v, rs2_v, uimm_v, tcg_env, desc); \ - mark_vs_dirty(s); \ + finalize_rvv_inst(s); \ return true; \ } \ return false; \
@@ -405,7 +405,7 @@ GEN_VI_UNMASKED_TRANS(vaeskf2_vi, vaeskf2_check, ZVKNED_EGS) s->cfg_ptr->vlenb, s->cfg_ptr->vlenb, \ data, gen_helper_##NAME); \ \ - mark_vs_dirty(s); \ + finalize_rvv_inst(s); \ return true; \ } \ return false; \
@@ -457,7 +457,7 @@ static bool trans_vsha2cl_vv(DisasContext *s, arg_rmrr *a) s->sew == MO_32 ? gen_helper_vsha2cl32_vv : gen_helper_vsha2cl64_vv); - mark_vs_dirty(s); + finalize_rvv_inst(s); return true; } return false;
@@ -488,7 +488,7 @@ static bool trans_vsha2ch_vv(DisasContext *s, arg_rmrr *a) s->sew == MO_32 ? gen_helper_vsha2ch32_vv : gen_helper_vsha2ch64_vv); - mark_vs_dirty(s); + finalize_rvv_inst(s); return true; } return false;
target/riscv/translate.c +6 -0
@@ -676,6 +676,12 @@ static void mark_vs_dirty(DisasContext *ctx)static inline void mark_vs_dirty (DisasContext *ctx) { }#endif +static void finalize_rvv_inst (DisasContext *ctx) +{ +mark_vs_dirty (ctx); + ctx->vstart_eq_zero = true; +} +static void gen_set_rm (DisasContext *ctx,int rm) {if (ctx->frm == rm) {
Signature · 1 line
2.44.0
PATCH v15 4/10 target/riscv: always clear vstart in whole vec move insns
In reply to Daniel Henrique BarbozaThese insns have 2 paths: we'll either have vstart already cleared if vstart_eq_zero or we'll do a brcond to check if vstart >= maxsz to call the 'vmvr_v' helper. The helper will clear vstart if it executes until the end, or if vstart >= vl.
For starters, the check itself is wrong: we're checking vstart >= maxsz, when in fact we should use vstart in bytes, or 'startb' like 'vmvr_v' is calling, to do the comparison. But even after fixing the comparison we'll still need to clear vstart in the end, which isn't happening too.
We want to make the helpers responsible to manage vstart, including these corner cases, precisely to avoid these situations:
- remove the wrong vstart >= maxsz cond from the translation;
- add a 'startb >= maxsz' cond in 'vmvr_v', and clear vstart if that happens.
This way we're now sure that vstart is being cleared in the end of the execution, regardless of the path taken.
--- target/riscv/insn_trans/trans_rvv.c.inc | 3 --- target/riscv/vector_helper.c | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +0 -3
@@ -3664,12 +3664,9 @@ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ vreg_ofs(s, a->rs2), maxsz, maxsz); \ mark_vs_dirty(s); \ } else { \ - TCGLabel *over = gen_new_label(); \ - tcg_gen_brcondi_tl(TCG_COND_GEU, cpu_vstart, maxsz, over); \ tcg_gen_gvec_2_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs2), \ tcg_env, maxsz, maxsz, 0, gen_helper_vmvr_v); \ mark_vs_dirty(s); \ - gen_set_label(over); \ } \ return true; \ } \
target/riscv/vector_helper.c +5 -0
@@ -5075,6 +5075,11 @@ void HELPER(vmvr_v)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc)uint32_t startb = env->vstart * sewb;uint32_t i = startb; +if (startb >= maxsz) { + env->vstart =0 ; +return ; + } +if (HOST_BIG_ENDIAN && i %8 !=0 ) {uint32_t j =ROUND_UP (i,8 ); memcpy((uint8_t *)vd + H1(j - 1),
Signature · 1 line
2.44.0
PATCH v15 7/10 target/riscv: remove 'over' brconds from vector trans
In reply to Daniel Henrique BarbozaAll helpers that rely on vstart >= vl are now doing early exits using the VSTART_CHECK_EARLY_EXIT() macro. This macro will not only exit the helper but also clear vstart.
We're still left with brconds that are skipping the helper, which is the only place where we're clearing vstart. The pattern goes like this:
tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over);
(... calls helper that clears vstart ...)
gen_set_label(over);
return true;This means that every time we jump to 'over' we're not clearing vstart, which is an oversight that we're doing across the board.
Instead of setting vstart = 0 manually after each 'over' jump, remove those brconds that are skipping helpers. The exception will be trans_vmv_s_x() and trans_vfmv_s_f(): they don't use a helper and are already clearing vstart manually in the 'over' label.
While we're at it, remove the (vl == 0) brconds from trans_rvbf16.c.inc too since they're unneeded.
--- target/riscv/insn_trans/trans_rvbf16.c.inc | 12 --- target/riscv/insn_trans/trans_rvv.c.inc | 99 ---------------------- target/riscv/insn_trans/trans_rvvk.c.inc | 18 ---- 3 files changed, 129 deletions(-)
target/riscv/insn_trans/trans_rvbf16.c.inc +0 -12
@@ -71,11 +71,8 @@ static bool trans_vfncvtbf16_f_f_w(DisasContext *ctx, arg_vfncvtbf16_f_f_w *a) if (opfv_narrow_check(ctx, a) && (ctx->sew == MO_16)) { uint32_t data = 0; - TCGLabel *over = gen_new_label(); gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN); - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
@@ -87,7 +84,6 @@ static bool trans_vfncvtbf16_f_f_w(DisasContext *ctx, arg_vfncvtbf16_f_f_w *a) ctx->cfg_ptr->vlenb, data, gen_helper_vfncvtbf16_f_f_w); mark_vs_dirty(ctx); - gen_set_label(over); return true; } return false;
@@ -100,11 +96,8 @@ static bool trans_vfwcvtbf16_f_f_v(DisasContext *ctx, arg_vfwcvtbf16_f_f_v *a) if (opfv_widen_check(ctx, a) && (ctx->sew == MO_16)) { uint32_t data = 0; - TCGLabel *over = gen_new_label(); gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN); - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
@@ -116,7 +109,6 @@ static bool trans_vfwcvtbf16_f_f_v(DisasContext *ctx, arg_vfwcvtbf16_f_f_v *a) ctx->cfg_ptr->vlenb, data, gen_helper_vfwcvtbf16_f_f_v); mark_vs_dirty(ctx); - gen_set_label(over); return true; } return false;
@@ -130,11 +122,8 @@ static bool trans_vfwmaccbf16_vv(DisasContext *ctx, arg_vfwmaccbf16_vv *a) if (require_rvv(ctx) && vext_check_isa_ill(ctx) && (ctx->sew == MO_16) && vext_check_dss(ctx, a->rd, a->rs1, a->rs2, a->vm)) { uint32_t data = 0; - TCGLabel *over = gen_new_label(); gen_set_rm_chkfrm(ctx, RISCV_FRM_DYN); - tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, ctx->lmul);
@@ -147,7 +136,6 @@ static bool trans_vfwmaccbf16_vv(DisasContext *ctx, arg_vfwmaccbf16_vv *a) ctx->cfg_ptr->vlenb, data, gen_helper_vfwmaccbf16_vv); mark_vs_dirty(ctx); - gen_set_label(over); return true; } return false;
target/riscv/insn_trans/trans_rvv.c.inc +0 -99
466 lines not on this page · raw message
target/riscv/insn_trans/trans_rvvk.c.inc +0 -18
@@ -164,8 +164,6 @@ GEN_OPIVX_GVEC_TRANS_CHECK(vandn_vx, andcs, zvkb_vx_check) gen_helper_##NAME##_w, \ gen_helper_##NAME##_d, \ }; \ - TCGLabel *over = gen_new_label(); \ - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \
@@ -177,7 +175,6 @@ GEN_OPIVX_GVEC_TRANS_CHECK(vandn_vx, andcs, zvkb_vx_check) s->cfg_ptr->vlenb, s->cfg_ptr->vlenb, \ data, fns[s->sew]); \ mark_vs_dirty(s); \ - gen_set_label(over); \ return true; \ } \ return false; \
@@ -249,14 +246,12 @@ GEN_OPIVI_WIDEN_TRANS(vwsll_vi, IMM_ZX, vwsll_vx, vwsll_vx_check) TCGv_ptr rd_v, rs2_v; \ TCGv_i32 desc, egs; \ uint32_t data = 0; \ - TCGLabel *over = gen_new_label(); \ \ if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { \ /* save opcode for unwinding in case we throw an exception */ \ decode_save_opc(s); \ egs = tcg_constant_i32(EGS); \ gen_helper_egs_check(egs, tcg_env); \ - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ } \ \ data = FIELD_DP32(data, VDATA, VM, a->vm); \
@@ -272,7 +267,6 @@ GEN_OPIVI_WIDEN_TRANS(vwsll_vi, IMM_ZX, vwsll_vx, vwsll_vx_check) tcg_gen_addi_ptr(rs2_v, tcg_env, vreg_ofs(s, a->rs2)); \ gen_helper_##NAME(rd_v, rs2_v, tcg_env, desc); \ mark_vs_dirty(s); \ - gen_set_label(over); \ return true; \ } \ return false; \
@@ -325,14 +319,12 @@ GEN_V_UNMASKED_TRANS(vaesem_vs, vaes_check_vs, ZVKNED_EGS) TCGv_ptr rd_v, rs2_v; \ TCGv_i32 uimm_v, desc, egs; \ uint32_t data = 0; \ - TCGLabel *over = gen_new_label(); \ \ if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { \ /* save opcode for unwinding in case we throw an exception */ \ decode_save_opc(s); \ egs = tcg_constant_i32(EGS); \ gen_helper_egs_check(egs, tcg_env); \ - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ } \ \ data = FIELD_DP32(data, VDATA, VM, a->vm); \
@@ -350,7 +342,6 @@ GEN_V_UNMASKED_TRANS(vaesem_vs, vaes_check_vs, ZVKNED_EGS) tcg_gen_addi_ptr(rs2_v, tcg_env, vreg_ofs(s, a->rs2)); \ gen_helper_##NAME(rd_v, rs2_v, uimm_v, tcg_env, desc); \ mark_vs_dirty(s); \ - gen_set_label(over); \ return true; \ } \ return false; \
@@ -394,7 +385,6 @@ GEN_VI_UNMASKED_TRANS(vaeskf2_vi, vaeskf2_check, ZVKNED_EGS) { \ if (CHECK(s, a)) { \ uint32_t data = 0; \ - TCGLabel *over = gen_new_label(); \ TCGv_i32 egs; \ \ if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { \
@@ -402,7 +392,6 @@ GEN_VI_UNMASKED_TRANS(vaeskf2_vi, vaeskf2_check, ZVKNED_EGS) decode_save_opc(s); \ egs = tcg_constant_i32(EGS); \ gen_helper_egs_check(egs, tcg_env); \ - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); \ } \ \ data = FIELD_DP32(data, VDATA, VM, a->vm); \
@@ -417,7 +406,6 @@ GEN_VI_UNMASKED_TRANS(vaeskf2_vi, vaeskf2_check, ZVKNED_EGS) data, gen_helper_##NAME); \ \ mark_vs_dirty(s); \ - gen_set_label(over); \ return true; \ } \ return false; \
@@ -448,7 +436,6 @@ static bool trans_vsha2cl_vv(DisasContext *s, arg_rmrr *a) { if (vsha_check(s, a)) { uint32_t data = 0; - TCGLabel *over = gen_new_label(); TCGv_i32 egs; if (!s->vstart_eq_zero || !s->vl_eq_vlmax) {
@@ -456,7 +443,6 @@ static bool trans_vsha2cl_vv(DisasContext *s, arg_rmrr *a) decode_save_opc(s); egs = tcg_constant_i32(ZVKNH_EGS); gen_helper_egs_check(egs, tcg_env); - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); } data = FIELD_DP32(data, VDATA, VM, a->vm);
@@ -472,7 +458,6 @@ static bool trans_vsha2cl_vv(DisasContext *s, arg_rmrr *a) gen_helper_vsha2cl32_vv : gen_helper_vsha2cl64_vv); mark_vs_dirty(s); - gen_set_label(over); return true; } return false;
@@ -482,7 +467,6 @@ static bool trans_vsha2ch_vv(DisasContext *s, arg_rmrr *a) { if (vsha_check(s, a)) { uint32_t data = 0; - TCGLabel *over = gen_new_label(); TCGv_i32 egs; if (!s->vstart_eq_zero || !s->vl_eq_vlmax) {
@@ -490,7 +474,6 @@ static bool trans_vsha2ch_vv(DisasContext *s, arg_rmrr *a) decode_save_opc(s); egs = tcg_constant_i32(ZVKNH_EGS); gen_helper_egs_check(egs, tcg_env); - tcg_gen_brcond_tl(TCG_COND_GEU, cpu_vstart, cpu_vl, over); } data = FIELD_DP32(data, VDATA, VM, a->vm);
@@ -506,7 +489,6 @@ static bool trans_vsha2ch_vv(DisasContext *s, arg_rmrr *a) gen_helper_vsha2ch32_vv : gen_helper_vsha2ch64_vv); mark_vs_dirty(s); - gen_set_label(over); return true; } return false;
Signature · 1 line
2.44.0
PATCH v15 5/10 target/riscv: always clear vstart for ldst_whole insns
In reply to Daniel Henrique BarbozaCommit 8ff8ac6329 added a conditional to guard the vext_ldst_whole() helper if vstart >= evl. But by skipping the helper we're also not setting vstart = 0 at the end of the insns, which is incorrect.
We'll move the conditional to vext_ldst_whole(), following in line with the removal of all brconds vstart >= vl that the next patch will do. The idea is to make the helpers responsible for their own vstart management.
Fix ldst_whole isns by:
- remove the brcond that skips the helper if vstart is >= evl;
- vext_ldst_whole() now does an early exit with the same check, where evl = (vlenb * nf) >> log2_esz, but the early exit will also clear vstart.
The 'width' param is now unneeded in ldst_whole_trans() and is also removed. It was used for the evl calculation for the brcond and has no other use now. The 'width' is reflected in vext_ldst_whole() via log2_esz, which is encoded by GEN_VEXT_LD_WHOLE() as "ctzl(sizeof(ETYPE))".
--- target/riscv/insn_trans/trans_rvv.c.inc | 52 +++++++++++-------------- target/riscv/vector_helper.c | 5 +++ 2 files changed, 28 insertions(+), 29 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +23 -29
@@ -1097,13 +1097,9 @@ GEN_VEXT_TRANS(vle64ff_v, MO_64, r2nfvm, ldff_op, ld_us_check) typedef void gen_helper_ldst_whole(TCGv_ptr, TCGv, TCGv_env, TCGv_i32); static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, - uint32_t width, gen_helper_ldst_whole *fn, + gen_helper_ldst_whole *fn, DisasContext *s) { - uint32_t evl = s->cfg_ptr->vlenb * nf / width; - TCGLabel *over = gen_new_label(); - tcg_gen_brcondi_tl(TCG_COND_GEU, cpu_vstart, evl, over); - TCGv_ptr dest; TCGv base; TCGv_i32 desc;
@@ -1120,8 +1116,6 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, fn(dest, base, tcg_env, desc); - gen_set_label(over); - return true; }
@@ -1129,42 +1123,42 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, * load and store whole register instructions ignore vtype and vl setting. * Thus, we don't need to check vill bit. (Section 7.9) */ -#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF, WIDTH) \ +#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF) \ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ { \ if (require_rvv(s) && \ QEMU_IS_ALIGNED(a->rd, ARG_NF)) { \ - return ldst_whole_trans(a->rd, a->rs1, ARG_NF, WIDTH, \ + return ldst_whole_trans(a->rd, a->rs1, ARG_NF, \ gen_helper_##NAME, s); \ } \ return false; \ } -GEN_LDST_WHOLE_TRANS(vl1re8_v, 1, 1) -GEN_LDST_WHOLE_TRANS(vl1re16_v, 1, 2) -GEN_LDST_WHOLE_TRANS(vl1re32_v, 1, 4) -GEN_LDST_WHOLE_TRANS(vl1re64_v, 1, 8) -GEN_LDST_WHOLE_TRANS(vl2re8_v, 2, 1) -GEN_LDST_WHOLE_TRANS(vl2re16_v, 2, 2) -GEN_LDST_WHOLE_TRANS(vl2re32_v, 2, 4) -GEN_LDST_WHOLE_TRANS(vl2re64_v, 2, 8) -GEN_LDST_WHOLE_TRANS(vl4re8_v, 4, 1) -GEN_LDST_WHOLE_TRANS(vl4re16_v, 4, 2) -GEN_LDST_WHOLE_TRANS(vl4re32_v, 4, 4) -GEN_LDST_WHOLE_TRANS(vl4re64_v, 4, 8) -GEN_LDST_WHOLE_TRANS(vl8re8_v, 8, 1) -GEN_LDST_WHOLE_TRANS(vl8re16_v, 8, 2) -GEN_LDST_WHOLE_TRANS(vl8re32_v, 8, 4) -GEN_LDST_WHOLE_TRANS(vl8re64_v, 8, 8) +GEN_LDST_WHOLE_TRANS(vl1re8_v, 1) +GEN_LDST_WHOLE_TRANS(vl1re16_v, 1) +GEN_LDST_WHOLE_TRANS(vl1re32_v, 1) +GEN_LDST_WHOLE_TRANS(vl1re64_v, 1) +GEN_LDST_WHOLE_TRANS(vl2re8_v, 2) +GEN_LDST_WHOLE_TRANS(vl2re16_v, 2) +GEN_LDST_WHOLE_TRANS(vl2re32_v, 2) +GEN_LDST_WHOLE_TRANS(vl2re64_v, 2) +GEN_LDST_WHOLE_TRANS(vl4re8_v, 4) +GEN_LDST_WHOLE_TRANS(vl4re16_v, 4) +GEN_LDST_WHOLE_TRANS(vl4re32_v, 4) +GEN_LDST_WHOLE_TRANS(vl4re64_v, 4) +GEN_LDST_WHOLE_TRANS(vl8re8_v, 8) +GEN_LDST_WHOLE_TRANS(vl8re16_v, 8) +GEN_LDST_WHOLE_TRANS(vl8re32_v, 8) +GEN_LDST_WHOLE_TRANS(vl8re64_v, 8) /* * The vector whole register store instructions are encoded similar to * unmasked unit-stride store of elements with EEW=8. */ -GEN_LDST_WHOLE_TRANS(vs1r_v, 1, 1) -GEN_LDST_WHOLE_TRANS(vs2r_v, 2, 1) -GEN_LDST_WHOLE_TRANS(vs4r_v, 4, 1) -GEN_LDST_WHOLE_TRANS(vs8r_v, 8, 1) +GEN_LDST_WHOLE_TRANS(vs1r_v, 1) +GEN_LDST_WHOLE_TRANS(vs2r_v, 2) +GEN_LDST_WHOLE_TRANS(vs4r_v, 4) +GEN_LDST_WHOLE_TRANS(vs8r_v, 8) /* *** Vector Integer Arithmetic Instructions
target/riscv/vector_helper.c +5 -0
@@ -572,6 +572,11 @@ vext_ldst_whole(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,uint32_t vlenb =riscv_cpu_cfg (env)->vlenb;uint32_t max_elems = vlenb >> log2_esz; +if (env->vstart >= ((vlenb * nf) >> log2_esz)) { + env->vstart =0 ; +return ; + } + k = env->vstart / max_elems; off = env->vstart % max_elems;
Signature · 1 line
2.44.0
PATCH v15 6/10 target/riscv/vector_helpers: do early exit when vstart >= vl
In reply to Daniel Henrique BarbozaWe're going to make changes that will required each helper to be responsible for the 'vstart' management, i.e. we will relieve the 'vstart < vl' assumption that helpers have today.
Helpers are usually able to deal with vstart >= vl, i.e. doing nothing aside from setting vstart = 0 at the end, but the tail update functions will update the tail regardless of vstart being valid or not. Unifying the tail update process in a single function that would handle the vstart >= vl case isn't trivial (see [1] for more info).
This patch takes a blunt approach: do an early exit in every single vector helper if vstart >= vl, unless the helper is guarded with vstart_eq_zero in the translation. For those cases the helper is ready to deal with cases where vl might be zero, i.e. throwing exceptions based on it like vcpop_m() and first_m().
Helpers that weren't changed:
- vcpop_m(), vfirst_m(), vmsetm(), GEN_VEXT_VIOTA_M(): these are guarded directly with vstart_eq_zero;
- GEN_VEXT_VCOMPRESS_VM(): guarded with vcompress_vm_check() that checks vstart_eq_zero;
- GEN_VEXT_RED(): guarded with either reduction_check() or reduction_widen_check(), both check vstart_eq_zero;
- GEN_VEXT_FRED(): guarded with either freduction_check() or freduction_widen_check(), both check vstart_eq_zero.
Another exception is vext_ldst_whole(), who operates on effective vector length regardless of the current settings in vtype and vl.
[1] https://lore.kernel.org/qemu-riscv/[email protected]/
--- target/riscv/vcrypto_helper.c | 32 ++++++++++++++++ target/riscv/vector_helper.c | 66 +++++++++++++++++++++++++++++++++ target/riscv/vector_internals.c | 4 ++ target/riscv/vector_internals.h | 9 +++++ 4 files changed, 111 insertions(+)
target/riscv/vcrypto_helper.c +32 -0
@@ -222,6 +222,8 @@ static inline void xor_round_key(AESState *round_state, AESState *round_key)uint32_t total_elems =vext_get_total_elems (env, desc,4 ); \uint32_t vta =vext_vta (desc); \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) { \AESState round_key; \ round_key.d[0 ] = *((uint64_t *)vs2 +H8 (i *2 +0 )); \
@@ -246,6 +248,8 @@ static inline void xor_round_key(AESState *round_state, AESState *round_key)uint32_t total_elems =vext_get_total_elems (env, desc,4 ); \uint32_t vta =vext_vta (desc); \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) { \AESState round_key; \ round_key.d[0 ] = *((uint64_t *)vs2 +H8 (0 )); \
@@ -305,6 +309,8 @@ void HELPER(vaeskf1_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm,uint32_t total_elems =vext_get_total_elems (env, desc,4 );uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); + uimm &=0b1111 ;if (uimm >10 || uimm ==0 ) { uimm ^=0b1000 ;
@@ -351,6 +357,8 @@ void HELPER(vaeskf2_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm,uint32_t total_elems =vext_get_total_elems (env, desc,4 );uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); + uimm &=0b1111 ;if (uimm >14 || uimm <2 ) { uimm ^=0b1000 ;
@@ -457,6 +465,8 @@ void HELPER(vsha2ms_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env,uint32_t total_elems;uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {if (sew ==MO_32 ) { vsha2ms_e32(((uint32_t *)vd) + i * 4, ((uint32_t *)vs1) + i * 4,
@@ -572,6 +582,8 @@ void HELPER(vsha2ch32_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env,uint32_t total_elems;uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {vsha2c_32 (((uint32_t *)vs2) +4 * i, ((uint32_t *)vd) +4 * i, ((uint32_t *)vs1) +4 * i +2 );
@@ -590,6 +602,8 @@ void HELPER(vsha2ch64_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env,uint32_t total_elems;uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {vsha2c_64 (((uint64_t *)vs2) +4 * i, ((uint64_t *)vd) +4 * i, ((uint64_t *)vs1) +4 * i +2 );
@@ -608,6 +622,8 @@ void HELPER(vsha2cl32_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env,uint32_t total_elems;uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {vsha2c_32 (((uint32_t *)vs2) +4 * i, ((uint32_t *)vd) +4 * i, (((uint32_t *)vs1) +4 * i));
@@ -626,6 +642,8 @@ void HELPER(vsha2cl64_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env,uint32_t total_elems;uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {vsha2c_64 (((uint64_t *)vs2) +4 * i, ((uint64_t *)vd) +4 * i, (((uint64_t *)vs1) +4 * i));
@@ -658,6 +676,8 @@ void HELPER(vsm3me_vv)(void *vd_vptr, void *vs1_vptr, void *vs2_vptr,uint32_t *vs1 = vs1_vptr;uint32_t *vs2 = vs2_vptr; +VSTART_CHECK_EARLY_EXIT (env); +for (int i = env->vstart /8 ; i < env->vl /8 ; i++) {uint32_t w[24 ];for (int j =0 ; j <8 ; j++) {
@@ -757,6 +777,8 @@ void HELPER(vsm3c_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm,uint32_t *vs2 = vs2_vptr;uint32_t v1[8 ], v2[8 ], v3[8 ]; +VSTART_CHECK_EARLY_EXIT (env); +for (int i = env->vstart /8 ; i < env->vl /8 ; i++) {for (int k =0 ; k <8 ; k++) { v2[k] =bswap32 (vd[H4 (i *8 + k)]);
@@ -780,6 +802,8 @@ void HELPER(vghsh_vv)(void *vd_vptr, void *vs1_vptr, void *vs2_vptr,uint32_t vta =vext_vta (desc);uint32_t total_elems =vext_get_total_elems (env, desc,4 ); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {uint64_t Y [2 ] = {vd[i *2 +0 ], vd[i *2 +1 ]};uint64_t H [2 ] = {brev8 (vs2[i *2 +0 ]),brev8 (vs2[i *2 +1 ])};
@@ -817,6 +841,8 @@ void HELPER(vgmul_vv)(void *vd_vptr, void *vs2_vptr, CPURISCVState *env,uint32_t vta =vext_vta (desc);uint32_t total_elems =vext_get_total_elems (env, desc,4 ); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {uint64_t Y [2 ] = {brev8 (vd[i *2 +0 ]),brev8 (vd[i *2 +1 ])};uint64_t H [2 ] = {brev8 (vs2[i *2 +0 ]),brev8 (vs2[i *2 +1 ])};
@@ -853,6 +879,8 @@ void HELPER(vsm4k_vi)(void *vd, void *vs2, uint32_t uimm5, CPURISCVState *env,uint32_t esz =sizeof (uint32_t );uint32_t total_elems =vext_get_total_elems (env, desc, esz); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = group_start; i < group_end; ++i) {uint32_t vstart = i * egs;uint32_t vend = (i +1 ) * egs;
@@ -909,6 +937,8 @@ void HELPER(vsm4r_vv)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc)uint32_t esz =sizeof (uint32_t );uint32_t total_elems =vext_get_total_elems (env, desc, esz); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = group_start; i < group_end; ++i) {uint32_t vstart = i * egs;uint32_t vend = (i +1 ) * egs;
@@ -943,6 +973,8 @@ void HELPER(vsm4r_vs)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc)uint32_t esz =sizeof (uint32_t );uint32_t total_elems =vext_get_total_elems (env, desc, esz); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = group_start; i < group_end; ++i) {uint32_t vstart = i * egs;uint32_t vend = (i +1 ) * egs;
target/riscv/vector_helper.c +66 -0
264 lines not on this page · raw message
target/riscv/vector_internals.c +4 -0
@@ -44,6 +44,8 @@ void do_vext_vv(void *vd, void *v0, void *vs1, void *vs2,uint32_t vma =vext_vma (desc);uint32_t i; +VSTART_CHECK_EARLY_EXIT (env); +for (i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) {/* set masked-off elements to 1s */
@@ -68,6 +70,8 @@ void do_vext_vx(void *vd, void *v0, target_long s1, void *vs2,uint32_t vma =vext_vma (desc);uint32_t i; +VSTART_CHECK_EARLY_EXIT (env); +for (i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) {/* set masked-off elements to 1s */
target/riscv/vector_internals.h +9 -0
@@ -24,6 +24,13 @@#include "tcg/tcg-gvec-desc.h" #include "internals.h" +#define VSTART_CHECK_EARLY_EXIT (env) do { \ + if (env->vstart >= env->vl) { \ + env->vstart = 0; \ + return; \ + } \ +} while (0) +static inline uint32_t vext_nf (uint32_t desc) {return FIELD_EX32 (simd_data (desc),VDATA ,NF );
@@ -151,6 +158,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs2, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \
Signature · 1 line
2.44.0
Re: [PATCH for 9.0 v15 03/10] target/riscv/vector_helper.c: fix 'vmvr_v' memcpy endianess
In reply to Daniel Henrique BarbozaQuoted 9 lines · Daniel Henrique Barboza
vmvr_visn't handling the case where the host might be big endian and the bytes to be copied aren't sequential.Suggested-by Richard Henderson<[email protected]>Fixes f714361ed7 ("target/riscv: rvv-1.0: implement vstart CSR")Signed-off-by Daniel Henrique Barboza<[email protected]>--- target/riscv/vector_helper.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
r~
Re: [PATCH for 9.0 v15 04/10] target/riscv: always clear vstart in whole vec move insns
In reply to Daniel Henrique BarbozaQuoted 20 lines · Daniel Henrique Barboza
These insns have 2 paths: we'll either have vstart already cleared if
vstart_eq_zeroor we'll do a brcond to check if vstart >= maxsz to call the 'vmvr_v' helper. The helper will clear vstart if it executes until the end, or if vstart >= vl.For starters, the check itself is wrong: we're checking vstart >= maxsz, when in fact we should use vstart in bytes, or 'startb' like '
vmvr_v' is calling, to do the comparison. But even after fixing the comparison we'll still need to clear vstart in the end, which isn't happening too.We want to make the helpers responsible to manage vstart, including these corner cases, precisely to avoid these situations:
- remove the wrong vstart >= maxsz cond from the translation;
- add a 'startb >= maxsz' cond in 'vmvr_v', and clear vstart if that happens.This way we're now sure that vstart is being cleared in the end of the execution, regardless of the path taken.
Quoted 6 lines
Fixes f714361ed7 ("target/riscv: rvv-1.0: implement vstart CSR")Signed-off-by Daniel Henrique Barboza<[email protected]>--- target/riscv/insn_trans/trans_rvv.c.inc | 3 --- target/riscv/vector_helper.c | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-)
r~
Re: [PATCH for 9.0 v15 05/10] target/riscv: always clear vstart for ldst_whole insns
In reply to Daniel Henrique BarbozaQuoted 139 lines · Daniel Henrique Barboza
Commit
8ff8ac6329added a conditional to guard thevext_ldst_whole()helper if vstart >= evl. But by skipping the helper we're also not setting vstart = 0 at the end of the insns, which is incorrect.We'll move the conditional to
vext_ldst_whole(), following in line with the removal of all brconds vstart >= vl that the next patch will do. The idea is to make the helpers responsible for their own vstart management.Fix
ldst_wholeisns by:- remove the brcond that skips the helper if vstart is >= evl;
-
vext_ldst_whole()now does an early exit with the same check, where evl = (vlenb * nf) >>log2_esz, but the early exit will also clear vstart.The 'width' param is now unneeded in
ldst_whole_trans()and is also removed. It was used for the evl calculation for the brcond and has no other use now. The 'width' is reflected invext_ldst_whole()vialog2_esz, which is encoded byGEN_VEXT_LD_WHOLE()as "ctzl(sizeof(ETYPE))".Suggested-by Max Chou <[email protected]>Fixes 8ff8ac6329 ("target/riscv: rvv: Add missing early exit condition for whole register load/store")Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/riscv/insn_trans/trans_rvv.c.inc | 52 +++++++++++-------------- target/riscv/vector_helper.c | 5 +++ 2 files changed, 28 insertions(+), 29 deletions(-)target/riscv/insn_trans/trans_rvv.c.inc +23
-29@@ -1097,13 +1097,9 @@ GEN_VEXT_TRANS(vle64ff_v, MO_64, r2nfvm, ldff_op, ld_us_check) typedef void gen_helper_ldst_whole(TCGv_ptr, TCGv, TCGv_env, TCGv_i32); static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, - uint32_t width, gen_helper_ldst_whole *fn, + gen_helper_ldst_whole *fn, DisasContext *s) { - uint32_t evl = s->cfg_ptr->vlenb * nf / width; - TCGLabel *over = gen_new_label(); - tcg_gen_brcondi_tl(TCG_COND_GEU, cpu_vstart, evl, over); - TCGv_ptr dest; TCGv base; TCGv_i32 desc;@@ -1120,8 +1116,6 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, fn(dest, base, tcg_env, desc); - gen_set_label(over); - return true; }@@ -1129,42 +1123,42 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, * load and store whole register instructions ignore vtype and vl setting. * Thus, we don't need to check vill bit. (Section 7.9) */ -#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF, WIDTH) \ +#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF) \ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ { \ if (require_rvv(s) && \ QEMU_IS_ALIGNED(a->rd, ARG_NF)) { \ - return ldst_whole_trans(a->rd, a->rs1, ARG_NF, WIDTH, \ + return ldst_whole_trans(a->rd, a->rs1, ARG_NF, \ gen_helper_##NAME, s); \ } \ return false; \ } -GEN_LDST_WHOLE_TRANS(vl1re8_v, 1, 1) -GEN_LDST_WHOLE_TRANS(vl1re16_v, 1, 2) -GEN_LDST_WHOLE_TRANS(vl1re32_v, 1, 4) -GEN_LDST_WHOLE_TRANS(vl1re64_v, 1, 8) -GEN_LDST_WHOLE_TRANS(vl2re8_v, 2, 1) -GEN_LDST_WHOLE_TRANS(vl2re16_v, 2, 2) -GEN_LDST_WHOLE_TRANS(vl2re32_v, 2, 4) -GEN_LDST_WHOLE_TRANS(vl2re64_v, 2, 8) -GEN_LDST_WHOLE_TRANS(vl4re8_v, 4, 1) -GEN_LDST_WHOLE_TRANS(vl4re16_v, 4, 2) -GEN_LDST_WHOLE_TRANS(vl4re32_v, 4, 4) -GEN_LDST_WHOLE_TRANS(vl4re64_v, 4, 8) -GEN_LDST_WHOLE_TRANS(vl8re8_v, 8, 1) -GEN_LDST_WHOLE_TRANS(vl8re16_v, 8, 2) -GEN_LDST_WHOLE_TRANS(vl8re32_v, 8, 4) -GEN_LDST_WHOLE_TRANS(vl8re64_v, 8, 8) +GEN_LDST_WHOLE_TRANS(vl1re8_v, 1) +GEN_LDST_WHOLE_TRANS(vl1re16_v, 1) +GEN_LDST_WHOLE_TRANS(vl1re32_v, 1) +GEN_LDST_WHOLE_TRANS(vl1re64_v, 1) +GEN_LDST_WHOLE_TRANS(vl2re8_v, 2) +GEN_LDST_WHOLE_TRANS(vl2re16_v, 2) +GEN_LDST_WHOLE_TRANS(vl2re32_v, 2) +GEN_LDST_WHOLE_TRANS(vl2re64_v, 2) +GEN_LDST_WHOLE_TRANS(vl4re8_v, 4) +GEN_LDST_WHOLE_TRANS(vl4re16_v, 4) +GEN_LDST_WHOLE_TRANS(vl4re32_v, 4) +GEN_LDST_WHOLE_TRANS(vl4re64_v, 4) +GEN_LDST_WHOLE_TRANS(vl8re8_v, 8) +GEN_LDST_WHOLE_TRANS(vl8re16_v, 8) +GEN_LDST_WHOLE_TRANS(vl8re32_v, 8) +GEN_LDST_WHOLE_TRANS(vl8re64_v, 8) /* * The vector whole register store instructions are encoded similar to * unmasked unit-stride store of elements with EEW=8. */ -GEN_LDST_WHOLE_TRANS(vs1r_v, 1, 1) -GEN_LDST_WHOLE_TRANS(vs2r_v, 2, 1) -GEN_LDST_WHOLE_TRANS(vs4r_v, 4, 1) -GEN_LDST_WHOLE_TRANS(vs8r_v, 8, 1) +GEN_LDST_WHOLE_TRANS(vs1r_v, 1) +GEN_LDST_WHOLE_TRANS(vs2r_v, 2) +GEN_LDST_WHOLE_TRANS(vs4r_v, 4) +GEN_LDST_WHOLE_TRANS(vs8r_v, 8) /* *** Vector Integer Arithmetic Instructionstarget/riscv/vector_helper.c +5
-0@@ -572,6 +572,11 @@ vext_ldst_whole(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,uint32_t vlenb =riscv_cpu_cfg (env)->vlenb;uint32_t max_elems = vlenb >> log2_esz; +if (env->vstart >= ((vlenb * nf) >> log2_esz)) { + env->vstart =0 ; +return ; + } + k = env->vstart / max_elems; off = env->vstart % max_elems;
Re: [PATCH for 9.0 v15 02/10] trans_rvv.c.inc: set vstart = 0 in int scalar move insns
In reply to Daniel Henrique BarbozaQuoted 11 lines · Daniel Henrique Barboza
trans_vmv_x_s,trans_vmv_s_x,trans_vfmv_f_sandtrans_vfmv_s_faren't setting vstart = 0 after execution. This is usually done by a helper invector_helper.cbut these functions don't use helpers.We'll set vstart after any potential 'over' brconds, and that will also mandate a
mark_vs_dirty()too.Fixes dedc53cbc9 ("target/riscv: rvv-1.0: integer scalar move instructions")Signed-off-by Daniel Henrique Barboza <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Alistair
Quoted 52 lines
--- target/riscv/insn_trans/trans_rvv.c.inc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)target/riscv/insn_trans/trans_rvv.c.inc +8
-3@@ -3373,6 +3373,8 @@ static bool trans_vmv_x_s(DisasContext *s, arg_vmv_x_s *a) vec_element_loadi(s, t1, a->rs2, 0, true); tcg_gen_trunc_i64_tl(dest, t1); gen_set_gpr(s, a->rd, dest); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;@@ -3399,8 +3401,9 @@ static bool trans_vmv_s_x(DisasContext *s, arg_vmv_s_x *a) s1 = get_gpr(s, a->rs1, EXT_NONE); tcg_gen_ext_tl_i64(t1, s1); vec_element_storei(s, a->rd, 0, t1); - mark_vs_dirty(s); gen_set_label(over); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;@@ -3427,6 +3430,8 @@ static bool trans_vfmv_f_s(DisasContext *s, arg_vfmv_f_s *a) } mark_fs_dirty(s); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;@@ -3452,8 +3457,9 @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_s_f *a) do_nanbox(s, t1, cpu_fpr[a->rs1]); vec_element_storei(s, a->rd, 0, t1); - mark_vs_dirty(s); gen_set_label(over); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false; --2.44.0
Re: [PATCH for 9.0 v15 03/10] target/riscv/vector_helper.c: fix 'vmvr_v' memcpy endianess
In reply to Daniel Henrique BarbozaQuoted 7 lines · Daniel Henrique Barboza
vmvr_visn't handling the case where the host might be big endian and the bytes to be copied aren't sequential.Suggested-by Richard Henderson <[email protected]>Fixes f714361ed7 ("target/riscv: rvv-1.0: implement vstart CSR")Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 31 lines
--- target/riscv/vector_helper.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)target/riscv/vector_helper.c +9
-2@@ -5075,9 +5075,17 @@ void HELPER(vmvr_v)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc)uint32_t startb = env->vstart * sewb;uint32_t i = startb; +if (HOST_BIG_ENDIAN && i %8 !=0 ) { +uint32_t j =ROUND_UP (i,8 ); +memcpy ((uint8_t *)vd +H1 (j -1 ), + (uint8_t *)vs2 +H1 (j -1 ), + j - i); + i = j; + } +memcpy ((uint8_t *)vd +H1 (i), (uint8_t *)vs2 +H1 (i), - maxsz - startb); + maxsz - i); env->vstart =0 ; } --2.44.0
Re: [PATCH for 9.0 v15 04/10] target/riscv: always clear vstart in whole vec move insns
In reply to Daniel Henrique BarbozaQuoted 18 lines · Daniel Henrique Barboza
These insns have 2 paths: we'll either have vstart already cleared if
vstart_eq_zeroor we'll do a brcond to check if vstart >= maxsz to call the 'vmvr_v' helper. The helper will clear vstart if it executes until the end, or if vstart >= vl.For starters, the check itself is wrong: we're checking vstart >= maxsz, when in fact we should use vstart in bytes, or 'startb' like '
vmvr_v' is calling, to do the comparison. But even after fixing the comparison we'll still need to clear vstart in the end, which isn't happening too.We want to make the helpers responsible to manage vstart, including these corner cases, precisely to avoid these situations:
- remove the wrong vstart >= maxsz cond from the translation;
- add a 'startb >= maxsz' cond in 'vmvr_v', and clear vstart if that happens.
Quoted 5 lines
This way we're now sure that vstart is being cleared in the end of the execution, regardless of the path taken.
Fixes f714361ed7 ("target/riscv: rvv-1.0: implement vstart CSR")Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 42 lines
--- target/riscv/insn_trans/trans_rvv.c.inc | 3 --- target/riscv/vector_helper.c | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-)target/riscv/insn_trans/trans_rvv.c.inc +0
-3@@ -3664,12 +3664,9 @@ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ vreg_ofs(s, a->rs2), maxsz, maxsz); \ mark_vs_dirty(s); \ } else { \ - TCGLabel *over = gen_new_label(); \ - tcg_gen_brcondi_tl(TCG_COND_GEU, cpu_vstart, maxsz, over); \ tcg_gen_gvec_2_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs2), \ tcg_env, maxsz, maxsz, 0, gen_helper_vmvr_v); \ mark_vs_dirty(s); \ - gen_set_label(over); \ } \ return true; \ } \target/riscv/vector_helper.c +5
-1@@ -5075,6 +5075,11 @@ void HELPER(vmvr_v)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc)uint32_t startb = env->vstart * sewb;uint32_t i = startb; +if (startb >= maxsz) { + env->vstart =0 ; +return ; + } +if (HOST_BIG_ENDIAN && i %8 !=0 ) {uint32_t j =ROUND_UP (i,8 ); memcpy((uint8_t *)vd + H1(j - 1), --2.44.0
Re: [PATCH for 9.0 v15 05/10] target/riscv: always clear vstart for ldst_whole insns
In reply to Daniel Henrique BarbozaQuoted 23 lines · Daniel Henrique Barboza
Commit
8ff8ac6329added a conditional to guard thevext_ldst_whole()helper if vstart >= evl. But by skipping the helper we're also not setting vstart = 0 at the end of the insns, which is incorrect.We'll move the conditional to
vext_ldst_whole(), following in line with the removal of all brconds vstart >= vl that the next patch will do. The idea is to make the helpers responsible for their own vstart management.Fix
ldst_wholeisns by:- remove the brcond that skips the helper if vstart is >= evl;
-
vext_ldst_whole()now does an early exit with the same check, where evl = (vlenb * nf) >>log2_esz, but the early exit will also clear vstart.The 'width' param is now unneeded in
ldst_whole_trans()and is also removed. It was used for the evl calculation for the brcond and has no other use now. The 'width' is reflected invext_ldst_whole()vialog2_esz, which is encoded byGEN_VEXT_LD_WHOLE()as "ctzl(sizeof(ETYPE))".
Quoted 3 lines
Suggested-by Max Chou <[email protected]>Fixes 8ff8ac6329 ("target/riscv: rvv: Add missing early exit condition for whole register load/store")Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 118 lines
--- target/riscv/insn_trans/trans_rvv.c.inc | 52 +++++++++++-------------- target/riscv/vector_helper.c | 5 +++ 2 files changed, 28 insertions(+), 29 deletions(-)target/riscv/insn_trans/trans_rvv.c.inc +23
-29@@ -1097,13 +1097,9 @@ GEN_VEXT_TRANS(vle64ff_v, MO_64, r2nfvm, ldff_op, ld_us_check) typedef void gen_helper_ldst_whole(TCGv_ptr, TCGv, TCGv_env, TCGv_i32); static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, - uint32_t width, gen_helper_ldst_whole *fn, + gen_helper_ldst_whole *fn, DisasContext *s) { - uint32_t evl = s->cfg_ptr->vlenb * nf / width; - TCGLabel *over = gen_new_label(); - tcg_gen_brcondi_tl(TCG_COND_GEU, cpu_vstart, evl, over); - TCGv_ptr dest; TCGv base; TCGv_i32 desc;@@ -1120,8 +1116,6 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, fn(dest, base, tcg_env, desc); - gen_set_label(over); - return true; }@@ -1129,42 +1123,42 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, * load and store whole register instructions ignore vtype and vl setting. * Thus, we don't need to check vill bit. (Section 7.9) */ -#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF, WIDTH) \ +#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF) \ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ { \ if (require_rvv(s) && \ QEMU_IS_ALIGNED(a->rd, ARG_NF)) { \ - return ldst_whole_trans(a->rd, a->rs1, ARG_NF, WIDTH, \ + return ldst_whole_trans(a->rd, a->rs1, ARG_NF, \ gen_helper_##NAME, s); \ } \ return false; \ } -GEN_LDST_WHOLE_TRANS(vl1re8_v, 1, 1) -GEN_LDST_WHOLE_TRANS(vl1re16_v, 1, 2) -GEN_LDST_WHOLE_TRANS(vl1re32_v, 1, 4) -GEN_LDST_WHOLE_TRANS(vl1re64_v, 1, 8) -GEN_LDST_WHOLE_TRANS(vl2re8_v, 2, 1) -GEN_LDST_WHOLE_TRANS(vl2re16_v, 2, 2) -GEN_LDST_WHOLE_TRANS(vl2re32_v, 2, 4) -GEN_LDST_WHOLE_TRANS(vl2re64_v, 2, 8) -GEN_LDST_WHOLE_TRANS(vl4re8_v, 4, 1) -GEN_LDST_WHOLE_TRANS(vl4re16_v, 4, 2) -GEN_LDST_WHOLE_TRANS(vl4re32_v, 4, 4) -GEN_LDST_WHOLE_TRANS(vl4re64_v, 4, 8) -GEN_LDST_WHOLE_TRANS(vl8re8_v, 8, 1) -GEN_LDST_WHOLE_TRANS(vl8re16_v, 8, 2) -GEN_LDST_WHOLE_TRANS(vl8re32_v, 8, 4) -GEN_LDST_WHOLE_TRANS(vl8re64_v, 8, 8) +GEN_LDST_WHOLE_TRANS(vl1re8_v, 1) +GEN_LDST_WHOLE_TRANS(vl1re16_v, 1) +GEN_LDST_WHOLE_TRANS(vl1re32_v, 1) +GEN_LDST_WHOLE_TRANS(vl1re64_v, 1) +GEN_LDST_WHOLE_TRANS(vl2re8_v, 2) +GEN_LDST_WHOLE_TRANS(vl2re16_v, 2) +GEN_LDST_WHOLE_TRANS(vl2re32_v, 2) +GEN_LDST_WHOLE_TRANS(vl2re64_v, 2) +GEN_LDST_WHOLE_TRANS(vl4re8_v, 4) +GEN_LDST_WHOLE_TRANS(vl4re16_v, 4) +GEN_LDST_WHOLE_TRANS(vl4re32_v, 4) +GEN_LDST_WHOLE_TRANS(vl4re64_v, 4) +GEN_LDST_WHOLE_TRANS(vl8re8_v, 8) +GEN_LDST_WHOLE_TRANS(vl8re16_v, 8) +GEN_LDST_WHOLE_TRANS(vl8re32_v, 8) +GEN_LDST_WHOLE_TRANS(vl8re64_v, 8) /* * The vector whole register store instructions are encoded similar to * unmasked unit-stride store of elements with EEW=8. */ -GEN_LDST_WHOLE_TRANS(vs1r_v, 1, 1) -GEN_LDST_WHOLE_TRANS(vs2r_v, 2, 1) -GEN_LDST_WHOLE_TRANS(vs4r_v, 4, 1) -GEN_LDST_WHOLE_TRANS(vs8r_v, 8, 1) +GEN_LDST_WHOLE_TRANS(vs1r_v, 1) +GEN_LDST_WHOLE_TRANS(vs2r_v, 2) +GEN_LDST_WHOLE_TRANS(vs4r_v, 4) +GEN_LDST_WHOLE_TRANS(vs8r_v, 8) /* *** Vector Integer Arithmetic Instructionstarget/riscv/vector_helper.c +5
-1@@ -572,6 +572,11 @@ vext_ldst_whole(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,uint32_t vlenb =riscv_cpu_cfg (env)->vlenb;uint32_t max_elems = vlenb >> log2_esz; +if (env->vstart >= ((vlenb * nf) >> log2_esz)) { + env->vstart =0 ; +return ; + } + k = env->vstart / max_elems; off = env->vstart % max_elems; --2.44.0
Re: [PATCH for 9.0 v15 01/10] target/riscv/vector_helper.c: set vstart = 0 in GEN_VEXT_VSLIDEUP_VX()
In reply to Daniel Henrique BarbozaQuoted 6 lines · Daniel Henrique Barboza
The helper isn't setting
env->vstart= 0 after its execution, as it is expected from every vector instruction that completes successfully.Signed-off-by Daniel Henrique Barboza <[email protected]>Reviewed-by Richard Henderson <[email protected]>Reviewed-by Alistair Francis <[email protected]>
Zhiwei
Quoted 16 lines
--- target/riscv/vector_helper.c | 1 + 1 file changed, 1 insertion(+)target/riscv/vector_helper.c +1
-0@@ -4781,6 +4781,7 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \ } \ *((ETYPE *)vd +H (i)) = *((ETYPE *)vs2 +H (i - offset)); \ } \ + env->vstart =0 ; \/* set tail elements to 1s */ \vext_set_elems_1s (vd, vta, vl * esz, total_elems * esz); \ }
Re: [PATCH for 9.0 v15 02/10] trans_rvv.c.inc: set vstart = 0 in int scalar move insns
In reply to Daniel Henrique BarbozaQuoted 10 lines · Daniel Henrique Barboza
trans_vmv_x_s,trans_vmv_s_x,trans_vfmv_f_sandtrans_vfmv_s_faren't setting vstart = 0 after execution. This is usually done by a helper invector_helper.cbut these functions don't use helpers.We'll set vstart after any potential 'over' brconds, and that will also mandate a
mark_vs_dirty()too.Fixes dedc53cbc9 ("target/riscv: rvv-1.0: integer scalar move instructions")Signed-off-by Daniel Henrique Barboza <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Zhiwei
Quoted 48 lines
--- target/riscv/insn_trans/trans_rvv.c.inc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)target/riscv/insn_trans/trans_rvv.c.inc +8
-2@@ -3373,6 +3373,8 @@ static bool trans_vmv_x_s(DisasContext *s, arg_vmv_x_s *a) vec_element_loadi(s, t1, a->rs2, 0, true); tcg_gen_trunc_i64_tl(dest, t1); gen_set_gpr(s, a->rd, dest); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;@@ -3399,8 +3401,9 @@ static bool trans_vmv_s_x(DisasContext *s, arg_vmv_s_x *a) s1 = get_gpr(s, a->rs1, EXT_NONE); tcg_gen_ext_tl_i64(t1, s1); vec_element_storei(s, a->rd, 0, t1); - mark_vs_dirty(s); gen_set_label(over); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;@@ -3427,6 +3430,8 @@ static bool trans_vfmv_f_s(DisasContext *s, arg_vfmv_f_s *a) } mark_fs_dirty(s); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;@@ -3452,8 +3457,9 @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_s_f *a) do_nanbox(s, t1, cpu_fpr[a->rs1]); vec_element_storei(s, a->rd, 0, t1); - mark_vs_dirty(s); gen_set_label(over); + tcg_gen_movi_tl(cpu_vstart, 0); + mark_vs_dirty(s); return true; } return false;
Re: [PATCH for 9.0 v15 03/10] target/riscv/vector_helper.c: fix 'vmvr_v' memcpy endianess
In reply to Daniel Henrique BarbozaQuoted 20 lines · Daniel Henrique Barboza
vmvr_visn't handling the case where the host might be big endian and the bytes to be copied aren't sequential.Suggested-by Richard Henderson <[email protected]>Fixes f714361ed7 ("target/riscv: rvv-1.0: implement vstart CSR")Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/riscv/vector_helper.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)target/riscv/vector_helper.c +2
-0@@ -5075,9 +5075,17 @@ void HELPER(vmvr_v)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc)uint32_t startb = env->vstart * sewb;uint32_t i = startb; +if (HOST_BIG_ENDIAN && i %8 !=0 ) { +uint32_t j =ROUND_UP (i,8 );
target/riscv/vector_helper.c void HELPER(vmvr_v)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc) · line 5088
Quoted 10 lines
target/riscv/vector_helper.c +7
-1+memcpy ((uint8_t *)vd +H1 (j -1 ), + (uint8_t *)vs2 +H1 (j -1 ), + j - i); + i = j; + } +memcpy ((uint8_t *)vd +H1 (i), (uint8_t *)vs2 +H1 (i), - maxsz - startb); + maxsz - i);
Zhiwei
Quoted 3 lines
target/riscv/vector_helper.c +0
-0env->vstart =0 ; }
Re: [PATCH for 9.0 v15 04/10] target/riscv: always clear vstart in whole vec move insns
In reply to Daniel Henrique BarbozaQuoted 17 lines · Daniel Henrique Barboza
These insns have 2 paths: we'll either have vstart already cleared if
vstart_eq_zeroor we'll do a brcond to check if vstart >= maxsz to call the 'vmvr_v' helper. The helper will clear vstart if it executes until the end, or if vstart >= vl.For starters, the check itself is wrong: we're checking vstart >= maxsz, when in fact we should use vstart in bytes, or 'startb' like '
vmvr_v' is calling, to do the comparison. But even after fixing the comparison we'll still need to clear vstart in the end, which isn't happening too.We want to make the helpers responsible to manage vstart, including these corner cases, precisely to avoid these situations:
- remove the wrong vstart >= maxsz cond from the translation;
- add a 'startb >= maxsz' cond in 'vmvr_v', and clear vstart if that happens.
Quoted 5 lines
This way we're now sure that vstart is being cleared in the end of the execution, regardless of the path taken.
Fixes f714361ed7 ("target/riscv: rvv-1.0: implement vstart CSR")Signed-off-by Daniel Henrique Barboza <[email protected]>
Zhiwei
Quoted 38 lines
--- target/riscv/insn_trans/trans_rvv.c.inc | 3 --- target/riscv/vector_helper.c | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-)target/riscv/insn_trans/trans_rvv.c.inc +0
-3@@ -3664,12 +3664,9 @@ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ vreg_ofs(s, a->rs2), maxsz, maxsz); \ mark_vs_dirty(s); \ } else { \ - TCGLabel *over = gen_new_label(); \ - tcg_gen_brcondi_tl(TCG_COND_GEU, cpu_vstart, maxsz, over); \ tcg_gen_gvec_2_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs2), \ tcg_env, maxsz, maxsz, 0, gen_helper_vmvr_v); \ mark_vs_dirty(s); \ - gen_set_label(over); \ } \ return true; \ } \target/riscv/vector_helper.c +5
-0@@ -5075,6 +5075,11 @@ void HELPER(vmvr_v)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc)uint32_t startb = env->vstart * sewb;uint32_t i = startb; +if (startb >= maxsz) { + env->vstart =0 ; +return ; + } +if (HOST_BIG_ENDIAN && i %8 !=0 ) {uint32_t j =ROUND_UP (i,8 ); memcpy((uint8_t *)vd + H1(j - 1),
Re: [PATCH for 9.0 v15 06/10] target/riscv/vector_helpers: do early exit when vstart >= vl
In reply to Daniel Henrique BarbozaQuoted 31 lines · Daniel Henrique Barboza
We're going to make changes that will required each helper to be responsible for the 'vstart' management, i.e. we will relieve the 'vstart < vl' assumption that helpers have today.
Helpers are usually able to deal with vstart >= vl, i.e. doing nothing aside from setting vstart = 0 at the end, but the tail update functions will update the tail regardless of vstart being valid or not. Unifying the tail update process in a single function that would handle the vstart >= vl case isn't trivial (see [1] for more info).
This patch takes a blunt approach: do an early exit in every single vector helper if vstart >= vl, unless the helper is guarded with
vstart_eq_zeroin the translation. For those cases the helper is ready to deal with cases where vl might be zero, i.e. throwing exceptions based on it likevcpop_m()andfirst_m().Helpers that weren't changed:
-
vcpop_m(),vfirst_m(),vmsetm(),GEN_VEXT_VIOTA_M(): these are guarded directly withvstart_eq_zero;-
GEN_VEXT_VCOMPRESS_VM(): guarded withvcompress_vm_check()that checksvstart_eq_zero;-
GEN_VEXT_RED(): guarded with eitherreduction_check()orreduction_widen_check(), both checkvstart_eq_zero;-
GEN_VEXT_FRED(): guarded with eitherfreduction_check()orfreduction_widen_check(), both checkvstart_eq_zero.
Quoted 8 lines
Another exception is
vext_ldst_whole(), who operates on effective vector length regardless of the current settings in vtype and vl.[1] https://lore.kernel.org/qemu-riscv/[email protected]/
Signed-off-by Daniel Henrique Barboza <[email protected]>Reviewed-by Richard Henderson <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 509 lines
--- target/riscv/vcrypto_helper.c | 32 ++++++++++++++++ target/riscv/vector_helper.c | 66 +++++++++++++++++++++++++++++++++ target/riscv/vector_internals.c | 4 ++ target/riscv/vector_internals.h | 9 +++++ 4 files changed, 111 insertions(+)target/riscv/vcrypto_helper.c +32
-0@@ -222,6 +222,8 @@ static inline void xor_round_key(AESState *round_state, AESState *round_key)uint32_t total_elems =vext_get_total_elems (env, desc,4 ); \uint32_t vta =vext_vta (desc); \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) { \AESState round_key; \ round_key.d[0 ] = *((uint64_t *)vs2 +H8 (i *2 +0 )); \@@ -246,6 +248,8 @@ static inline void xor_round_key(AESState *round_state, AESState *round_key)uint32_t total_elems =vext_get_total_elems (env, desc,4 ); \uint32_t vta =vext_vta (desc); \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) { \AESState round_key; \ round_key.d[0 ] = *((uint64_t *)vs2 +H8 (0 )); \@@ -305,6 +309,8 @@ void HELPER(vaeskf1_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm,uint32_t total_elems =vext_get_total_elems (env, desc,4 );uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); + uimm &=0b1111 ;if (uimm >10 || uimm ==0 ) { uimm ^=0b1000 ;@@ -351,6 +357,8 @@ void HELPER(vaeskf2_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm,uint32_t total_elems =vext_get_total_elems (env, desc,4 );uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); + uimm &=0b1111 ;if (uimm >14 || uimm <2 ) { uimm ^=0b1000 ;@@ -457,6 +465,8 @@ void HELPER(vsha2ms_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env,uint32_t total_elems;uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {if (sew ==MO_32 ) { vsha2ms_e32(((uint32_t *)vd) + i * 4, ((uint32_t *)vs1) + i * 4,@@ -572,6 +582,8 @@ void HELPER(vsha2ch32_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env,uint32_t total_elems;uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {vsha2c_32 (((uint32_t *)vs2) +4 * i, ((uint32_t *)vd) +4 * i, ((uint32_t *)vs1) +4 * i +2 );@@ -590,6 +602,8 @@ void HELPER(vsha2ch64_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env,uint32_t total_elems;uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {vsha2c_64 (((uint64_t *)vs2) +4 * i, ((uint64_t *)vd) +4 * i, ((uint64_t *)vs1) +4 * i +2 );@@ -608,6 +622,8 @@ void HELPER(vsha2cl32_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env,uint32_t total_elems;uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {vsha2c_32 (((uint32_t *)vs2) +4 * i, ((uint32_t *)vd) +4 * i, (((uint32_t *)vs1) +4 * i));@@ -626,6 +642,8 @@ void HELPER(vsha2cl64_vv)(void *vd, void *vs1, void *vs2, CPURISCVState *env,uint32_t total_elems;uint32_t vta =vext_vta (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {vsha2c_64 (((uint64_t *)vs2) +4 * i, ((uint64_t *)vd) +4 * i, (((uint64_t *)vs1) +4 * i));@@ -658,6 +676,8 @@ void HELPER(vsm3me_vv)(void *vd_vptr, void *vs1_vptr, void *vs2_vptr,uint32_t *vs1 = vs1_vptr;uint32_t *vs2 = vs2_vptr; +VSTART_CHECK_EARLY_EXIT (env); +for (int i = env->vstart /8 ; i < env->vl /8 ; i++) {uint32_t w[24 ];for (int j =0 ; j <8 ; j++) {@@ -757,6 +777,8 @@ void HELPER(vsm3c_vi)(void *vd_vptr, void *vs2_vptr, uint32_t uimm,uint32_t *vs2 = vs2_vptr;uint32_t v1[8 ], v2[8 ], v3[8 ]; +VSTART_CHECK_EARLY_EXIT (env); +for (int i = env->vstart /8 ; i < env->vl /8 ; i++) {for (int k =0 ; k <8 ; k++) { v2[k] =bswap32 (vd[H4 (i *8 + k)]);@@ -780,6 +802,8 @@ void HELPER(vghsh_vv)(void *vd_vptr, void *vs1_vptr, void *vs2_vptr,uint32_t vta =vext_vta (desc);uint32_t total_elems =vext_get_total_elems (env, desc,4 ); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {uint64_t Y [2 ] = {vd[i *2 +0 ], vd[i *2 +1 ]};uint64_t H [2 ] = {brev8 (vs2[i *2 +0 ]),brev8 (vs2[i *2 +1 ])};@@ -817,6 +841,8 @@ void HELPER(vgmul_vv)(void *vd_vptr, void *vs2_vptr, CPURISCVState *env,uint32_t vta =vext_vta (desc);uint32_t total_elems =vext_get_total_elems (env, desc,4 ); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = env->vstart /4 ; i < env->vl /4 ; i++) {uint64_t Y [2 ] = {brev8 (vd[i *2 +0 ]),brev8 (vd[i *2 +1 ])};uint64_t H [2 ] = {brev8 (vs2[i *2 +0 ]),brev8 (vs2[i *2 +1 ])};@@ -853,6 +879,8 @@ void HELPER(vsm4k_vi)(void *vd, void *vs2, uint32_t uimm5, CPURISCVState *env,uint32_t esz =sizeof (uint32_t );uint32_t total_elems =vext_get_total_elems (env, desc, esz); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = group_start; i < group_end; ++i) {uint32_t vstart = i * egs;uint32_t vend = (i +1 ) * egs;@@ -909,6 +937,8 @@ void HELPER(vsm4r_vv)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc)uint32_t esz =sizeof (uint32_t );uint32_t total_elems =vext_get_total_elems (env, desc, esz); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = group_start; i < group_end; ++i) {uint32_t vstart = i * egs;uint32_t vend = (i +1 ) * egs;@@ -943,6 +973,8 @@ void HELPER(vsm4r_vs)(void *vd, void *vs2, CPURISCVState *env, uint32_t desc)uint32_t esz =sizeof (uint32_t );uint32_t total_elems =vext_get_total_elems (env, desc, esz); +VSTART_CHECK_EARLY_EXIT (env); +for (uint32_t i = group_start; i < group_end; ++i) {uint32_t vstart = i * egs;uint32_t vend = (i +1 ) * egs;target/riscv/vector_helper.c +66
-0@@ -207,6 +207,8 @@ vext_ldst_stride(void *vd, void *v0, target_ulong base,uint32_t esz =1 << log2_esz;uint32_t vma =vext_vma (desc); +VSTART_CHECK_EARLY_EXIT (env); +for (i = env->vstart; i < env->vl; i++, env->vstart++) { k =0 ;while (k < nf) {@@ -272,6 +274,8 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,uint32_t max_elems =vext_max_elems (desc, log2_esz);uint32_t esz =1 << log2_esz; +VSTART_CHECK_EARLY_EXIT (env); +/* load bytes from guest memory */ for (i = env->vstart; i < evl; i++, env->vstart++) { k =0 ;@@ -386,6 +390,8 @@ vext_ldst_index(void *vd, void *v0, target_ulong base,uint32_t esz =1 << log2_esz;uint32_t vma =vext_vma (desc); +VSTART_CHECK_EARLY_EXIT (env); +/* load bytes from guest memory */ for (i = env->vstart; i < env->vl; i++, env->vstart++) { k =0 ;@@ -477,6 +483,8 @@ vext_ldff(void *vd, void *v0, target_ulong base,target_ulong addr, offset, remain;int mmu_index =riscv_env_mmu_index (env, false); +VSTART_CHECK_EARLY_EXIT (env); +/* probe every access */ for (i = env->vstart; i < env->vl; i++) {if (!vm && !vext_elem_mask (v0, i)) {@@ -882,6 +890,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \uint32_t vta =vext_vta (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s1 = *((ETYPE *)vs1 +H (i)); \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \@@ -914,6 +924,8 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \uint32_t vta =vext_vta (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \ETYPE carry =vext_elem_mask (v0, i); \@@ -949,6 +961,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \uint32_t vta_all_1s =vext_vta_all_1s (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s1 = *((ETYPE *)vs1 +H (i)); \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \@@ -987,6 +1001,8 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, \uint32_t vta_all_1s =vext_vta_all_1s (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \ETYPE carry = !vm &&vext_elem_mask (v0, i); \@@ -1083,6 +1099,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \@@ -1130,6 +1148,8 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \@@ -1192,6 +1212,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s1 = *((ETYPE *)vs1 +H (i)); \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \@@ -1257,6 +1279,8 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \if (!vm && !vext_elem_mask (v0, i)) { \@@ -1804,6 +1828,8 @@ void HELPER(NAME)(void *vd, void *vs1, CPURISCVState *env, \uint32_t vta =vext_vta (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s1 = *((ETYPE *)vs1 +H (i)); \ *((ETYPE *)vd +H (i)) = s1; \@@ -1828,6 +1854,8 @@ void HELPER(NAME)(void *vd, uint64_t s1, CPURISCVState *env, \uint32_t vta =vext_vta (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ *((ETYPE *)vd +H (i)) = (ETYPE )s1; \ } \@@ -1851,6 +1879,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \uint32_t vta =vext_vta (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE *vt = (!vext_elem_mask (v0, i) ? vs2 : vs1); \ *((ETYPE *)vd +H (i)) = *(vt +H (i)); \@@ -1875,6 +1905,8 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, \uint32_t vta =vext_vta (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \ ETYPE d = (!vext_elem_mask(v0, i) ? s2 : \@@ -1920,6 +1952,8 @@ vext_vv_rm_1(void *vd, void *v0, void *vs1, void *vs2, uint32_t vl, uint32_t vm, int vxrm, opivv2_rm_fn *fn, uint32_t vma, uint32_t esz) { +VSTART_CHECK_EARLY_EXIT (env ); +for (uint32_t i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) {/* set masked-off elements to 1s */ @@ -2045,6 +2079,8 @@ vext_vx_rm_1(void *vd, void *v0, target_long s1, void *vs2, uint32_t vl, uint32_t vm, int vxrm, opivx2_rm_fn *fn, uint32_t vma, uint32_t esz) { +VSTART_CHECK_EARLY_EXIT (env ); +for (uint32_t i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) {/* set masked-off elements to 1s */ @@ -2842,6 +2878,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \@@ -2885,6 +2923,8 @@ void HELPER(NAME)(void *vd, void *v0, uint64_t s1, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \@@ -3471,6 +3511,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs2, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \if (vl ==0 ) { \return ; \ } \@@ -3992,6 +4034,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s1 = *((ETYPE *)vs1 +H (i)); \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \@@ -4032,6 +4076,8 @@ void HELPER(NAME)(void *vd, void *v0, uint64_t s1, void *vs2, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \if (!vm && !vext_elem_mask (v0, i)) { \@@ -4225,6 +4271,8 @@ void HELPER(NAME)(void *vd, void *v0, uint64_t s1, void *vs2, \uint32_t vta =vext_vta (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \ *((ETYPE *)vd + H(i)) = \@@ -4549,6 +4597,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, \uint32_t i; \int a, b; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \ a =vext_elem_mask (vs1, i); \ b =vext_elem_mask (vs2, i); \@@ -4742,6 +4792,8 @@ void HELPER(NAME)(void *vd, void *v0, CPURISCVState *env, uint32_t desc) \uint32_t vma =vext_vma (desc); \int i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \@@ -4777,6 +4829,8 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \uint32_t vma =vext_vma (desc); \target_ulong offset = s1, i_min, i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \ i_min =MAX (env->vstart, offset); \for (i = i_min; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \@@ -4810,6 +4864,8 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \uint32_t vma =vext_vma (desc); \target_ulong i_max, i_min, i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \ i_min =MIN (s1 < vlmax ? vlmax - s1 :0 , vl); \ i_max =MAX (i_min, env->vstart); \for (i = env->vstart; i < i_max; ++i) { \@@ -4852,6 +4908,8 @@ static void vslide1up_##BITWIDTH(void *vd, void *v0, uint64_t s1, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \@@ -4901,6 +4959,8 @@ static void vslide1down_##BITWIDTH(void *vd, void *v0, uint64_t s1, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \@@ -4976,6 +5036,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \uint64_t index; \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \@@ -5019,6 +5081,8 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \uint64_t index = s1; \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \@@ -5113,6 +5177,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs2, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \target/riscv/vector_internals.c +4
-0@@ -44,6 +44,8 @@ void do_vext_vv(void *vd, void *v0, void *vs1, void *vs2,uint32_t vma =vext_vma (desc);uint32_t i; +VSTART_CHECK_EARLY_EXIT (env); +for (i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) {/* set masked-off elements to 1s */ @@ -68,6 +70,8 @@ void do_vext_vx(void *vd, void *v0, target_long s1, void *vs2,uint32_t vma =vext_vma (desc);uint32_t i; +VSTART_CHECK_EARLY_EXIT (env); +for (i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) {/* set masked-off elements to 1s */ target/riscv/vector_internals.h +9
-1@@ -24,6 +24,13 @@#include "tcg/tcg-gvec-desc.h" #include "internals.h" +#define VSTART_CHECK_EARLY_EXIT (env) do { \ + if (env->vstart >= env->vl) { \ + env->vstart = 0; \ + return; \ + } \ +} while (0) +static inline uint32_t vext_nf (uint32_t desc) {return FIELD_EX32 (simd_data (desc),VDATA ,NF );@@ -151,6 +158,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs2, \uint32_t vma =vext_vma (desc); \uint32_t i; \ \ +VSTART_CHECK_EARLY_EXIT (env); \ + \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \/* set masked-off elements to 1s */ \ --2.44.0
Alistair Francis
AppliedQuoted 44 lines · Daniel Henrique Barboza
Hi,
The series was renamed to reflect that at this point we're fixing more things than just vstart management.
In this new version a couple fixes were added:
- patch 3 (new) fixes the memcpy endianess in '
vmvr_v', as suggested by Richard;- patch 5 (new) fixes
ldst_wholeinsns to now clear vstart in all cases. The fix was proposed by Max.Another notable change was made in patch 6 (patch 4 from v14). We're not doing early exits in helpers that are gated by
vstart_eq_zero. This was found to cause side-effects with insns that wants to send faults if vl = 0, and for the rest it becomes a moot check since vstart is granted to be zero beforehand.Series based on master.
Patches missing acks: 3, 4, 5
Changes from v14:
- patch 3 (new):
- make 'vmvr_v' big endian compliant
- patch 5 (new):
- makeldst_wholeinsns clear vstart in all code paths
- patch 6 (patch 4 from v14):
- do not add early exits on helpers that are gated withvstart_eq_zero
- v14 link: https://lore.kernel.org/qemu-riscv/[email protected]/Daniel Henrique Barboza (9):
target/riscv/vector_helper.c: set vstart = 0 inGEN_VEXT_VSLIDEUP_VX()trans_rvv.c.inc: set vstart = 0 in int scalar move insnstarget/riscv/vector_helper.c: fix 'vmvr_v' memcpy endianess target/riscv: always clear vstart in whole vec move insns target/riscv: always clear vstart forldst_wholeinsns target/riscv/vector_helpers: do early exit when vstart >= vl target/riscv: remove 'over' brconds from vector trans trans_rvv.c.inc: remove redundantmark_vs_dirty()callstarget/riscv/vector_helper.c: optimize loops in ldst helpers
Quoted 2 lines
Ivan Klokov (1):
target/riscv: enable 'vstart_eq_zero' in the end of insns
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 15 lines
target/riscv/insn_trans/trans_rvbf16.c.inc | 18 +- target/riscv/insn_trans/trans_rvv.c.inc | 244 ++++++--------------- target/riscv/insn_trans/trans_rvvk.c.inc | 30 +-- target/riscv/translate.c | 6 + target/riscv/vcrypto_helper.c | 32 +++ target/riscv/vector_helper.c | 93 +++++++- target/riscv/vector_internals.c | 4 + target/riscv/vector_internals.h | 9 + 8 files changed, 220 insertions(+), 216 deletions(-)--
2.44.0