target/riscv: rvv: Add mask_reg_full_update option
PATCH 1/4 target/riscv: rvv: Add mask_reg_full_update option
Implementations can optionally write all bits of a mask production instruction, regardless of VL/SEW/LMUL configuration:
Furthermore, for mask-logical instructions and vmsbf.m, vmsif.m, vmsof.m mask-manipulation instructions, any element in the tail of the result can be written with the value the mask-producing operation would have calculated with vl=VLEN, SEW=8, and LMUL=8 (i.e., all bits of the mask register can be overwritten).
Add mask_reg_full_update to cover this.
---
I just picked the next free bit for MASK_REG_FULL_UPDATE, I presume that is correct.
target/riscv/cpu.c | 2 ++ target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/insn_trans/trans_rvv.c.inc | 4 ++++ target/riscv/internals.h | 1 + target/riscv/translate.c | 2 ++ target/riscv/vector_internals.h | 5 +++++ 6 files changed, 15 insertions(+)
target/riscv/cpu.c +2 -0
@@ -2688,6 +2688,8 @@ static const Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("rvv_ma_all_1s" ,RISCVCPU , cfg.rvv_ma_all_1s, false),DEFINE_PROP_BOOL ("rvv_vl_half_avl" ,RISCVCPU , cfg.rvv_vl_half_avl, false),DEFINE_PROP_BOOL ("rvv_vsetvl_x0_vill" ,RISCVCPU , cfg.rvv_vsetvl_x0_vill, false), +DEFINE_PROP_BOOL ("rvv_mask_reg_full_update" ,RISCVCPU , + cfg.rvv_mask_reg_full_update, false),/* * write_misa() is marked as experimental for now so mark
target/riscv/cpu_cfg_fields.h.inc +1 -0
@@ -117,6 +117,7 @@ BOOL_FIELD(rvv_ta_all_1s) BOOL_FIELD(rvv_ma_all_1s) BOOL_FIELD(rvv_vl_half_avl) BOOL_FIELD(rvv_vsetvl_x0_vill) +BOOL_FIELD(rvv_mask_reg_full_update) /* Named features */ BOOL_FIELD(ext_svade) BOOL_FIELD(ext_zic64b)
target/riscv/insn_trans/trans_rvv.c.inc +4 -0
@@ -3288,6 +3288,8 @@ static bool trans_##NAME(DisasContext *s, arg_r *a) \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = \ FIELD_DP32(data, VDATA, VTA_ALL_1S, s->cfg_vta_all_1s);\ + data = FIELD_DP32(data, VDATA, MASK_REG_FULL_UPDATE, \ + s->cfg_mask_reg_full_update); \ tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ vreg_ofs(s, a->rs1), \ vreg_ofs(s, a->rs2), tcg_env, \
@@ -3387,6 +3389,8 @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ data = \ FIELD_DP32(data, VDATA, VTA_ALL_1S, s->cfg_vta_all_1s);\ data = FIELD_DP32(data, VDATA, VMA, s->vma); \ + data = FIELD_DP32(data, VDATA, MASK_REG_FULL_UPDATE, \ + s->cfg_mask_reg_full_update); \ tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), \ vreg_ofs(s, 0), vreg_ofs(s, a->rs2), \ tcg_env, s->cfg_ptr->vlenb, \
target/riscv/internals.h +1 -0
@@ -70,6 +70,7 @@ FIELD(VDATA, VTA_ALL_1S, 5, 1) FIELD(VDATA, VMA, 6, 1) FIELD(VDATA, NF, 7, 4) FIELD(VDATA, WD, 7, 1) +FIELD (VDATA ,MASK_REG_FULL_UPDATE ,11 ,1 ) /* float point classify helpers */target_ulong fclass_h (uint64_t frs1);
target/riscv/translate.c +2 -0
@@ -101,6 +101,7 @@ typedef struct DisasContext {bool cfg_vta_all_1s;bool vstart_eq_zero;bool vl_eq_vlmax; +bool cfg_mask_reg_full_update;CPUState *cs;TCGv zero;/* actual address width */
@@ -1314,6 +1315,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->vta =FIELD_EX32 (tb_flags,TB_FLAGS ,VTA ) && cpu->cfg.rvv_ta_all_1s; ctx->vma =FIELD_EX32 (tb_flags,TB_FLAGS ,VMA ) && cpu->cfg.rvv_ma_all_1s; ctx->cfg_vta_all_1s = cpu->cfg.rvv_ta_all_1s; + ctx->cfg_mask_reg_full_update = cpu->cfg.rvv_mask_reg_full_update; ctx->vstart_eq_zero =FIELD_EX32 (tb_flags,TB_FLAGS ,VSTART_EQ_ZERO ); ctx->vl_eq_vlmax =FIELD_EX32 (tb_flags,TB_FLAGS ,VL_EQ_VLMAX ); ctx->misa_mxl_max = mcc->def->misa_mxl_max;
target/riscv/vector_internals.h +5 -0
@@ -94,6 +94,11 @@ static inline uint32_t vext_vta_all_1s(uint32_t desc)return FIELD_EX32 (simd_data (desc),VDATA ,VTA_ALL_1S ); } +static inline uint32_t vext_mask_reg_full_update (uint32_t desc) +{ +return FIELD_EX32 (simd_data (desc),VDATA ,MASK_REG_FULL_UPDATE ); +} +/* * Earlier designs (pre-0.9) had a varying number of bits * per mask value (MLEN). In the 0.9 design, MLEN=1.
Signature · 1 line
2.34.1
PATCH 2/4 target/riscv: rvv: Add mask_reg_full_update to mask-logical instructions
--- target/riscv/vector_helper.c | 6 ++++++ 1 file changed, 6 insertions(+)
target/riscv/vector_helper.c +6 -0
@@ -4980,11 +4980,17 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, \uint32_t vl = env->vl; \uint32_t total_elems =riscv_cpu_cfg (env)->vlenb <<3 ;\uint32_t vta_all_1s =vext_vta_all_1s (desc); \ +uint32_t mask_reg_full_update = \ +vext_mask_reg_full_update (desc); \uint32_t i; \int a, b; \ \VSTART_CHECK_EARLY_EXIT (env, vl); \ \ +if (mask_reg_full_update) { \ + vl = total_elems; \ + } \ + \for (i = env->vstart; i < vl; i++) { \ a =vext_elem_mask (vs1, i); \ b =vext_elem_mask (vs2, i); \
Signature · 1 line
2.34.1
PATCH 3/4 target/riscv: rvv: Add mask_reg_full_update to mask-manipulation instructions
In reply to Anton Blanchard--- target/riscv/vector_helper.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
target/riscv/vector_helper.c +16 -0
@@ -5075,12 +5075,17 @@ static void vmsetm(void *vd, void *v0, void *vs2, CPURISCVState *env,uint32_t vl = env->vl;uint32_t total_elems =riscv_cpu_cfg (env)->vlenb <<3 ;uint32_t vta_all_1s =vext_vta_all_1s (desc); +uint32_t mask_reg_full_update =vext_mask_reg_full_update (desc);uint32_t vma =vext_vma (desc);int i;bool first_mask_bit = false;VSTART_CHECK_EARLY_EXIT (env, vl); +if (mask_reg_full_update) { + vl = total_elems; + } +for (i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) {/* set masked-off elements to 1s */
@@ -5094,6 +5099,17 @@ static void vmsetm(void *vd, void *v0, void *vs2, CPURISCVState *env,vext_set_elem_mask (vd, i,0 );continue ; } + +/* Handle elements past vl in mask_reg_full_update mode */ +if (i >= env->vl) { +if (type ==ONLY_FIRST ) { +vext_set_elem_mask (vd, i,0 ); + }else { +vext_set_elem_mask (vd, i,1 ); + } +continue ; + } +if (vext_elem_mask (vs2, i)) { first_mask_bit = true;if (type ==BEFORE_FIRST ) {
Signature · 1 line
2.34.1
PATCH 4/4 target/riscv: Add mask_reg_full_update to Ascalon CPU model
In reply to Anton BlanchardAscalon writes all bits of the destination on mask-logical and mask-manipulation instructions.
--- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+)
target/riscv/cpu.c +1 -0
@@ -3169,6 +3169,7 @@ static const TypeInfo riscv_cpu_type_infos[] = { .cfg.elen = 64, .cfg.rvv_ma_all_1s = true, .cfg.rvv_ta_all_1s = true, + .cfg.rvv_mask_reg_full_update = true, .cfg.misa_w = true, .cfg.pmp = true, .cfg.cbom_blocksize = 64,
Signature · 1 line
2.34.1