Skip to content

Commit f03e97c

Browse files
authored
Merge pull request #1701 from riscv-software-src/zvl_zve
Correctly determine vector capability from v/zve/zvl ISA strings, remove --varch
2 parents 3d4027a + c790f73 commit f03e97c

File tree

15 files changed

+93
-119
lines changed

15 files changed

+93
-119
lines changed

.github/workflows/debug-smoke.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: |
4848
git clone --recurse-submodules https://github.com/riscv-software-src/riscv-tests.git
4949
cd riscv-tests
50-
git checkout bd0a19c136927eaa3b7296a591a896c141affb6b
50+
git checkout 00ab5f0dd4cf56b5a0551bc5adedf60c765d0c66
5151
5252
- name: Run Tests
5353
run: |

config.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
/* Default value for --priv switch */
1313
#undef DEFAULT_PRIV
1414

15-
/* Default value for --varch switch */
16-
#undef DEFAULT_VARCH
17-
1815
/* Define if subproject MCPPBS_SPROJ_NORM is enabled */
1916
#undef DISASM_ENABLED
2017

configure

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,6 @@ with_boost_asio
739739
with_boost_regex
740740
with_isa
741741
with_priv
742-
with_varch
743742
with_target
744743
enable_dual_endian
745744
'
@@ -1407,8 +1406,6 @@ Optional Packages:
14071406
--with-isa=RV64IMAFDC_zicntr_zihpm
14081407
Sets the default RISC-V ISA
14091408
--with-priv=MSU Sets the default RISC-V privilege modes supported
1410-
--with-varch=vlen:128,elen:64
1411-
Sets the default vector config
14121409
--with-target=riscv64-unknown-elf
14131410
Sets the default target config
14141411
@@ -6593,20 +6590,6 @@ fi
65936590

65946591

65956592

6596-
# Check whether --with-varch was given.
6597-
if test ${with_varch+y}
6598-
then :
6599-
withval=$with_varch;
6600-
printf "%s\n" "#define DEFAULT_VARCH \"$withval\"" >>confdefs.h
6601-
6602-
else $as_nop
6603-
6604-
printf "%s\n" "#define DEFAULT_VARCH \"vlen:128,elen:64\"" >>confdefs.h
6605-
6606-
fi
6607-
6608-
6609-
66106593
# Check whether --with-target was given.
66116594
if test ${with_target+y}
66126595
then :

disasm/disasm.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ void disassembler_t::add_instructions(const isa_parser_t* isa)
14551455
DISASM_INSN("cm.jalt", cm_jalt, 0, {&rvcm_jt_index});
14561456
}
14571457

