Add mask agnostic behavior for rvv instructions
cover Add mask agnostic behavior for rvv instructions
According to v-spec, agnostic elements can be either kept as undisturbed or set elements' bits to all 1s. To distinguish the difference of mask policies, QEMU should be able to simulate the mask agnostic behavior as "set masked-off elements' bits to all 1s". An option 'rvv_ma_all_1s' is added to enable the behavior, it is default as disabled.
This patch set is based on the patch set "Add tail agnostic behavior for rvv instructions".
Based on: <[email protected]>
Yueh-Ting (eop) Chen (9):
target/riscv: rvv: Add mask agnostic for vv instructions target/riscv: rvv: Add mask agnostic for vector load / store
instructions
target/riscv: rvv: Add mask agnostic for vx instructions target/riscv: rvv: Add mask agnostic for vector integer shift
instructions
target/riscv: rvv: Add mask agnostic for vector integer comparison
instructions
target/riscv: rvv: Add mask agnostic for vector fix-point arithmetic
instructions
target/riscv: rvv: Add mask agnostic for vector floating-point
instructions
target/riscv: rvv: Add mask agnostic for vector mask instructions target/riscv: rvv: Add mask agnostic for vector permutation
instructions
target/riscv/cpu.c | 1 + target/riscv/cpu.h | 2 + target/riscv/cpu_helper.c | 2 + target/riscv/insn_trans/trans_rvv.c.inc | 32 +++++ target/riscv/internals.h | 5 +- target/riscv/translate.c | 2 + target/riscv/vector_helper.c | 159 ++++++++++++++++++++++-- 7 files changed, 189 insertions(+), 14 deletions(-)
Signature · 1 line
2.34.2
PATCH 1/9 target/riscv: rvv: Add mask agnostic for vv instructions
From: Yueh-Ting (eop) Chen <[email protected]>
This is the first commit regarding the mask agnostic behavior. Added option 'rvv_ma_all_1s' to enable the behavior, the option is default to false.
--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 2 ++ target/riscv/cpu_helper.c | 2 ++ target/riscv/insn_trans/trans_rvv.c.inc | 3 +++ target/riscv/internals.h | 5 +++-- target/riscv/translate.c | 2 ++ target/riscv/vector_helper.c | 8 ++++++++ 7 files changed, 21 insertions(+), 2 deletions(-)
target/riscv/cpu.c +1 -0
@@ -811,6 +811,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT64 ("resetvec" ,RISCVCPU , cfg.resetvec,DEFAULT_RSTVEC ),DEFINE_PROP_BOOL ("rvv_ta_all_1s" ,RISCVCPU , cfg.rvv_ta_all_1s, false), +DEFINE_PROP_BOOL ("rvv_ma_all_1s" ,RISCVCPU , cfg.rvv_ma_all_1s, false), DEFINE_PROP_END_OF_LIST(), };
target/riscv/cpu.h +2 -0
@@ -370,6 +370,7 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f;bool rvv_ta_all_1s; +bool rvv_ma_all_1s;/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;
@@ -518,6 +519,7 @@ FIELD(TB_FLAGS, XL, 20, 2) FIELD(TB_FLAGS, PM_MASK_ENABLED, 22, 1) FIELD(TB_FLAGS, PM_BASE_ENABLED, 23, 1) FIELD(TB_FLAGS, VTA, 24, 1) +FIELD(TB_FLAGS, VMA, 25, 1)#ifdef TARGET_RISCV32 #define riscv_cpu_mxl (env) ((void)(env), MXL_RV32)
target/riscv/cpu_helper.c +2 -0
@@ -67,6 +67,8 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, flags =FIELD_DP32 (flags,TB_FLAGS ,VL_EQ_VLMAX , vl_eq_vlmax); flags =FIELD_DP32 (flags,TB_FLAGS ,VTA ,FIELD_EX64 (env->vtype,VTYPE ,VTA )); + flags =FIELD_DP32 (flags,TB_FLAGS ,VMA , +FIELD_EX64 (env->vtype,VTYPE ,VMA )); }else { flags =FIELD_DP32 (flags,TB_FLAGS ,VILL ,1 ); }
target/riscv/insn_trans/trans_rvv.c.inc +3 -0
@@ -1251,6 +1251,7 @@ do_opivv_gvec(DisasContext *s, arg_rmrr *a, GVecGen3Fn *gvec_fn, data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), vreg_ofs(s, a->rs1), vreg_ofs(s, a->rs2), cpu_env, s->cfg_ptr->vlen / 8,
@@ -1567,6 +1568,7 @@ static bool do_opivv_widen(DisasContext *s, arg_rmrr *a, data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), vreg_ofs(s, a->rs1), vreg_ofs(s, a->rs2),
@@ -1649,6 +1651,7 @@ static bool do_opiwv_widen(DisasContext *s, arg_rmrr *a, data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), vreg_ofs(s, a->rs1), vreg_ofs(s, a->rs2),
target/riscv/internals.h +3 -2
@@ -25,8 +25,9 @@ FIELD(VDATA, VM, 0, 1) FIELD(VDATA, LMUL, 1, 3) FIELD(VDATA, VTA, 4, 1) -FIELD(VDATA, NF, 5, 4) -FIELD (VDATA ,WD ,5 ,1 ) +FIELD(VDATA, VMA, 5, 1) +FIELD(VDATA, NF, 6, 4) +FIELD (VDATA ,WD ,6 ,1 ) /* float point classify helpers */target_ulong fclass_h (uint64_t frs1);
target/riscv/translate.c +2 -0
@@ -95,6 +95,7 @@ typedef struct DisasContext {int8_t lmul;uint8_t sew;uint8_t vta; +uint8_t vma;target_ulong vstart;bool vl_eq_vlmax;uint8_t ntemp;
@@ -1085,6 +1086,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->sew =FIELD_EX32 (tb_flags,TB_FLAGS ,SEW ); ctx->lmul =sextract32 (FIELD_EX32 (tb_flags,TB_FLAGS ,LMUL ),0 ,3 ); 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->vstart = env->vstart; ctx->vl_eq_vlmax =FIELD_EX32 (tb_flags,TB_FLAGS ,VL_EQ_VLMAX ); ctx->misa_mxl_max = env->misa_mxl_max;
target/riscv/vector_helper.c +8 -0
@@ -127,6 +127,11 @@ static inline uint32_t vext_vta(uint32_t desc)return FIELD_EX32 (simd_data (desc),VDATA ,VTA ); } +static inline uint32_t vext_vma (uint32_t desc) +{ +return FIELD_EX32 (simd_data (desc),VDATA ,VMA ); +} +/* * Get the maximum number of elements can be operated. *
@@ -797,10 +802,13 @@ static void do_vext_vv(void *vd, void *v0, void *vs1, void *vs2,uint32_t vl = env->vl;uint32_t total_elems =vext_get_total_elems (desc, esz);uint32_t vta =vext_vta (desc); +uint32_t vma =vext_vma (desc);uint32_t i;for (i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) { +/* set masked-off elements to 1s */ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, (i +1 ) * esz);continue ; }fn (vd, vs1, vs2, i);
Signature · 1 line
2.34.2
Re: [PATCH qemu 1/9] target/riscv: rvv: Add mask agnostic for vv instructions
Quoted 144 lines · ~eopxd
From: Yueh-Ting (eop) Chen <[email protected]>
This is the first commit regarding the mask agnostic behavior. Added option '
rvv_ma_all_1s' to enable the behavior, the option is default to false.Signed-off-by eop Chen <[email protected]>Reviewed-by Frank Chang <[email protected]>--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 2 ++ target/riscv/cpu_helper.c | 2 ++ target/riscv/insn_trans/trans_rvv.c.inc | 3 +++ target/riscv/internals.h | 5 +++-- target/riscv/translate.c | 2 ++ target/riscv/vector_helper.c | 8 ++++++++ 7 files changed, 21 insertions(+), 2 deletions(-)target/riscv/cpu.c +1
-0@@ -811,6 +811,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT64 ("resetvec" ,RISCVCPU , cfg.resetvec,DEFAULT_RSTVEC ),DEFINE_PROP_BOOL ("rvv_ta_all_1s" ,RISCVCPU , cfg.rvv_ta_all_1s, false), +DEFINE_PROP_BOOL ("rvv_ma_all_1s" ,RISCVCPU , cfg.rvv_ma_all_1s, false), DEFINE_PROP_END_OF_LIST(), };target/riscv/cpu.h +2
-0@@ -370,6 +370,7 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f;bool rvv_ta_all_1s; +bool rvv_ma_all_1s;/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;@@ -518,6 +519,7 @@ FIELD(TB_FLAGS, XL, 20, 2) FIELD(TB_FLAGS, PM_MASK_ENABLED, 22, 1) FIELD(TB_FLAGS, PM_BASE_ENABLED, 23, 1) FIELD(TB_FLAGS, VTA, 24, 1) +FIELD(TB_FLAGS, VMA, 25, 1)#ifdef TARGET_RISCV32 #define riscv_cpu_mxl (env) ((void)(env), MXL_RV32)target/riscv/cpu_helper.c +2
-0@@ -67,6 +67,8 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, flags =FIELD_DP32 (flags,TB_FLAGS ,VL_EQ_VLMAX , vl_eq_vlmax); flags =FIELD_DP32 (flags,TB_FLAGS ,VTA ,FIELD_EX64 (env->vtype,VTYPE ,VTA )); + flags =FIELD_DP32 (flags,TB_FLAGS ,VMA , +FIELD_EX64 (env->vtype,VTYPE ,VMA )); }else { flags =FIELD_DP32 (flags,TB_FLAGS ,VILL ,1 ); }target/riscv/insn_trans/trans_rvv.c.inc +3
-0@@ -1251,6 +1251,7 @@ do_opivv_gvec(DisasContext *s, arg_rmrr *a, GVecGen3Fn *gvec_fn, data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), vreg_ofs(s, a->rs1), vreg_ofs(s, a->rs2), cpu_env, s->cfg_ptr->vlen / 8,@@ -1567,6 +1568,7 @@ static bool do_opivv_widen(DisasContext *s, arg_rmrr *a, data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), vreg_ofs(s, a->rs1), vreg_ofs(s, a->rs2),@@ -1649,6 +1651,7 @@ static bool do_opiwv_widen(DisasContext *s, arg_rmrr *a, data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), vreg_ofs(s, a->rs1), vreg_ofs(s, a->rs2),target/riscv/internals.h +3
-2@@ -25,8 +25,9 @@ FIELD(VDATA, VM, 0, 1) FIELD(VDATA, LMUL, 1, 3) FIELD(VDATA, VTA, 4, 1) -FIELD(VDATA, NF, 5, 4) -FIELD (VDATA ,WD ,5 ,1 ) +FIELD(VDATA, VMA, 5, 1) +FIELD(VDATA, NF, 6, 4) +FIELD (VDATA ,WD ,6 ,1 ) /* float point classify helpers */target_ulong fclass_h (uint64_t frs1);target/riscv/translate.c +2
-0@@ -95,6 +95,7 @@ typedef struct DisasContext {int8_t lmul;uint8_t sew;uint8_t vta; +uint8_t vma;target_ulong vstart;bool vl_eq_vlmax;uint8_t ntemp;@@ -1085,6 +1086,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->sew =FIELD_EX32 (tb_flags,TB_FLAGS ,SEW ); ctx->lmul =sextract32 (FIELD_EX32 (tb_flags,TB_FLAGS ,LMUL ),0 ,3 ); 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->vstart = env->vstart; ctx->vl_eq_vlmax =FIELD_EX32 (tb_flags,TB_FLAGS ,VL_EQ_VLMAX ); ctx->misa_mxl_max = env->misa_mxl_max;target/riscv/vector_helper.c +5
-0@@ -127,6 +127,11 @@ static inline uint32_t vext_vta(uint32_t desc)return FIELD_EX32 (simd_data (desc),VDATA ,VTA ); } +static inline uint32_t vext_vma (uint32_t desc) +{ +return FIELD_EX32 (simd_data (desc),VDATA ,VMA ); +} +/* * Get the maximum number of elements can be operated. *
target/riscv/vector_helper.c static void do_vext_vv(void *vd, void *v0, void *vs1, void *vs2, · line 811
Quoted 10 lines
target/riscv/vector_helper.c +3
-0@@ -797,10 +802,13 @@ static void do_vext_vv(void *vd, void *v0, void *vs1, void *vs2,uint32_t vl = env->vl;uint32_t total_elems =vext_get_total_elems (desc, esz);uint32_t vta =vext_vta (desc); +uint32_t vma =vext_vma (desc);uint32_t i;for (i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) { +/* set masked-off elements to 1s */ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, (i +1 ) * esz);
Similar to our last discussion, vext_set_elems_1s_fns array can be simplified to single vext_set_elems_1s,
since the fourth argement can be used as the start offset.
Another question, may be not related to this patchset, in section 3.4.3 of the spec:
/"Mask destination tail elements are always treated as tail-agnostic, regardless of the setting of vta."/
What does "Mask destination tail elements" mean?
Regards,
Weiwei Li
Quoted 3 lines
target/riscv/vector_helper.c +0
-0continue ; }fn (vd, vs1, vs2, i);
Re: [PATCH qemu 1/9] target/riscv: rvv: Add mask agnostic for vv instructions
Quoted 17 lines
Weiwei Li <[email protected]> 於 2022年4月26日 下午4:47 寫道:
Quoted 8 lines · ~eopxd
From: Yueh-Ting (eop) Chen <[email protected]> <mailto:[email protected]>
This is the first commit regarding the mask agnostic behavior. Added option '
rvv_ma_all_1s' to enable the behavior, the option is default to false.Similar to our last discussion,
vext_set_elems_1s_fnsarray can be simplified to singlevext_set_elems_1s,since the fourth argement can be used as the start offset.
Another question, may be not related to this patchset, in section 3.4.3 of the spec:
Quoted 8 lines
"Mask destination tail elements are always treated as tail-agnostic, regardless of the setting of vta."
What does "Mask destination tail elements" mean?
Regards,
Weiwei Li
I have just updated a new version for the tail agnostic patch set, it also includes a bug fix discovered today.
Regarding the question, mask / masked-off are for body elements and respects the mask policy, and tail elements respect the tail policy.
Regards,
eop Chen
Re: [PATCH qemu 1/9] target/riscv: rvv: Add mask agnostic for vv instructions
Quoted 27 lines · eop Chen
Quoted 18 lines
Weiwei Li <[email protected] <mailto:[email protected]>> 於 2022年4月26日 下午4:47 寫道:
Quoted 8 lines · ~eopxd
From: Yueh-Ting (eop) Chen<[email protected]>
This is the first commit regarding the mask agnostic behavior. Added option '
rvv_ma_all_1s' to enable the behavior, the option is default to false.Signed-off-by eop Chen<[email protected]>Reviewed-by Frank Chang<[email protected]>Similar to our last discussion,
vext_set_elems_1s_fnsarray can be simplified to singlevext_set_elems_1s,since the fourth argement can be used as the start offset.
Another question, may be not related to this patchset, in section 3.4.3 of the spec:
Quoted 8 lines
/"Mask destination tail elements are always treated as tail-agnostic, regardless of the setting of vta."/
What does "Mask destination tail elements" mean?
Regards,
Weiwei Li
Quoted 7 lines
I have just updated a new version for the tail agnostic patch set, it also includes a bug fix discovered today.
Regarding the question, mask / masked-off are for body elements and respects the mask policy, and tail elements respect the tail policy.
Regards,
eop Chen
I find another descriptions in the spec. For the instructions that write mask register (such as vmadc, vmseq,vmsne,vmfeq...), they all have similar description
(You can search "tail-agnostic" in the spec):
/Section 11.4: "Because these instructions produce a mask value, they always operate with a tail-agnostic policy"// /
/Section 11.8/13.13: "Compares //write mask registers, and so always operate under a tail-agnostic policy"// /
/Section 15.1: "Mask elements past vl, the tail elements, are always updated with a tail-agnostic policy"// /
//
/Section 15.4/15.5/15.6: "The tail elements in the destination mask register are updated under a tail-agnostic policy"/
So I think "Mask destination tail elements" may means the tail element for instructions that take mask register as destination register. For these instructions,
maybe the setting of VTA can be ignored.
Regards,
Weiwei Li
Re: [PATCH qemu 1/9] target/riscv: rvv: Add mask agnostic for vv instructions
Quoted 51 lines · eop Chen
Quoted 27 lines
Quoted 17 lines
Weiwei Li <[email protected] <mailto:[email protected]>> 於 2022年4月26日 下午4:47 寫道:
Quoted 8 lines · ~eopxd
From: Yueh-Ting (eop) Chen <[email protected]> <mailto:[email protected]>
This is the first commit regarding the mask agnostic behavior. Added option '
rvv_ma_all_1s' to enable the behavior, the option is default to false.Similar to our last discussion,
vext_set_elems_1s_fnsarray can be simplified to singlevext_set_elems_1s,since the fourth argement can be used as the start offset.
Another question, may be not related to this patchset, in section 3.4.3 of the spec:
Quoted 8 lines
"Mask destination tail elements are always treated as tail-agnostic, regardless of the setting of vta."
What does "Mask destination tail elements" mean?
Regards,
Weiwei Li
Quoted 7 lines
I have just updated a new version for the tail agnostic patch set, it also includes a bug fix discovered today.
Regarding the question, mask / masked-off are for body elements and respects the mask policy, and tail elements respect the tail policy.
Regards,
eop Chen
I find another descriptions in the spec. For the instructions that write mask register (such as vmadc, vmseq,vmsne,vmfeq...), they all have similar description
(You can search "tail-agnostic" in the spec):
Section 11.4: "Because these instructions produce a mask value, they always operate with a tail-agnostic policy"
Section 11.8/13.13: "Compares write mask registers, and so always operate under a tail-agnostic policy"
Section 15.1: "Mask elements past vl, the tail elements, are always updated with a tail-agnostic policy"
Section 15.4/15.5/15.6: "The tail elements in the destination mask register are updated under a tail-agnostic policy"
Quoted 8 lines
So I think "Mask destination tail elements" may means the tail element for instructions that take mask register as destination register. For these instructions,
maybe the setting of VTA can be ignored.
Regards,
Weiwei Li
Yes, the setting of VTA should be ignored when v-spec specifies.
I think the implementation of the tail agnostic patch set don’t need to change on this.
Regards,
eop Chen
Re: [PATCH qemu 1/9] target/riscv: rvv: Add mask agnostic for vv instructions
Quoted 60 lines · eop Chen
Quoted 60 lines · eop Chen
Quoted 27 lines
Quoted 18 lines
Weiwei Li <[email protected] <mailto:[email protected]>> 於 2022年4月26日 下午4:47 寫道:
Quoted 8 lines · ~eopxd
From: Yueh-Ting (eop) Chen<[email protected]>
This is the first commit regarding the mask agnostic behavior. Added option '
rvv_ma_all_1s' to enable the behavior, the option is default to false.Signed-off-by eop Chen<[email protected]>Reviewed-by Frank Chang<[email protected]>Similar to our last discussion,
vext_set_elems_1s_fnsarray can be simplified to singlevext_set_elems_1s,since the fourth argement can be used as the start offset.
Another question, may be not related to this patchset, in section 3.4.3 of the spec:
Quoted 8 lines
/"Mask destination tail elements are always treated as tail-agnostic, regardless of the setting of vta."/
What does "Mask destination tail elements" mean?
Regards,
Weiwei Li
Quoted 7 lines
I have just updated a new version for the tail agnostic patch set, it also includes a bug fix discovered today.
Regarding the question, mask / masked-off are for body elements and respects the mask policy, and tail elements respect the tail policy.
Regards,
eop Chen
I find another descriptions in the spec. For the instructions that write mask register (such as vmadc, vmseq,vmsne,vmfeq...), they all have similar description
(You can search "tail-agnostic" in the spec):
/Section 11.4: "Because these instructions produce a mask value, they always operate with a tail-agnostic policy"// /
/Section 11.8/13.13: "Compares //write mask registers, and so always operate under a tail-agnostic policy"// /
/Section 15.1: "Mask elements past vl, the tail elements, are always updated with a tail-agnostic policy"// /
//
/Section 15.4/15.5/15.6: "The tail elements in the destination mask register are updated under a tail-agnostic policy"/
So I think "Mask destination tail elements" may means the tail element for instructions that take mask register as destination register. For these instructions,
maybe the setting of VTA can be ignored.
Quoted 7 lines
Quoted 4 lines
Regards,
Weiwei Li
Yes, the setting of VTA should be ignored when v-spec specifies.
I think the implementation of the tail agnostic patch set don’t need to change on this.
Sorry. I don't get your idea?
In current patch, these instructions seems need to set the tail elements to 1s when vta is true which means
VTA is setted and rvv_ta_all_1s is enabled. If setting of VTA should be ignored for these instrucitons,
they will set the tail elements to 1s only when rvv_ta_all_1s is enabled.
Regards,
Weiwei Li
Quoted 7 lines
Regards,
eop Chen
Re: [PATCH qemu 1/9] target/riscv: rvv: Add mask agnostic for vv instructions
Quoted 73 lines
Weiwei Li <[email protected]> 於 2022年4月27日 上午11:27 寫道:
Quoted 55 lines · eop Chen
Quoted 55 lines · eop Chen
Quoted 27 lines
Quoted 17 lines
Weiwei Li <[email protected] <mailto:[email protected]>> 於 2022年4月26日 下午4:47 寫道:
Quoted 8 lines · ~eopxd
From: Yueh-Ting (eop) Chen <[email protected]> <mailto:[email protected]>
This is the first commit regarding the mask agnostic behavior. Added option '
rvv_ma_all_1s' to enable the behavior, the option is default to false.Similar to our last discussion,
vext_set_elems_1s_fnsarray can be simplified to singlevext_set_elems_1s,since the fourth argement can be used as the start offset.
Another question, may be not related to this patchset, in section 3.4.3 of the spec:
Quoted 8 lines
"Mask destination tail elements are always treated as tail-agnostic, regardless of the setting of vta."
What does "Mask destination tail elements" mean?
Regards,
Weiwei Li
Quoted 7 lines
I have just updated a new version for the tail agnostic patch set, it also includes a bug fix discovered today.
Regarding the question, mask / masked-off are for body elements and respects the mask policy, and tail elements respect the tail policy.
Regards,
eop Chen
I find another descriptions in the spec. For the instructions that write mask register (such as vmadc, vmseq,vmsne,vmfeq...), they all have similar description
(You can search "tail-agnostic" in the spec):
Section 11.4: "Because these instructions produce a mask value, they always operate with a tail-agnostic policy"
Section 11.8/13.13: "Compares write mask registers, and so always operate under a tail-agnostic policy"
Section 15.1: "Mask elements past vl, the tail elements, are always updated with a tail-agnostic policy"
Section 15.4/15.5/15.6: "The tail elements in the destination mask register are updated under a tail-agnostic policy"
So I think "Mask destination tail elements" may means the tail element for instructions that take mask register as destination register. For these instructions,
maybe the setting of VTA can be ignored.
Quoted 7 lines
Quoted 4 lines
Regards,
Weiwei Li
Yes, the setting of VTA should be ignored when v-spec specifies.
I think the implementation of the tail agnostic patch set don’t need to change on this.Sorry. I don't get your idea?
In current patch, these instructions seems need to set the tail elements to 1s when vta is true which means
Quoted 15 lines
VTA is setted and
rvv_ta_all_1sis enabled. If setting of VTA should be ignored for these instrucitons,they will set the tail elements to 1s only when
rvv_ta_all_1sis enabled.Regards,
Weiwei Li
Quoted 7 lines
Regards,
eop Chen
I see your point now. Yes the implementation should be changed. Let me submit a new version for this.
Regards,
eop Chen
PATCH 2/9 target/riscv: rvv: Add mask agnostic for vector load / store instructions
In reply to ~eopxdFrom: Yueh-Ting (eop) Chen <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 9 +++++++++ target/riscv/vector_helper.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+)
target/riscv/insn_trans/trans_rvv.c.inc +9 -0
@@ -712,6 +712,7 @@ static bool ld_us_op(DisasContext *s, arg_r2nfvm *a, uint8_t eew) data = FIELD_DP32(data, VDATA, LMUL, emul); 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_us_trans(a->rd, a->rs1, data, fn, s, false); }
@@ -750,6 +751,7 @@ static bool st_us_op(DisasContext *s, arg_r2nfvm *a, uint8_t eew) data = FIELD_DP32(data, VDATA, LMUL, emul); 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_us_trans(a->rd, a->rs1, data, fn, s, true); }
@@ -777,6 +779,7 @@ static bool ld_us_mask_op(DisasContext *s, arg_vlm_v *a, uint8_t eew) data = FIELD_DP32(data, VDATA, LMUL, 0); data = FIELD_DP32(data, VDATA, NF, 1); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); return ldst_us_trans(a->rd, a->rs1, data, fn, s, false); }
@@ -795,6 +798,7 @@ static bool st_us_mask_op(DisasContext *s, arg_vsm_v *a, uint8_t eew) data = FIELD_DP32(data, VDATA, LMUL, 0); data = FIELD_DP32(data, VDATA, NF, 1); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); return ldst_us_trans(a->rd, a->rs1, data, fn, s, true); }
@@ -867,6 +871,7 @@ static bool ld_stride_op(DisasContext *s, arg_rnfvm *a, uint8_t eew) data = FIELD_DP32(data, VDATA, LMUL, emul); 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, false); }
@@ -897,6 +902,7 @@ static bool st_stride_op(DisasContext *s, arg_rnfvm *a, uint8_t eew) data = FIELD_DP32(data, VDATA, LMUL, emul); data = FIELD_DP32(data, VDATA, NF, a->nf); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); fn = fns[eew]; if (fn == NULL) { return false;
@@ -998,6 +1004,7 @@ static bool ld_index_op(DisasContext *s, arg_rnfvm *a, uint8_t eew) data = FIELD_DP32(data, VDATA, LMUL, emul); 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_index_trans(a->rd, a->rs1, a->rs2, data, fn, s, false); }
@@ -1051,6 +1058,7 @@ static bool st_index_op(DisasContext *s, arg_rnfvm *a, uint8_t eew) data = FIELD_DP32(data, VDATA, LMUL, emul); 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_index_trans(a->rd, a->rs1, a->rs2, data, fn, s, true); }
@@ -1117,6 +1125,7 @@ static bool ldff_op(DisasContext *s, arg_r2nfvm *a, uint8_t eew) data = FIELD_DP32(data, VDATA, LMUL, emul); 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 ldff_trans(a->rd, a->rs1, data, fn, s); }
target/riscv/vector_helper.c +20 -0
@@ -296,9 +296,17 @@ vext_ldst_stride(void *vd, void *v0, target_ulong base,uint32_t max_elems =vext_max_elems (desc, log2_esz);uint32_t esz =1 << log2_esz;uint32_t vta =vext_vta (desc); +uint32_t vma =vext_vma (desc);for (i = env->vstart; i < env->vl; i++, env->vstart++) {if (!vm && !vext_elem_mask (v0, i)) { + k =0 ; +while (k < nf) { +/* set masked-off elements to 1s */ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i + k * max_elems, + (i + k * max_elems) * esz, (i + k * max_elems +1 ) * esz); + k++; + }continue ; }
@@ -479,10 +487,18 @@ vext_ldst_index(void *vd, void *v0, target_ulong base,uint32_t max_elems =vext_max_elems (desc, log2_esz);uint32_t esz =1 << log2_esz;uint32_t vta =vext_vta (desc); +uint32_t vma =vext_vma (desc);/* load bytes from guest memory */ for (i = env->vstart; i < env->vl; i++, env->vstart++) {if (!vm && !vext_elem_mask (v0, i)) { + k =0 ; +while (k < nf) { +/* set masked-off elements to 1s */ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i + k * max_elems, + (i + k * max_elems) * esz, (i + k * max_elems +1 ) * esz); + k++; + }continue ; }
@@ -568,6 +584,7 @@ vext_ldff(void *vd, void *v0, target_ulong base,uint32_t max_elems =vext_max_elems (desc, log2_esz);uint32_t esz =1 << log2_esz;uint32_t vta =vext_vta (desc); +uint32_t vma =vext_vma (desc);target_ulong addr, offset, remain;/* probe every access*/
@@ -614,6 +631,9 @@ ProbeSuccess:for (i = env->vstart; i < env->vl; i++) { k =0 ;if (!vm && !vext_elem_mask (v0, i)) { +/* set masked-off elements to 1s */ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i + k * max_elems, + (i + k * max_elems) * esz, (i + k * max_elems +1 ) * esz);continue ; }while (k < nf) {
Signature · 1 line
2.34.2
PATCH 3/9 target/riscv: rvv: Add mask agnostic for vx instructions
In reply to ~eopxdFrom: Yueh-Ting (eop) Chen <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 2 ++ target/riscv/vector_helper.c | 3 +++ 2 files changed, 5 insertions(+)
target/riscv/insn_trans/trans_rvv.c.inc +2 -0
@@ -1308,6 +1308,7 @@ static bool opivx_trans(uint32_t vd, uint32_t rs1, uint32_t vs2, uint32_t vm, data = FIELD_DP32(data, VDATA, VM, vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); desc = tcg_constant_i32(simd_desc(s->cfg_ptr->vlen / 8, s->cfg_ptr->vlen / 8, data));
@@ -1484,6 +1485,7 @@ static bool opivi_trans(uint32_t vd, uint32_t imm, uint32_t vs2, uint32_t vm, data = FIELD_DP32(data, VDATA, VM, vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); desc = tcg_constant_i32(simd_desc(s->cfg_ptr->vlen / 8, s->cfg_ptr->vlen / 8, data));
target/riscv/vector_helper.c +3 -0
@@ -891,10 +891,13 @@ static void do_vext_vx(void *vd, void *v0, target_long s1, void *vs2,uint32_t vl = env->vl;uint32_t total_elems =vext_get_total_elems (desc, esz);uint32_t vta =vext_vta (desc); +uint32_t vma =vext_vma (desc);uint32_t i;for (i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) { +/* set masked-off elements to 1s */ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, (i +1 ) * esz);continue ; }fn (vd, s1, vs2, i);
Signature · 1 line
2.34.2
PATCH 4/9 target/riscv: rvv: Add mask agnostic for vector integer shift instructions
In reply to ~eopxdFrom: Yueh-Ting (eop) Chen <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 1 + target/riscv/vector_helper.c | 9 +++++++++ 2 files changed, 10 insertions(+)
target/riscv/insn_trans/trans_rvv.c.inc +1 -0
@@ -1935,6 +1935,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ vreg_ofs(s, a->rs1), \ vreg_ofs(s, a->rs2), cpu_env, \
target/riscv/vector_helper.c +9 -0
@@ -1291,10 +1291,14 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, \uint32_t esz =sizeof (TS1 ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, \ + (i +1 ) * esz); \continue ; \ } \TS1 s1 = *((TS1 *)vs1 +HS1 (i)); \
@@ -1332,10 +1336,15 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, \uint32_t esz =sizeof (TD ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, \ + i * esz, \ + (i +1 ) * esz);\continue ; \ } \TS2 s2 = *((TS2 *)vs2 +HS2 (i)); \
Signature · 1 line
2.34.2
PATCH 5/9 target/riscv: rvv: Add mask agnostic for vector integer comparison instructions
In reply to ~eopxdFrom: Yueh-Ting (eop) Chen <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 1 + target/riscv/vector_helper.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
target/riscv/insn_trans/trans_rvv.c.inc +1 -0
@@ -1742,6 +1742,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ vreg_ofs(s, a->rs1), \ vreg_ofs(s, a->rs2), cpu_env, \
target/riscv/vector_helper.c +10 -0
@@ -1401,12 +1401,17 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \ETYPE s1 = *((ETYPE *)vs1 +H (i)); \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ +if (vma) { \ +vext_set_elem_mask (vd, i,1 ); \ + } \continue ; \ } \vext_set_elem_mask (vd, i,DO_OP (s2, s1)); \
@@ -1459,11 +1464,16 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ +if (vma) { \ +vext_set_elem_mask (vd, i,1 ); \ + } \continue ; \ } \ vext_set_elem_mask(vd, i, \
Signature · 1 line
2.34.2
PATCH 6/9 target/riscv: rvv: Add mask agnostic for vector fix-point arithmetic instructions
In reply to ~eopxdFrom: Yueh-Ting (eop) Chen <[email protected]>
--- target/riscv/vector_helper.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
target/riscv/vector_helper.c +16 -10
@@ -2129,10 +2129,12 @@ static inline voidvext_vv_rm_1 (void *vd, void *v0, void *vs1, void *vs2, CPURISCVState *env, uint32_t vl, uint32_t vm, int vxrm, - opivv2_rm_fn *fn) + opivv2_rm_fn *fn, uint32_t vma, uint32_t esz) {for (uint32_t i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) { +/* set masked-off elements to 1s */ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, (i +1 ) * esz);continue ; }fn (vd, vs1, vs2, i, env, vxrm);
@@ -2150,23 +2152,24 @@ vext_vv_rm_2(void *vd, void *v0, void *vs1, void *vs2,uint32_t vl = env->vl;uint32_t total_elems =vext_get_total_elems (desc, esz);uint32_t vta =vext_vta (desc); +uint32_t vma =vext_vma (desc);switch (env->vxrm) {case 0 :/* rnu */ vext_vv_rm_1 (vd, v0, vs1, vs2, - env, vl, vm,0 , fn); + env, vl, vm,0 , fn, vma, esz);break ;case 1 :/* rne */ vext_vv_rm_1 (vd, v0, vs1, vs2, - env, vl, vm,1 , fn); + env, vl, vm,1 , fn, vma, esz);break ;case 2 :/* rdn */ vext_vv_rm_1 (vd, v0, vs1, vs2, - env, vl, vm,2 , fn); + env, vl, vm,2 , fn, vma, esz);break ;default :/* rod */ vext_vv_rm_1 (vd, v0, vs1, vs2, - env, vl, vm,3 , fn); + env, vl, vm,3 , fn, vma, esz);break ; }/* set tail elements to 1s */
@@ -2250,10 +2253,12 @@ static inline void vext_vx_rm_1(void *vd, void *v0, target_long s1, void *vs2, CPURISCVState *env, uint32_t vl, uint32_t vm, int vxrm, - opivx2_rm_fn *fn) + opivx2_rm_fn *fn, uint32_t vma, uint32_t esz) {for (uint32_t i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) { +/* set masked-off elements to 1s */ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, (i +1 ) * esz);continue ; }fn (vd, s1, vs2, i, env, vxrm);
@@ -2271,23 +2276,24 @@ vext_vx_rm_2(void *vd, void *v0, target_long s1, void *vs2,uint32_t vl = env->vl;uint32_t total_elems =vext_get_total_elems (desc, esz);uint32_t vta =vext_vta (desc); +uint32_t vma =vext_vma (desc);switch (env->vxrm) {case 0 :/* rnu */ vext_vx_rm_1 (vd, v0, s1, vs2, - env, vl, vm,0 , fn); + env, vl, vm,0 , fn, vma, esz);break ;case 1 :/* rne */ vext_vx_rm_1 (vd, v0, s1, vs2, - env, vl, vm,1 , fn); + env, vl, vm,1 , fn, vma, esz);break ;case 2 :/* rdn */ vext_vx_rm_1 (vd, v0, s1, vs2, - env, vl, vm,2 , fn); + env, vl, vm,2 , fn, vma, esz);break ;default :/* rod */ vext_vx_rm_1 (vd, v0, s1, vs2, - env, vl, vm,3 , fn); + env, vl, vm,3 , fn, vma, esz);break ; }/* set tail elements to 1s */
Signature · 1 line
2.34.2
PATCH 7/9 target/riscv: rvv: Add mask agnostic for vector floating-point instructions
In reply to ~eopxdFrom: Yueh-Ting (eop) Chen <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 12 +++++++++ target/riscv/vector_helper.c | 36 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
target/riscv/insn_trans/trans_rvv.c.inc +12 -0
@@ -2415,6 +2415,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ vreg_ofs(s, a->rs1), \ vreg_ofs(s, a->rs2), cpu_env, \
@@ -2498,6 +2499,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ return opfvf_trans(a->rd, a->rs1, a->rs2, data, \ fns[s->sew - 1], s); \ } \
@@ -2537,6 +2539,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ vreg_ofs(s, a->rs1), \ vreg_ofs(s, a->rs2), cpu_env, \
@@ -2577,6 +2580,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ return opfvf_trans(a->rd, a->rs1, a->rs2, data, \ fns[s->sew - 1], s); \ } \
@@ -2614,6 +2618,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ vreg_ofs(s, a->rs1), \ vreg_ofs(s, a->rs2), cpu_env, \
@@ -2654,6 +2659,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmrr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ return opfvf_trans(a->rd, a->rs1, a->rs2, data, \ fns[s->sew - 1], s); \ } \
@@ -2738,6 +2744,7 @@ static bool do_opfv(DisasContext *s, arg_rmr *a, data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), vreg_ofs(s, a->rs2), cpu_env, s->cfg_ptr->vlen / 8,
@@ -2852,6 +2859,7 @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) TCGv_i32 desc; uint32_t data = FIELD_DP32(0, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); static gen_helper_vmv_vx * const fns[3] = { gen_helper_vmv_v_x_h, gen_helper_vmv_v_x_w,
@@ -2953,6 +2961,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ vreg_ofs(s, a->rs2), cpu_env, \ s->cfg_ptr->vlen / 8, \
@@ -3005,6 +3014,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ vreg_ofs(s, a->rs2), cpu_env, \ s->cfg_ptr->vlen / 8, \
@@ -3073,6 +3083,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ vreg_ofs(s, a->rs2), cpu_env, \ s->cfg_ptr->vlen / 8, \
@@ -3127,6 +3138,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), \ vreg_ofs(s, a->rs2), cpu_env, \ s->cfg_ptr->vlen / 8, \
target/riscv/vector_helper.c +36 -0
@@ -3051,10 +3051,16 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, \uint32_t total_elems = \vext_get_total_elems (desc,ESZ ); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (ESZ )](vd, vma, i, \ + i *ESZ , \ + (i +1 ) * \ +ESZ ); \continue ; \ } \ do_##NAME(vd, vs1, vs2, i, env); \
@@ -3091,10 +3097,16 @@ void HELPER(NAME)(void *vd, void *v0, uint64_t s1, \uint32_t total_elems = \vext_get_total_elems (desc,ESZ ); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (ESZ )](vd, vma, i, \ + i *ESZ , \ + (i +1 ) * \ +ESZ ); \continue ; \ } \ do_##NAME(vd, s1, vs2, i, env); \
@@ -3667,6 +3679,7 @@ void HELPER(NAME)(void *vd, void *v0, void *vs2, \uint32_t total_elems = \vext_get_total_elems (desc,ESZ ); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \if (vl ==0 ) { \
@@ -3674,6 +3687,12 @@ void HELPER(NAME)(void *vd, void *v0, void *vs2, \ } \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (ESZ )](vd, vma, \ + i, \ + i *ESZ , \ + (i +1 ) \ + *ESZ ); \continue ; \ } \ do_##NAME(vd, vs2, i, env); \
@@ -4188,12 +4207,17 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \ETYPE s1 = *((ETYPE *)vs1 +H (i)); \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ +if (vma) { \ +vext_set_elem_mask (vd, i,1 ); \ + } \continue ; \ } \ vext_set_elem_mask(vd, i, \
@@ -4221,11 +4245,16 @@ void HELPER(NAME)(void *vd, void *v0, uint64_t s1, void *vs2, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \ETYPE s2 = *((ETYPE *)vs2 +H (i)); \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ +if (vma) { \ +vext_set_elem_mask (vd, i,1 ); \ + } \continue ; \ } \ vext_set_elem_mask(vd, i, \
@@ -4347,10 +4376,17 @@ void HELPER(NAME)(void *vd, void *v0, void *vs2, \uint32_t total_elems = \vext_get_total_elems (desc,ESZ ); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (ESZ )](vd, vma, \ + i, \ + i *ESZ , \ + (i +1 ) * \ +ESZ ); \continue ; \ } \ do_##NAME(vd, vs2, i); \
Signature · 1 line
2.34.2
PATCH 8/9 target/riscv: rvv: Add mask agnostic for vector mask instructions
In reply to ~eopxdFrom: Yueh-Ting (eop) Chen <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 3 +++ target/riscv/vector_helper.c | 13 +++++++++++++ 2 files changed, 16 insertions(+)
target/riscv/insn_trans/trans_rvv.c.inc +3 -0
@@ -3333,6 +3333,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ data = FIELD_DP32(data, VDATA, VM, a->vm); \ data = FIELD_DP32(data, VDATA, LMUL, s->lmul); \ data = FIELD_DP32(data, VDATA, VTA, s->vta); \ + data = FIELD_DP32(data, VDATA, VMA, s->vma); \ tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), \ vreg_ofs(s, 0), vreg_ofs(s, a->rs2), \ cpu_env, s->cfg_ptr->vlen / 8, \
@@ -3371,6 +3372,7 @@ static bool trans_viota_m(DisasContext *s, arg_viota_m *a) data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); static gen_helper_gvec_3_ptr * const fns[4] = { gen_helper_viota_m_b, gen_helper_viota_m_h, gen_helper_viota_m_w, gen_helper_viota_m_d,
@@ -3401,6 +3403,7 @@ static bool trans_vid_v(DisasContext *s, arg_vid_v *a) data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, LMUL, s->lmul); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); static gen_helper_gvec_2_ptr * const fns[4] = { gen_helper_vid_v_b, gen_helper_vid_v_h, gen_helper_vid_v_w, gen_helper_vid_v_d,
target/riscv/vector_helper.c +13 -0
@@ -4895,11 +4895,16 @@ static void vmsetm(void *vd, void *v0, void *vs2, CPURISCVState *env,uint32_t vl = env->vl;uint32_t total_elems =env_archcpu (env)->cfg.vlen;uint32_t vta =vext_vta (desc); +uint32_t vma =vext_vma (desc);int i;bool first_mask_bit = false;for (i = env->vstart; i < vl; i++) {if (!vm && !vext_elem_mask (v0, i)) { +/* set masked-off elements to 1s */ +if (vma) { +vext_set_elem_mask (vd, i,1 ); + }continue ; }/* write a zero to all following active elements */
@@ -4959,11 +4964,15 @@ void HELPER(NAME)(void *vd, void *v0, void *vs2, CPURISCVState *env, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t sum =0 ; \int i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, \ + (i +1 ) * esz); \continue ; \ } \ *((ETYPE *)vd +H (i)) = sum; \
@@ -4991,10 +5000,14 @@ void HELPER(NAME)(void *vd, void *v0, CPURISCVState *env, uint32_t desc) \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \int i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, \ + (i +1 ) * esz); \continue ; \ } \ *((ETYPE *)vd +H (i)) = i; \
Signature · 1 line
2.34.2
PATCH 9/9 target/riscv: rvv: Add mask agnostic for vector permutation instructions
In reply to ~eopxdFrom: Yueh-Ting (eop) Chen <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 1 + target/riscv/vector_helper.c | 34 +++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +1 -0
@@ -3975,6 +3975,7 @@ static bool int_ext_op(DisasContext *s, arg_rmr *a, uint8_t seq) data = FIELD_DP32(data, VDATA, VM, a->vm); data = FIELD_DP32(data, VDATA, VTA, s->vta); + data = FIELD_DP32(data, VDATA, VMA, s->vma); tcg_gen_gvec_3_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), vreg_ofs(s, a->rs2), cpu_env,
target/riscv/vector_helper.c +32 -2
@@ -5037,11 +5037,15 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \target_ulong offset = s1, i_min, i; \ \ i_min =MAX (env->vstart, offset); \for (i = i_min; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, \ + (i +1 ) * esz); \continue ; \ } \ *((ETYPE *)vd +H (i)) = *((ETYPE *)vs2 +H (i - offset)); \
@@ -5067,13 +5071,18 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \target_ulong i_max, i; \ \ i_max =MAX (MIN (s1 < vlmax ? vlmax - s1 :0 , vl), env->vstart); \for (i = env->vstart; i < i_max; ++i) { \ -if (vm ||vext_elem_mask (v0, i)) { \ - *((ETYPE *)vd +H (i)) = *((ETYPE *)vs2 +H (i + s1)); \ +if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, \ + (i +1 ) * esz); \ +continue ; \ } \ + *((ETYPE *)vd +H (i)) = *((ETYPE *)vs2 +H (i + s1)); \ } \ \for (i = i_max; i < vl; ++i) { \
@@ -5104,10 +5113,14 @@ static void vslide1up_##BITWIDTH(void *vd, void *v0, target_ulong s1, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, \ + (i +1 ) * esz); \continue ; \ } \if (i ==0 ) { \
@@ -5150,10 +5163,14 @@ static void vslide1down_##BITWIDTH(void *vd, void *v0, target_ulong s1, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, \ + (i +1 ) * esz); \continue ; \ } \if (i == vl -1 ) { \
@@ -5222,11 +5239,15 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \uint32_t esz =sizeof (TS2 ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint64_t index; \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, \ + (i +1 ) * esz); \continue ; \ } \ index = *((TS1 *)vs1 +HS1 (i)); \
@@ -5263,11 +5284,15 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint64_t index = s1; \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, i * esz, \ + (i +1 ) * esz); \continue ; \ } \if (index >= vlmax) { \
@@ -5349,10 +5374,15 @@ void HELPER(NAME)(void *vd, void *v0, void *vs2, \uint32_t esz =sizeof (ETYPE ); \uint32_t total_elems =vext_get_total_elems (desc, esz); \uint32_t vta =vext_vta (desc); \ +uint32_t vma =vext_vma (desc); \uint32_t i; \ \for (i = env->vstart; i < vl; i++) { \if (!vm && !vext_elem_mask (v0, i)) { \ +/* set masked-off elements to 1s */ \ + vext_set_elems_1s_fns[ctzl (esz)](vd, vma, i, \ + i * esz, \ + (i +1 ) * esz); \continue ; \ } \ *((ETYPE *)vd +HD (i)) = *((DTYPE *)vs2 +HS1 (i)); \
Signature · 1 line
2.34.2