diff --git a/CMakeLists.txt b/CMakeLists.txt index 765aafc..86197b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,13 +53,9 @@ if(WITH_TCC) list(APPEND LIB_SOURCES ${TCC_GEN_SOURCES}) endif() -if(TARGET RapidJSON OR TARGET RapidJSON::RapidJSON) +if(TARGET yaml-cpp::yaml-cpp) list(APPEND LIB_SOURCES src/iss/plugin/cycle_estimate.cpp - ) -endif() -if(TARGET jsoncpp::jsoncpp) - list(APPEND LIB_SOURCES src/iss/plugin/instruction_count.cpp ) endif() @@ -84,11 +80,9 @@ if(NOT (DBT_CORE_DEFS STREQUAL DBT_CORE_DEFS-NOTFOUND)) endif() target_link_libraries(${PROJECT_NAME} PUBLIC elfio::elfio softfloat scc-util Boost::coroutine) -if(TARGET jsoncpp::jsoncpp) - target_link_libraries(${PROJECT_NAME} PUBLIC jsoncpp::jsoncpp) -endif() -if(TARGET RapidJSON) - target_link_libraries(${PROJECT_NAME} PUBLIC RapidJSON) +if(TARGET yaml-cpp::yaml-cpp) + target_compile_definitions(${PROJECT_NAME} PUBLIC WITH_PLUGINS) + target_link_libraries(${PROJECT_NAME} PUBLIC yaml-cpp::yaml-cpp) endif() if(WITH_LLVM) diff --git a/TGC_C_instr.yaml b/TGC5C_instr.yaml similarity index 90% rename from TGC_C_instr.yaml rename to TGC5C_instr.yaml index e28cb64..8f14fe9 100644 --- a/TGC_C_instr.yaml +++ b/TGC5C_instr.yaml @@ -1,297 +1,297 @@ RV32I: - - LUI: + LUI: encoding: 0b00000000000000000000000000110111 mask: 0b00000000000000000000000001111111 size: 32 branch: false delay: 1 - - AUIPC: + AUIPC: encoding: 0b00000000000000000000000000010111 mask: 0b00000000000000000000000001111111 size: 32 branch: false delay: 1 - - JAL: + JAL: encoding: 0b00000000000000000000000001101111 mask: 0b00000000000000000000000001111111 size: 32 branch: true delay: 1 - - JALR: + JALR: encoding: 0b00000000000000000000000001100111 mask: 0b00000000000000000111000001111111 size: 32 branch: true - delay: 1 - - BEQ: + delay: [1,1] + BEQ: encoding: 0b00000000000000000000000001100011 mask: 0b00000000000000000111000001111111 size: 32 branch: true - delay: 1 - - BNE: + delay: [1,1] + BNE: encoding: 0b00000000000000000001000001100011 mask: 0b00000000000000000111000001111111 size: 32 branch: true - delay: 1 - - BLT: + delay: [1,1] + BLT: encoding: 0b00000000000000000100000001100011 mask: 0b00000000000000000111000001111111 size: 32 branch: true - delay: 1 - - BGE: + delay: [1,1] + BGE: encoding: 0b00000000000000000101000001100011 mask: 0b00000000000000000111000001111111 size: 32 branch: true - delay: 1 - - BLTU: + delay: [1,1] + BLTU: encoding: 0b00000000000000000110000001100011 mask: 0b00000000000000000111000001111111 size: 32 branch: true - delay: 1 - - BGEU: + delay: [1,1] + BGEU: encoding: 0b00000000000000000111000001100011 mask: 0b00000000000000000111000001111111 size: 32 branch: true - delay: 1 - - LB: + delay: [1,1] + LB: encoding: 0b00000000000000000000000000000011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - LH: + LH: encoding: 0b00000000000000000001000000000011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - LW: + LW: encoding: 0b00000000000000000010000000000011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - LBU: + LBU: encoding: 0b00000000000000000100000000000011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - LHU: + LHU: encoding: 0b00000000000000000101000000000011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - SB: + SB: encoding: 0b00000000000000000000000000100011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - SH: + SH: encoding: 0b00000000000000000001000000100011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - SW: + SW: encoding: 0b00000000000000000010000000100011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - ADDI: + ADDI: encoding: 0b00000000000000000000000000010011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - SLTI: + SLTI: encoding: 0b00000000000000000010000000010011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - SLTIU: + SLTIU: encoding: 0b00000000000000000011000000010011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - XORI: + XORI: encoding: 0b00000000000000000100000000010011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - ORI: + ORI: encoding: 0b00000000000000000110000000010011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - ANDI: + ANDI: encoding: 0b00000000000000000111000000010011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - SLLI: + SLLI: encoding: 0b00000000000000000001000000010011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - SRLI: + SRLI: encoding: 0b00000000000000000101000000010011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - SRAI: + SRAI: encoding: 0b01000000000000000101000000010011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - ADD: + ADD: encoding: 0b00000000000000000000000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - SUB: + SUB: encoding: 0b01000000000000000000000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - SLL: + SLL: encoding: 0b00000000000000000001000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - SLT: + SLT: encoding: 0b00000000000000000010000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - SLTU: + SLTU: encoding: 0b00000000000000000011000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - XOR: + XOR: encoding: 0b00000000000000000100000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - SRL: + SRL: encoding: 0b00000000000000000101000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - SRA: + SRA: encoding: 0b01000000000000000101000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - OR: + OR: encoding: 0b00000000000000000110000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - AND: + AND: encoding: 0b00000000000000000111000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - FENCE: + FENCE: encoding: 0b00000000000000000000000000001111 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - ECALL: + ECALL: encoding: 0b00000000000000000000000001110011 mask: 0b11111111111111111111111111111111 size: 32 branch: false delay: 1 - - EBREAK: + EBREAK: encoding: 0b00000000000100000000000001110011 mask: 0b11111111111111111111111111111111 size: 32 branch: false delay: 1 - - MRET: + MRET: encoding: 0b00110000001000000000000001110011 mask: 0b11111111111111111111111111111111 attributes: [[name:no_cont]] size: 32 branch: false delay: 1 - - WFI: + WFI: encoding: 0b00010000010100000000000001110011 mask: 0b11111111111111111111111111111111 size: 32 branch: false delay: 1 Zicsr: - - CSRRW: + CSRRW: encoding: 0b00000000000000000001000001110011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - CSRRS: + CSRRS: encoding: 0b00000000000000000010000001110011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - CSRRC: + CSRRC: encoding: 0b00000000000000000011000001110011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - CSRRWI: + CSRRWI: encoding: 0b00000000000000000101000001110011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - CSRRSI: + CSRRSI: encoding: 0b00000000000000000110000001110011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 - - CSRRCI: + CSRRCI: encoding: 0b00000000000000000111000001110011 mask: 0b00000000000000000111000001111111 size: 32 branch: false delay: 1 Zifencei: - - FENCE_I: + FENCE_I: encoding: 0b00000000000000000001000000001111 mask: 0b00000000000000000111000001111111 attributes: [[name:flush]] @@ -299,218 +299,231 @@ Zifencei: branch: false delay: 1 RV32M: - - MUL: + MUL: encoding: 0b00000010000000000000000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - MULH: + MULH: encoding: 0b00000010000000000001000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - MULHSU: + MULHSU: encoding: 0b00000010000000000010000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - MULHU: + MULHU: encoding: 0b00000010000000000011000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - DIV: + DIV: encoding: 0b00000010000000000100000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - DIVU: + DIVU: encoding: 0b00000010000000000101000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - REM: + REM: encoding: 0b00000010000000000110000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 - - REMU: + REMU: encoding: 0b00000010000000000111000000110011 mask: 0b11111110000000000111000001111111 size: 32 branch: false delay: 1 RV32IC: - - CADDI4SPN: + C__ADDI4SPN: encoding: 0b0000000000000000 mask: 0b1110000000000011 size: 16 branch: false delay: 1 - - CLW: + C__LW: encoding: 0b0100000000000000 mask: 0b1110000000000011 size: 16 branch: false delay: 1 - - CSW: + C__SW: encoding: 0b1100000000000000 mask: 0b1110000000000011 size: 16 branch: false delay: 1 - - CADDI: + C__ADDI: encoding: 0b0000000000000001 mask: 0b1110000000000011 size: 16 branch: false delay: 1 - - CNOP: + C__NOP: encoding: 0b0000000000000001 mask: 0b1110111110000011 size: 16 branch: false delay: 1 - - CJAL: + C__JAL: encoding: 0b0010000000000001 mask: 0b1110000000000011 size: 16 branch: true delay: 1 - - CLI: + C__LI: encoding: 0b0100000000000001 mask: 0b1110000000000011 size: 16 branch: false delay: 1 - - CLUI: + C__LUI: encoding: 0b0110000000000001 mask: 0b1110000000000011 size: 16 branch: false delay: 1 - - CADDI16SP: + C__ADDI16SP: encoding: 0b0110000100000001 mask: 0b1110111110000011 size: 16 branch: false delay: 1 - - CSRLI: + __reserved_clui: + encoding: 0b0110000000000001 + mask: 0b1111000001111111 + size: 16 + branch: false + delay: 1 + C__SRLI: encoding: 0b1000000000000001 mask: 0b1111110000000011 size: 16 branch: false delay: 1 - - CSRAI: + C__SRAI: encoding: 0b1000010000000001 mask: 0b1111110000000011 size: 16 branch: false delay: 1 - - CANDI: + C__ANDI: encoding: 0b1000100000000001 mask: 0b1110110000000011 size: 16 branch: false delay: 1 - - CSUB: + C__SUB: encoding: 0b1000110000000001 mask: 0b1111110001100011 size: 16 branch: false delay: 1 - - CXOR: + C__XOR: encoding: 0b1000110000100001 mask: 0b1111110001100011 size: 16 branch: false delay: 1 - - COR: + C__OR: encoding: 0b1000110001000001 mask: 0b1111110001100011 size: 16 branch: false delay: 1 - - CAND: + C__AND: encoding: 0b1000110001100001 mask: 0b1111110001100011 size: 16 branch: false delay: 1 - - CJ: + C__J: encoding: 0b1010000000000001 mask: 0b1110000000000011 size: 16 branch: true delay: 1 - - CBEQZ: + C__BEQZ: encoding: 0b1100000000000001 mask: 0b1110000000000011 size: 16 branch: true - delay: 1 - - CBNEZ: + delay: [1,1] + C__BNEZ: encoding: 0b1110000000000001 mask: 0b1110000000000011 size: 16 branch: true - delay: 1 - - CSLLI: + delay: [1,1] + C__SLLI: encoding: 0b0000000000000010 mask: 0b1111000000000011 + attributes: [[name:enable, value:1]] size: 16 branch: false delay: 1 - - CLWSP: + C__LWSP: encoding: 0b0100000000000010 mask: 0b1110000000000011 size: 16 branch: false delay: 1 - - CMV: + C__MV: encoding: 0b1000000000000010 mask: 0b1111000000000011 size: 16 branch: false delay: 1 - - CJR: + C__JR: encoding: 0b1000000000000010 mask: 0b1111000001111111 size: 16 branch: true delay: 1 - - CADD: + __reserved_cmv: + encoding: 0b1000000000000010 + mask: 0b1111111111111111 + size: 16 + branch: false + delay: 1 + C__ADD: encoding: 0b1001000000000010 mask: 0b1111000000000011 size: 16 branch: false delay: 1 - - CJALR: + C__JALR: encoding: 0b1001000000000010 mask: 0b1111000001111111 size: 16 branch: true delay: 1 - - CEBREAK: + C__EBREAK: encoding: 0b1001000000000010 mask: 0b1111111111111111 size: 16 branch: false delay: 1 - - CSWSP: + C__SWSP: encoding: 0b1100000000000010 mask: 0b1110000000000011 size: 16 branch: false delay: 1 - - DII: + DII: encoding: 0b0000000000000000 mask: 0b1111111111111111 size: 16 diff --git a/gen_input/templates/CORENAME_instr.yaml.gtl b/gen_input/templates/CORENAME_instr.yaml.gtl index eb344ff..6710a1a 100644 --- a/gen_input/templates/CORENAME_instr.yaml.gtl +++ b/gen_input/templates/CORENAME_instr.yaml.gtl @@ -9,8 +9,8 @@ } instrGroups }%><%getInstructionGroups().each{name, instrList -> %> -${name}: <% instrList.findAll{!it.instruction.name.startsWith("__")}.each { %> - - ${it.instruction.name}: +${name}: <% instrList.each { %> + ${it.instruction.name}: encoding: ${it.encoding} mask: ${it.mask}<%if(it.attributes.size) {%> attributes: ${it.attributes}<%}%> diff --git a/src/iss/plugin/cycle_estimate.cpp b/src/iss/plugin/cycle_estimate.cpp index 77d4c5b..267c88e 100644 --- a/src/iss/plugin/cycle_estimate.cpp +++ b/src/iss/plugin/cycle_estimate.cpp @@ -33,18 +33,12 @@ ******************************************************************************/ #include "cycle_estimate.h" +#include #include #include -#include -#include -#include -#include -#include -#include #include -using namespace rapidjson; using namespace std; iss::plugin::cycle_estimate::cycle_estimate(string const& config_file_name) @@ -61,40 +55,31 @@ bool iss::plugin::cycle_estimate::registration(const char* const version, vm_if& if(!instr_if) return false; const string core_name = instr_if->core_type_name(); if (config_file_name.length() > 0) { - ifstream is(config_file_name); + std::ifstream is(config_file_name); if (is.is_open()) { try { - IStreamWrapper isw(is); - Document d; - ParseResult ok = d.ParseStream(isw); - if(ok) { - Value& val = d[core_name.c_str()]; - if(val.IsArray()){ - delays.reserve(val.Size()); - for (auto it = val.Begin(); it != val.End(); ++it) { - auto& name = (*it)["name"]; - auto& size = (*it)["size"]; - auto& delay = (*it)["delay"]; - auto& branch = (*it)["branch"]; - if(delay.IsArray()) { - auto dt = delay[0].Get(); - auto dnt = delay[1].Get(); - delays.push_back(instr_desc{size.Get(), dt, dnt, branch.Get()}); - } else if(delay.Is()) { - auto d = delay.Get(); - delays.push_back(instr_desc{size.Get(), d, d, branch.Get()}); - } else - throw runtime_error("JSON parse error"); - } - } else { - LOG(ERR)<<"plugin cycle_estimate: could not find an entry for "<(); + auto delay = instr.second["delay"]; + if(delay.IsSequence()) { + res.not_taken = delay[0].as(); + res.taken = delay[1].as(); + } else { + res.not_taken = delay.as(); + res.taken = res.not_taken; + } + delays.push_back(std::move(res)); + } + } + } catch (YAML::ParserException &e) { LOG(ERR) << "Could not parse input file " << config_file_name << ", reason: " << e.what(); return false; } diff --git a/src/iss/plugin/instruction_count.cpp b/src/iss/plugin/instruction_count.cpp index 7613b27..01fb45c 100644 --- a/src/iss/plugin/instruction_count.cpp +++ b/src/iss/plugin/instruction_count.cpp @@ -34,6 +34,7 @@ #include "instruction_count.h" #include +#include #include #include @@ -44,8 +45,30 @@ iss::plugin::instruction_count::instruction_count(std::string config_file_name) std::ifstream is(config_file_name); if (is.is_open()) { try { - is >> root; - } catch (Json::RuntimeError &e) { + auto root = YAML::LoadAll(is); + if(root.size()!=1) { + LOG(ERR) << "Too many rro nodes in YAML file " << config_file_name; + } + for (auto p : root[0]) { + auto isa_subset = p.first; + auto instructions = p.second; + for (auto const& instr : instructions) { + instr_delay res; + res.instr_name = instr.first.as(); + res.size = instr.second["encoding"].as().size()-2; // not counting 0b + auto delay = instr.second["delay"]; + if(delay.IsSequence()) { + res.not_taken_delay = delay[0].as(); + res.taken_delay = delay[1].as(); + } else { + res.not_taken_delay = delay.as(); + res.taken_delay = res.not_taken_delay; + } + delays.push_back(std::move(res)); + } + } + rep_counts.resize(delays.size()); + } catch (YAML::ParserException &e) { LOG(ERR) << "Could not parse input file " << config_file_name << ", reason: " << e.what(); } } else { @@ -57,7 +80,7 @@ iss::plugin::instruction_count::instruction_count(std::string config_file_name) iss::plugin::instruction_count::~instruction_count() { size_t idx=0; for(auto it:delays){ - if(rep_counts[idx]>0) + if(rep_counts[idx]>0 && it.instr_name.find("__"!=0)) LOG(INFO)<get_instrumentation_if(); if(!instr_if) return false; - const std::string core_name = instr_if->core_type_name(); - Json::Value &val = root[core_name]; - if(!val.isNull() && val.isArray()){ - delays.reserve(val.size()); - for(auto it:val){ - auto name = it["name"]; - auto size = it["size"]; - auto delay = it["delay"]; - if(!name.isString() || !size.isUInt() || !(delay.isUInt() || delay.isArray())) throw std::runtime_error("JSON parse error"); - if(delay.isUInt()){ - const instr_delay entry{name.asCString(), size.asUInt(), delay.asUInt(), 0}; - delays.push_back(entry); - } else { - const instr_delay entry{name.asCString(), size.asUInt(), delay[0].asUInt(), delay[1].asUInt()}; - delays.push_back(entry); - } - } - rep_counts.resize(delays.size()); - } else { - LOG(ERR)<<"plugin instruction_count: could not find an entry for "< -#include #include +#include namespace iss { namespace plugin { @@ -72,7 +72,6 @@ public: void callback(instr_info_t) override; private: - Json::Value root; std::vector delays; std::vector rep_counts; }; diff --git a/src/main.cpp b/src/main.cpp index 1d3d8e9..c93d558 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) { ("mem,m", po::value(), "the memory input file") ("plugin,p", po::value>(), "plugin to activate") ("backend", po::value()->default_value("interp"), "the ISS backend to use, options are: interp, tcc") - ("isa", po::value()->default_value("tgc5c"), "isa to use for simulation"); + ("isa", po::value()->default_value("tgc5c"), "core or isa name to use for simulation, use '?' to get list"); // clang-format on auto parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); try { @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) { std::tie(cpu, vm) = f.create(isa_opt+"|"+clim["backend"].as(), clim["gdb-port"].as()); } else { auto base_isa = isa_opt.substr(0, 5); - if(base_isa=="tgc_d" || base_isa=="tgc_e") { + if(base_isa=="tgc5d" || base_isa=="tgc5e") { isa_opt += "|mu_p_clic_pmp|"+clim["backend"].as(); } else { isa_opt += "|m_p|"+clim["backend"].as(); @@ -148,6 +148,7 @@ int main(int argc, char *argv[]) { plugin_name = opt_val.substr(0, found); arg = opt_val.substr(found + 1, opt_val.size()); } +#if defined(WITH_PLUGINS) if (plugin_name == "ic") { auto *ic_plugin = new iss::plugin::instruction_count(arg); vm->register_plugin(*ic_plugin); @@ -156,8 +157,10 @@ int main(int argc, char *argv[]) { auto *ce_plugin = new iss::plugin::cycle_estimate(arg); vm->register_plugin(*ce_plugin); plugin_list.push_back(ce_plugin); - }else { -#ifndef WIN32 + } else +#endif + { +#if !defined(WIN32) std::vector a{}; if(arg.length()) a.push_back({arg.c_str()});