Skip to content

Commit 6bf9161

Browse files
LIU Zhiweialistair23
authored andcommitted
target/riscv: configure and turn on vector extension from command line
Vector extension is default off. The only way to use vector extension is 1. use cpu rv32 or rv64 2. turn on it by command line "-cpu rv64,x-v=true,vlen=128,elen=64,vext_spec=v0.7.1". vlen is the vector register length, default value is 128 bit. elen is the max operator size in bits, default value is 64 bit. vext_spec is the vector specification version, default value is v0.7.1. These properties can be specified with other values. Signed-off-by: LIU Zhiwei <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
1 parent 31bf42a commit 6bf9161

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

target/riscv/cpu.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,45 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
430430
if (cpu->cfg.ext_h) {
431431
target_misa |= RVH;
432432
}
433+
if (cpu->cfg.ext_v) {
434+
target_misa |= RVV;
435+
if (!is_power_of_2(cpu->cfg.vlen)) {
436+
error_setg(errp,
437+
"Vector extension VLEN must be power of 2");
438+
return;
439+
}
440+
if (cpu->cfg.vlen > RV_VLEN_MAX || cpu->cfg.vlen < 128) {
441+
error_setg(errp,
442+
"Vector extension implementation only supports VLEN "
443+
"in the range [128, %d]", RV_VLEN_MAX);
444+
return;
445+
}
446+
if (!is_power_of_2(cpu->cfg.elen)) {
447+
error_setg(errp,
448+
"Vector extension ELEN must be power of 2");
449+
return;
450+
}
451+
if (cpu->cfg.elen > 64 || cpu->cfg.vlen < 8) {
452+
error_setg(errp,
453+
"Vector extension implementation only supports ELEN "
454+
"in the range [8, 64]");
455+
return;
456+
}
457+
if (cpu->cfg.vext_spec) {
458+
if (!g_strcmp0(cpu->cfg.vext_spec, "v0.7.1")) {
459+
vext_version = VEXT_VERSION_0_07_1;
460+
} else {
461+
error_setg(errp,
462+
"Unsupported vector spec version '%s'",
463+
cpu->cfg.vext_spec);
464+
return;
465+
}
466+
} else {
467+
qemu_log("vector verison is not specified, "
468+
"use the default value v0.7.1\n");
469+
}
470+
set_vext_version(env, vext_version);
471+
}
433472

434473
set_misa(env, RVXLEN | target_misa);
435474
}
@@ -469,10 +508,14 @@ static Property riscv_cpu_properties[] = {
469508
DEFINE_PROP_BOOL("u", RISCVCPU, cfg.ext_u, true),
470509
/* This is experimental so mark with 'x-' */
471510
DEFINE_PROP_BOOL("x-h", RISCVCPU, cfg.ext_h, false),
511+
DEFINE_PROP_BOOL("x-v", RISCVCPU, cfg.ext_v, false),
472512
DEFINE_PROP_BOOL("Counters", RISCVCPU, cfg.ext_counters, true),
473513
DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true),
474514
DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true),
475515
DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
516+
DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
517+
DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),
518+
DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
476519
DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
477520
DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
478521
DEFINE_PROP_END_OF_LIST(),

target/riscv/cpu.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ typedef struct CPURISCVState CPURISCVState;
9292

9393
#include "pmp.h"
9494

95-
#define RV_VLEN_MAX 512
95+
#define RV_VLEN_MAX 256
9696

9797
FIELD(VTYPE, VLMUL, 0, 2)
9898
FIELD(VTYPE, VSEW, 2, 3)
@@ -279,12 +279,14 @@ typedef struct RISCVCPU {
279279
bool ext_s;
280280
bool ext_u;
281281
bool ext_h;
282+
bool ext_v;
282283
bool ext_counters;
283284
bool ext_ifencei;
284285
bool ext_icsr;
285286

286287
char *priv_spec;
287288
char *user_spec;
289+
char *vext_spec;
288290
uint16_t vlen;
289291
uint16_t elen;
290292
bool mmu;

0 commit comments

Comments
 (0)