1458-
if (isa->extension_enabled('V')) {
1458+
if (isa->has_any_vector()) {
14591459
DISASM_INSN("vsetivli", vsetivli, 0, {&xrd, &zimm5, &v_vtype});
14601460
DISASM_INSN("vsetvli", vsetvli, 0, {&xrd, &xrs1, &v_vtype});
14611461
DEFINE_RTYPE(vsetvl);

disasm/isa_parser.cc

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ isa_parser_t::isa_parser_t(const char* str, const char *priv)
3838
else
3939
bad_isa_string(str, "ISA strings must begin with RV32 or RV64");
4040

41+
vlen = 0;
42+
elen = 0;
43+
zvf = false;
44+
zvd = false;
45+
4146
switch (isa_string[4]) {
4247
case 'g':
4348
// G = IMAFD_Zicsr_Zifencei, but Spike includes the latter two
@@ -70,7 +75,8 @@ isa_parser_t::isa_parser_t(const char* str, const char *priv)
7075
}
7176

7277
switch (*p) {
73-
case 'v': // even rv32iv implies double float
78+
case 'v': vlen = 128; elen = 64; zvf = true; zvd = true;
79+
// even rv32iv implies double float
7480
case 'q': extension_table['D'] = true;
7581
// Fall through
7682
case 'd': extension_table['F'] = true;
@@ -95,9 +101,6 @@ isa_parser_t::isa_parser_t(const char* str, const char *priv)
95101
if (ext_str == "zfh")
96102
extension_table[EXT_ZFH] = true;
97103
} else if (ext_str == "zvfh" || ext_str == "zvfhmin") {
98-
if (!extension_table['V'])
99-
bad_isa_string(str, ("'" + ext_str + "' extension requires 'V'").c_str());
100-
101104
extension_table[EXT_ZVFHMIN] = true;
102105

103106
if (ext_str == "zvfh") {
@@ -314,6 +317,35 @@ isa_parser_t::isa_parser_t(const char* str, const char *priv)
314317
extension_table[EXT_ZICFILP] = true;
315318
} else if (ext_str == "zicfiss") {
316319
extension_table[EXT_ZICFISS] = true;
320+
} else if (ext_str.substr(0, 3) == "zvl") {
321+
reg_t new_vlen;
322+
try {
323+
new_vlen = std::stol(ext_str.substr(3, ext_str.size() - 4));
324+
} catch (std::logic_error& e) {
325+
new_vlen = 0;
326+
}
327+
if ((new_vlen & (new_vlen - 1)) != 0 || new_vlen < 32)
328+
bad_isa_string(str, ("Invalid Zvl string: " + ext_str).c_str());
329+
vlen = std::max(vlen, new_vlen);
330+
} else if (ext_str.substr(0, 3) == "zve") {
331+
reg_t new_elen;
332+
try {
333+
new_elen = std::stol(ext_str.substr(3, ext_str.size() - 4));
334+
} catch (std::logic_error& e) {
335+
new_elen = 0;
336+
}
337+
if (ext_str.substr(5) == "d") {
338+
zvd |= true; zvf |= true;
339+
} else if (ext_str.substr(5) == "f") {
340+
zvf |= true;
341+
} else if (ext_str.substr(5) == "x") {
342+
/* do nothing */
343+
} else {
344+
new_elen = 0;
345+
}
346+
if (new_elen != 32 && new_elen != 64)
347+
bad_isa_string(str, ("Invalid Zve string: " + ext_str).c_str());
348+
elen = std::max(elen, new_elen);
317349
} else if (ext_str[0] == 'x') {
318350
extension_table['X'] = true;
319351
if (ext_str.size() == 1) {
@@ -424,6 +456,31 @@ isa_parser_t::isa_parser_t(const char* str, const char *priv)
424456
"extensions are incompatible with WORDS_BIGENDIAN setups.");
425457
}
426458
#endif
459+
460+
if (vlen > 4096) {
461+
bad_isa_string(str, "Spike does not currently support VLEN > 4096b");
462+
}
463+
464+
if ((vlen != 0) ^ (elen != 0)) {
465+
bad_isa_string(str, "Invalid Zvl/Zve configuration");
466+
}
467+
468+
if (extension_table[EXT_ZVFHMIN] && (vlen == 0 || elen == 0 || !zvf)) {
469+
bad_isa_string(str, "'Zvfhmin' extension requires Zve32f");
470+
}
471+
472+
if (extension_table[EXT_ZVFH] && (vlen == 0 || elen == 0 || !zvf || !extension_table[EXT_ZVFHMIN])) {
473+
bad_isa_string(str, "'Zvfh' extension requires Zve32f and 'Zvfhmin'");
474+
}
475+
476+
if (zvd && !extension_table['D'] && elen < 64) {
477+
bad_isa_string(str, "'ZveXXd' extension requires D");
478+
}
479+
480+
if (zvf && !extension_table['F']) {
481+
bad_isa_string(str, "'ZveXXf' extension requires F");
482+
}
483+
427484
std::string lowercase = strtolower(priv);
428485
bool user = false, supervisor = false;
429486

riscv/cfg.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ cfg_t::cfg_t()
3535
bootargs = nullptr;
3636
isa = DEFAULT_ISA;
3737
priv = DEFAULT_PRIV;
38-
varch = DEFAULT_VARCH;
3938
misaligned = false;
4039
endianness = endianness_little;
4140
pmpregions = 16;

riscv/cfg.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class cfg_t
6767
const char * bootargs;
6868
const char * isa;
6969
const char * priv;
70-
const char * varch;
7170
bool misaligned;
7271
endianness_t endianness;
7372
reg_t pmpregions;

riscv/csrs.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ base_status_csr_t::base_status_csr_t(processor_t* const proc, const reg_t addr):
411411
reg_t base_status_csr_t::compute_sstatus_write_mask() const noexcept {
412412
// If a configuration has FS bits, they will always be accessible no
413413
// matter the state of misa.
414-
const bool has_fs = (proc->extension_enabled('S') || proc->extension_enabled('F')
415-
|| proc->extension_enabled('V')) && !proc->extension_enabled(EXT_ZFINX);
416-
const bool has_vs = proc->extension_enabled('V');
414+
const bool has_fs = (proc->extension_enabled('S') || proc->extension_enabled('F')) && !proc->extension_enabled(EXT_ZFINX);
415+
// Implementations w/o V may still have mstatus.vs,
416+
const bool has_vs = proc->any_vector_extensions();
417417
return 0
418418
| (proc->extension_enabled('S') ? (SSTATUS_SIE | SSTATUS_SPIE | SSTATUS_SPP) : 0)
419419
| (has_page ? (SSTATUS_SUM | SSTATUS_MXR) : 0)
@@ -1429,8 +1429,6 @@ vector_csr_t::vector_csr_t(processor_t* const proc, const reg_t addr, const reg_
14291429

14301430
void vector_csr_t::verify_permissions(insn_t insn, bool write) const {
14311431
require_vector_vs;
1432-
if (!proc->extension_enabled('V'))
1433-
throw trap_illegal_instruction(insn.bits());
14341432
basic_csr_t::verify_permissions(insn, write);
14351433
}
14361434

@@ -1452,8 +1450,6 @@ vxsat_csr_t::vxsat_csr_t(processor_t* const proc, const reg_t addr):
14521450

14531451
void vxsat_csr_t::verify_permissions(insn_t insn, bool write) const {
14541452
require_vector_vs;
1455-
if (!proc->extension_enabled('V'))
1456-
throw trap_illegal_instruction(insn.bits());
14571453
masked_csr_t::verify_permissions(insn, write);
14581454
}
14591455

riscv/decode_macros.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ static inline bool is_aligned(const unsigned val, const unsigned pos)
171171
#define require_vector(alu) \
172172
do { \
173173
require_vector_vs; \
174-
require_extension('V'); \
175174
require(!P.VU.vill); \
176175
if (alu && !P.VU.vstart_alu) \
177176
require(P.VU.vstart->read() == 0); \
@@ -181,7 +180,6 @@ static inline bool is_aligned(const unsigned val, const unsigned pos)
181180
#define require_vector_novtype(is_log) \
182181
do { \
183182
require_vector_vs; \
184-
require_extension('V'); \
185183
if (is_log) \
186184
WRITE_VSTATUS; \
187185
dirty_vs_state; \

riscv/isa_parser.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,17 @@ class isa_parser_t {
102102
unsigned get_max_xlen() const { return max_xlen; }
103103
reg_t get_max_isa() const { return max_isa; }
104104
std::string get_isa_string() const { return isa_string; }
105+
reg_t get_vlen() const { return vlen; }
106+
reg_t get_elen() const { return elen; }
107+
bool get_zvf() const { return zvf; }
108+
bool get_zvd() const { return zvd; }
105109
bool extension_enabled(unsigned char ext) const {
106110
return extension_enabled(isa_extension_t(ext));
107111
}
108112
bool extension_enabled(isa_extension_t ext) const {
109113
return extension_table[ext];
110114
}
115+
bool has_any_vector() const { return vlen > 0; }
111116

112117
std::bitset<NUM_ISA_EXTENSIONS> get_extension_table() const { return extension_table; }
113118

@@ -116,6 +121,10 @@ class isa_parser_t {
116121
protected:
117122
unsigned max_xlen;
118123
reg_t max_isa;
124+
reg_t vlen;
125+
reg_t elen;
126+
bool zvf;
127+
bool zvd;
119128
std::bitset<NUM_ISA_EXTENSIONS> extension_table;
120129
std::string isa_string;
121130
std::set<std::string> extensions;

0 commit comments

Comments
 (0)