Skip to content

Commit

Permalink
Add interface and unit tests for OOO window
Browse files Browse the repository at this point in the history
  • Loading branch information
kkorolev-intel committed Apr 12, 2020
1 parent ab1c94a commit 85e7c47
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions simulator/func_sim/func_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@

#include "driver/driver.h"
#include "func_sim.h"

#include <kernel/kernel.h>
#include <infra/config/config.h>

#include <iostream>
#include <sstream>
#include <stdexcept>

namespace config {
static Value<uint32> ooo_window_size = { "ooo_window_size", 0, "size of OOO window (ROB)"};
} // namespace config

template <typename ISA>
FuncSim<ISA>::FuncSim( Endian endian, bool log, std::string_view isa)
: BasicFuncSim( isa)
, ooo_window( config::ooo_window_size)
, imem( endian)
, driver( ISA::create_driver( this))
{
Expand Down Expand Up @@ -91,6 +98,7 @@ Trap FuncSim<ISA>::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);
}
Expand Down
2 changes: 2 additions & 0 deletions simulator/func_sim/func_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <infra/exception.h>
#include <memory/memory.h>
#include <simulator.h>
#include <func_sim/ooo_window/ooo_window.h>

#include <memory>
#include <string>
Expand All @@ -35,6 +36,7 @@ class FuncSim : public BasicFuncSim
using RegisterUInt = typename ISA::RegisterUInt;

private:
OOOWindow<FuncInstr> ooo_window;
RF<FuncInstr> rf;
uint64 sequence_id = 0;
std::shared_ptr<FuncMemory> mem;
Expand Down
38 changes: 38 additions & 0 deletions simulator/func_sim/ooo_window/t/unit_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

#include <catch.hpp>

#include <func_sim/ooo_window/ooo_window.h>
#include <risc_v/riscv_instr.h>

TEST_CASE( "OOO_Window: zero size")
{
OOOWindow<RISCVInstr<uint32>> w( 0);
RISCVInstr<uint32> 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<RISCVInstr<uint32>> w( 5);
RISCVInstr<uint32> 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<RISCVInstr<uint32>> w( 10);
RISCVInstr<uint32> 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
}
13 changes: 12 additions & 1 deletion simulator/func_sim/operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class BaseInstruction : public Datapath<T>
using MyDatapath = Datapath<T>;
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; }

Expand All @@ -251,6 +251,17 @@ class BaseInstruction : public Datapath<T>
R dst2 = R::zero();
};

template<typename T, typename R>
R BaseInstruction<T, R>::get_src_num( size_t index) const
{
if ( index == 0)
return src1;
else if ( index == 1)
return src2;
else
return src3;
}

template<typename T, typename R>
std::string BaseInstruction<T, R>::generate_disasm() const
{
Expand Down

0 comments on commit 85e7c47

Please sign in to comment.