diff --git a/simulator/CMakeLists.txt b/simulator/CMakeLists.txt index df19dac7a..7fe0f72d1 100644 --- a/simulator/CMakeLists.txt +++ b/simulator/CMakeLists.txt @@ -62,6 +62,7 @@ set(TESTS_CPPS func_sim/traps/t/unit_test.cpp func_sim/driver/t/unit_test.cpp func_sim/t/unit_test.cpp + func_sim/ooo_window/t/unit_test.cpp modules/fetch/bpu/t/unit_test.cpp modules/core/t/unit_test.cpp export/gdb/t/unit_test.cpp @@ -187,6 +188,7 @@ add_library(mipt-mips-src OBJECT func_sim/func_sim.cpp func_sim/driver/driver.cpp func_sim/traps/trap.cpp + func_sim/ooo_window/ooo_window.cpp mips/mips_instr.cpp mips/mips_register/mips_register.cpp mips/mips_driver.cpp diff --git a/simulator/func_sim/func_sim.cpp b/simulator/func_sim/func_sim.cpp index 214eadcc0..a462d7d54 100644 --- a/simulator/func_sim/func_sim.cpp +++ b/simulator/func_sim/func_sim.cpp @@ -5,15 +5,22 @@ #include "driver/driver.h" #include "func_sim.h" + #include +#include #include #include #include +namespace config { + static Value ooo_window_size = { "ooo_window_size", 0, "size of OOO window (ROB)"}; +} // namespace config + template FuncSim::FuncSim( Endian endian, bool log, std::string_view isa) : BasicFuncSim( isa) + , ooo_window( config::ooo_window_size) , imem( endian) , driver( ISA::create_driver( this)) { @@ -91,6 +98,7 @@ Trap FuncSim::run( uint64 instrs_to_run) auto result_trap = driver_step( instr); if ( result_trap != Trap::NO_TRAP) return result_trap; + ooo_window.write_instruction( instr); } return Trap(Trap::BREAKPOINT); } diff --git a/simulator/func_sim/func_sim.h b/simulator/func_sim/func_sim.h index b6bbc7bd1..e3e32e921 100644 --- a/simulator/func_sim/func_sim.h +++ b/simulator/func_sim/func_sim.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,7 @@ class FuncSim : public BasicFuncSim using RegisterUInt = typename ISA::RegisterUInt; private: + OOOWindow ooo_window; RF rf; uint64 sequence_id = 0; std::shared_ptr mem; diff --git a/simulator/func_sim/ooo_window/t/unit_test.cpp b/simulator/func_sim/ooo_window/t/unit_test.cpp new file mode 100644 index 000000000..1b1300dc0 --- /dev/null +++ b/simulator/func_sim/ooo_window/t/unit_test.cpp @@ -0,0 +1,38 @@ + +#include + +#include +#include + +TEST_CASE( "OOO_Window: zero size") +{ + OOOWindow> w( 0); + RISCVInstr nop(0x0001); + w.write_instruction( nop); + w.write_instruction( nop); + w.write_instruction( nop); + + CHECK( w.get_avg_independent_instructions() == 0); +} + +TEST_CASE( "OOO_Window: all independent") +{ + OOOWindow> w( 5); + RISCVInstr instr(0x48fd); // c_li $a7, 31 + + for ( int i = 0; i < 1000; i++) + w.write_instruction( instr); + + CHECK( w.get_avg_independent_instructions() == 5.0); +} + +TEST_CASE( "OOO_Window: all dependent") +{ + OOOWindow> w( 10); + RISCVInstr instr(0x8df1); // c_and $a1, $a2 + + for ( int i = 0; i < 1000; i++) + w.write_instruction( instr); + + CHECK( w.get_avg_independent_instructions() == 1.0); // the last instr. in the window is always independent +} diff --git a/simulator/func_sim/operation.h b/simulator/func_sim/operation.h index 520a8f740..900df3e6d 100644 --- a/simulator/func_sim/operation.h +++ b/simulator/func_sim/operation.h @@ -234,7 +234,7 @@ class BaseInstruction : public Datapath using MyDatapath = Datapath; using Register = R; using RegisterUInt = T; - R get_src_num( size_t index) const { return ( index == 0) ? src1 : src2; } + R get_src_num( size_t index) const; R get_dst_num() const { return dst; } R get_dst2_num() const { return dst2; } @@ -251,6 +251,17 @@ class BaseInstruction : public Datapath R dst2 = R::zero(); }; +template +R BaseInstruction::get_src_num( size_t index) const +{ + if ( index == 0) + return src1; + else if ( index == 1) + return src2; + else + return src3; +} + template std::string BaseInstruction::generate_disasm() const {