diff options
author | Zhen Wei <zhen.wei@sifive.com> | 2020-02-27 09:36:57 +0800 |
---|---|---|
committer | Chih-Min Chao <chihmin.chao@sifive.com> | 2020-03-09 19:58:54 -0700 |
commit | c949a75893a3c8df98a407d216ee995c82d4db4f (patch) | |
tree | 34a9bebbc9b13bfc50e9dd2827b59ee6fec2eee9 | |
parent | ef5950ea11c4ef97bbe9a025a70950f754b38959 (diff) | |
download | riscv-isa-sim-c949a75893a3c8df98a407d216ee995c82d4db4f.zip riscv-isa-sim-c949a75893a3c8df98a407d216ee995c82d4db4f.tar.gz riscv-isa-sim-c949a75893a3c8df98a407d216ee995c82d4db4f.tar.bz2 |
rvv: enhance --varch to parse string type options
To improve the readability of varch argument and future configuration,
the format of options within varch are changed
from
"v128:e64:s512"
to
"vlen:128,elen:64,slen:512".
-rwxr-xr-x | configure | 4 | ||||
-rw-r--r-- | riscv/processor.cc | 72 | ||||
-rw-r--r-- | riscv/riscv.ac | 4 |
3 files changed, 46 insertions, 34 deletions
@@ -1362,7 +1362,7 @@ Optional Packages: --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-isa=RV64IMAFDC Sets the default RISC-V ISA --with-priv=MSU Sets the default RISC-V privilege modes supported - --with-varch=v128:e64:s128 + --with-varch=vlen:128,elen:64,slen:128 Sets the default vector config Some influential environment variables: @@ -4791,7 +4791,7 @@ _ACEOF else cat >>confdefs.h <<_ACEOF -#define DEFAULT_VARCH "v128:e64:s128" +#define DEFAULT_VARCH "vlen:128,elen:64,slen:128" _ACEOF fi diff --git a/riscv/processor.cc b/riscv/processor.cc index 66901a0..89974b7 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -74,17 +74,27 @@ static void bad_varch_string(const char* varch, const char *message) abort(); } -static int parse_varch(std::string &str){ - int val = 0; - if(!str.empty()){ - std::string sval = str.substr(1); - val = std::stoi(sval); - if ((val & (val - 1)) != 0) // val should be power of 2 - bad_varch_string(str.c_str(), "must be a power of 2"); - }else{ - bad_varch_string(str.c_str(), "must not be empty"); +static std::string get_string_token(std::string str, const char delimiter, size_t& pos) +{ + size_t _pos = pos; + while (pos < str.length() && str[pos] != delimiter) ++pos; + return str.substr(_pos, pos - _pos); +} + +static int get_int_token(std::string str, const char delimiter, size_t& pos) +{ + size_t _pos = pos; + while (pos < str.length() && str[pos] != delimiter) { + if (!isdigit(str[pos])) + bad_varch_string(str.c_str(), "Unsupported value"); // An integer is expected + ++pos; } - return val; + return (pos == _pos) ? 0 : stoi(str.substr(_pos, pos - _pos)); +} + +static bool check_pow2(int val) +{ + return ((val & (val - 1))) == 0; } void processor_t::parse_varch_string(const char* s) @@ -93,30 +103,32 @@ void processor_t::parse_varch_string(const char* s) for (const char *r = s; *r; r++) str += std::tolower(*r); - std::string delimiter = ":"; - size_t pos = 0; + size_t len = str.length(); int vlen = 0; int elen = 0; int slen = 0; - std::string token; - while (!str.empty() && token != str) { - pos = str.find(delimiter); - if (pos == std::string::npos){ - token = str; - }else{ - token = str.substr(0, pos); - } - if (token[0] == 'v'){ - vlen = parse_varch(token); - }else if (token[0] == 'e'){ - elen = parse_varch(token); - }else if (token[0] == 's'){ - slen = parse_varch(token); - }else{ - bad_varch_string(str.c_str(), "Unsupported token"); - } - str.erase(0, pos + delimiter.length()); + + while (pos < len) { + std::string attr = get_string_token(str, ':', pos); + + ++pos; + + if (attr == "vlen") + vlen = get_int_token(str, ',', pos); + else if (attr == "slen") + slen = get_int_token(str, ',', pos); + else if (attr == "elen") + elen = get_int_token(str, ',', pos); + else + bad_varch_string(s, "Unsupported token"); + + ++pos; + } + + // The integer should be the power of 2 + if (!check_pow2(vlen) || !check_pow2(elen) || !check_pow2(slen)){ + bad_varch_string(s, "The integer value should be the power of 2"); } /* Vector spec requirements. */ diff --git a/riscv/riscv.ac b/riscv/riscv.ac index fc45732..22d0d3a 100644 --- a/riscv/riscv.ac +++ b/riscv/riscv.ac @@ -13,10 +13,10 @@ AC_ARG_WITH(priv, AC_DEFINE_UNQUOTED([DEFAULT_PRIV], "MSU", [Default value for --priv switch])) AC_ARG_WITH(varch, - [AS_HELP_STRING([--with-varch=v128:e64:s128], + [AS_HELP_STRING([--with-varch=vlen:128,elen:64,slen:128], [Sets the default vector config])], AC_DEFINE_UNQUOTED([DEFAULT_VARCH], "$withval", [Default value for --varch switch]), - AC_DEFINE_UNQUOTED([DEFAULT_VARCH], "v128:e64:s128", [Default value for --varch switch])) + AC_DEFINE_UNQUOTED([DEFAULT_VARCH], "vlen:128,elen:64,slen:128", [Default value for --varch switch])) AC_SEARCH_LIBS([dlopen], [dl dld], [], [ |