Skip to content

Commit 5625817

Browse files
vliaskovalistair23
authored andcommitted
target/riscv: Add a property to set vill bit on reserved usage of vsetvli instruction
Usage of vsetvli instruction is reserved if VLMAX is changed when vsetvli rs1 and rd arguments are x0. In this case, if the new property is true, only the vill bit will be set. See https://github.com/riscv/riscv-isa-manual/blob/main/src/v-st-ext.adoc#avl-encoding According to the spec, the above use cases are reserved, and "Implementations may set vill in either case." Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2422 Signed-off-by: Vasilis Liaskovitis <[email protected]> Reviewed-by: Daniel Henrique Barboza <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
1 parent a1f44e0 commit 5625817

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

target/riscv/cpu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,6 +2632,7 @@ static const Property riscv_cpu_properties[] = {
26322632
DEFINE_PROP_BOOL("rvv_ta_all_1s", RISCVCPU, cfg.rvv_ta_all_1s, false),
26332633
DEFINE_PROP_BOOL("rvv_ma_all_1s", RISCVCPU, cfg.rvv_ma_all_1s, false),
26342634
DEFINE_PROP_BOOL("rvv_vl_half_avl", RISCVCPU, cfg.rvv_vl_half_avl, false),
2635+
DEFINE_PROP_BOOL("rvv_vsetvl_x0_vill", RISCVCPU, cfg.rvv_vsetvl_x0_vill, false),
26352636

26362637
/*
26372638
* write_misa() is marked as experimental for now so mark

target/riscv/cpu_cfg_fields.h.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ BOOL_FIELD(ext_supm)
114114
BOOL_FIELD(rvv_ta_all_1s)
115115
BOOL_FIELD(rvv_ma_all_1s)
116116
BOOL_FIELD(rvv_vl_half_avl)
117+
BOOL_FIELD(rvv_vsetvl_x0_vill)
117118
/* Named features */
118119
BOOL_FIELD(ext_svade)
119120
BOOL_FIELD(ext_zic64b)

target/riscv/helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ DEF_HELPER_FLAGS_3(hyp_hsv_d, TCG_CALL_NO_WG, void, env, tl, tl)
159159
#endif
160160

161161
/* Vector functions */
162-
DEF_HELPER_3(vsetvl, tl, env, tl, tl)
162+
DEF_HELPER_4(vsetvl, tl, env, tl, tl, tl)
163163
DEF_HELPER_5(vle8_v, void, ptr, ptr, tl, env, i32)
164164
DEF_HELPER_5(vle16_v, void, ptr, ptr, tl, env, i32)
165165
DEF_HELPER_5(vle32_v, void, ptr, ptr, tl, env, i32)

target/riscv/insn_trans/trans_rvv.c.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2)
202202
s1 = get_gpr(s, rs1, EXT_ZERO);
203203
}
204204

205-
gen_helper_vsetvl(dst, tcg_env, s1, s2);
205+
gen_helper_vsetvl(dst, tcg_env, s1, s2, tcg_constant_tl((int) (rd == 0 && rs1 == 0)));
206206
gen_set_gpr(s, rd, dst);
207207
finalize_rvv_inst(s);
208208

@@ -222,7 +222,7 @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2)
222222

223223
dst = dest_gpr(s, rd);
224224

225-
gen_helper_vsetvl(dst, tcg_env, s1, s2);
225+
gen_helper_vsetvl(dst, tcg_env, s1, s2, tcg_constant_tl(0));
226226
gen_set_gpr(s, rd, dst);
227227
finalize_rvv_inst(s);
228228
gen_update_pc(s, s->cur_insn_len);

target/riscv/vector_helper.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <math.h>
3636

3737
target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,
38-
target_ulong s2)
38+
target_ulong s2, target_ulong x0)
3939
{
4040
int vlmax, vl;
4141
RISCVCPU *cpu = env_archcpu(env);
@@ -83,6 +83,16 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,
8383
} else {
8484
vl = vlmax;
8585
}
86+
87+
if (cpu->cfg.rvv_vsetvl_x0_vill && x0 && (env->vl != vl)) {
88+
/* only set vill bit. */
89+
env->vill = 1;
90+
env->vtype = 0;
91+
env->vl = 0;
92+
env->vstart = 0;
93+
return 0;
94+
}
95+
8696
env->vl = vl;
8797
env->vtype = s2;
8898
env->vstart = 0;

0 commit comments

Comments
 (0)