Skip to content

Commit 416b31a

Browse files
committed
Add support for extension versions
1 parent 51ff62c commit 416b31a

File tree

5 files changed

+91
-19
lines changed

5 files changed

+91
-19
lines changed

src/RevFeature.cc

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//
1010

1111
#include "RevFeature.h"
12+
#include <cctype>
1213
#include <cstring>
1314
#include <string_view>
1415
#include <utility>
@@ -46,32 +47,35 @@ bool RevFeature::ParseMachineModel() {
4647
///< By using a canonical ordering, the extensions' presence can be tested
4748
///< in linear time complexity of the table and the string. Some of the
4849
///< extensions imply other extensions, so the extension flags are ORed.
50+
///<
51+
///< The second and third values are the major version range that Rev supports.
52+
///<
4953
// clang-format off
50-
static constexpr std::pair<std::string_view, uint32_t> table[] = {
51-
{ "I", RV_I },
52-
{ "E", RV_E },
53-
{ "M", RV_M },
54-
{ "A", RV_A },
55-
{ "F", RV_F | RV_ZICSR },
56-
{ "D", RV_D | RV_F | RV_ZICSR },
57-
{ "G", RV_I | RV_M | RV_A | RV_F | RV_D | RV_ZICSR | RV_ZIFENCEI },
58-
{ "Q", RV_Q | RV_D | RV_F | RV_ZICSR },
59-
{ "C", RV_C },
60-
{ "P", RV_P },
61-
{ "V", RV_V | RV_D | RV_F | RV_ZICSR },
62-
{ "H", RV_H },
63-
{ "Zicsr", RV_ZICSR },
64-
{ "Zifencei", RV_ZIFENCEI },
65-
{ "Ztso", RV_ZTSO },
66-
{ "Zfa", RV_ZFA | RV_F | RV_ZICSR },
67-
{ "Zicbom", RV_ZICBOM },
54+
static constexpr std::tuple<std::string_view, uint32_t, uint32_t, uint32_t> table[] = {
55+
{ "I", 1, -1, RV_I },
56+
{ "E", 1, -1, RV_E },
57+
{ "M", 1, -1, RV_M },
58+
{ "A", 1, -1, RV_A },
59+
{ "F", 1, -1, RV_F | RV_ZICSR },
60+
{ "D", 1, -1, RV_D | RV_F | RV_ZICSR },
61+
{ "G", 1, -1, RV_I | RV_M | RV_A | RV_F | RV_D | RV_ZICSR | RV_ZIFENCEI },
62+
{ "Q", 1, -1, RV_Q | RV_D | RV_F | RV_ZICSR },
63+
{ "C", 1, -1, RV_C },
64+
{ "P", 1, -1, RV_P },
65+
{ "V", 1, -1, RV_V | RV_D | RV_F | RV_ZICSR },
66+
{ "H", 1, -1, RV_H },
67+
{ "Zicsr", 1, -1, RV_ZICSR },
68+
{ "Zifencei", 1, -1, RV_ZIFENCEI },
69+
{ "Ztso", 1, -1, RV_ZTSO },
70+
{ "Zfa", 1, -1, RV_ZFA | RV_F | RV_ZICSR },
71+
{ "Zicbom", 1, -1, RV_ZICBOM },
6872
};
6973
// clang-format on
7074

7175
// -- step 2: parse all the features
7276
// Note: Extension strings, if present, must appear in the order listed in the table above.
7377
if( *mac ) {
74-
for( const auto& [ext, flags] : table ) {
78+
for( const auto& [ext, minimumVersion, maximumVersion, flags] : table ) {
7579
// Look for an architecture string matching the current extension
7680
if( !strncasecmp( mac, ext.data(), ext.size() ) ) {
7781

@@ -81,6 +85,20 @@ bool RevFeature::ParseMachineModel() {
8185
// Move past the currently matching extension
8286
mac += ext.size();
8387

88+
// Optional version string follows extension
89+
unsigned long majorVersion = 2, minorVersion = 0;
90+
if( isdigit( *mac ) ) {
91+
majorVersion = strtoul( mac, const_cast<char**>( &mac ), 10 );
92+
if( tolower( *mac ) == 'p' && isdigit( *++mac ) )
93+
minorVersion = strtoul( mac, const_cast<char**>( &mac ), 10 );
94+
}
95+
96+
if( majorVersion < minimumVersion || majorVersion > maximumVersion ) {
97+
output->fatal(
98+
CALL_INFO, -1, "Error: Version %lu.%lu of %s extension is not supported\n", majorVersion, minorVersion, ext.data()
99+
);
100+
}
101+
84102
// Skip underscore separators
85103
while( *mac == '_' )
86104
++mac;

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ endif()
204204
endmacro()
205205

206206
# add_rev_test(test_name test_dir timeout labels)
207+
add_rev_test(EXT_VERSION ext_version 20 "rv64")
207208
add_rev_test(EX1 ex1 30 "memh;rv32")
208209
add_rev_test(EX2 ex2 30 "memh;rv64")
209210
add_rev_test(EX3 ex3 30 "memh;rv32")

test/ext_version/Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Makefile
3+
#
4+
# makefile: ext_version
5+
#
6+
# Copyright (C) 2017-2024 Tactical Computing Laboratories, LLC
7+
# All Rights Reserved
8+
9+
#
10+
# See LICENSE in the top level directory for licensing details
11+
#
12+
13+
.PHONY: src
14+
15+
EXAMPLE=ext_version
16+
CC=${RVCC}
17+
ARCH=rv64imafdc
18+
19+
all: $(EXAMPLE).exe
20+
$(EXAMPLE).exe: $(EXAMPLE).c
21+
$(CC) -march=$(ARCH) -O3 -static -o $(EXAMPLE).exe $(EXAMPLE).c
22+
clean:
23+
rm -Rf $(EXAMPLE).exe
24+
25+
#-- EOF

test/ext_version/ext_version.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int main( void ) {
2+
return 0;
3+
}

test/ext_version/run_ext_version.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
set -e
3+
4+
make clean
5+
make
6+
7+
# Unknown extension
8+
sst --add-lib-path=../../build/src/ ../rev-model-options-config.py -- --program "ext_version.exe" --args "one" --enableMemH=0 --machine="[CORES:RV64XGC]" 2>&1 | grep -q 'Error: failed to parse the machine model: RV64XGC'
9+
10+
# Out of order extension
11+
sst --add-lib-path=../../build/src/ ../rev-model-options-config.py -- --program "ext_version.exe" --args "one" --enableMemH=0 --machine="[CORES:RV64GVC]" 2>&1 | grep -q 'Error: failed to parse the machine model: RV64GVC'
12+
13+
# Incomplete version string
14+
sst --add-lib-path=../../build/src/ ../rev-model-options-config.py -- --program "ext_version.exe" --args "one" --enableMemH=0 --machine="[CORES:RV64XGC2P]" 2>&1 | grep -q 'Error: failed to parse the machine model: RV64XGC2P'
15+
16+
# Unsupported version
17+
sst --add-lib-path=../../build/src/ ../rev-model-options-config.py -- --program "ext_version.exe" --args "one" --enableMemH=0 --machine="[CORES:RV64GCV0p7]" 2>&1 | grep -q 'Error: Version 0.7 of V extension is not supported'
18+
19+
# Supported version
20+
sst --add-lib-path=../../build/src/ ../rev-model-options-config.py -- --program "ext_version.exe" --args "one" --enableMemH=0 --machine="[CORES:rv64i2p0m2a2p0fd2p0c]" 2>&1 | grep -q 'Simulation is complete'
21+
22+
# Supported version
23+
sst --add-lib-path=../../build/src/ ../rev-model-options-config.py -- --program "ext_version.exe" --args "one" --enableMemH=0 --machine="[CORES:rv64i2p0m2a2p0fd2p0c2_p]" 2>&1 | grep -q 'Simulation is complete'
24+
25+
echo 'Simulation is complete'

0 commit comments

Comments
 (0)