Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

54 refactoring of load methods #81

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

# CMake build files
build/
third_party/benchmark
third_party/googletest

# ide stuff
.idea
cmake-build*
include/ChaiVM/interpreter/autogen
include/ChaiVM/interpreter/autogen
1 change: 0 additions & 1 deletion bench/sin_plus_cos_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ static void BM_SinCos(benchmark::State &state) {
for (auto _ : state) {
chai::memory::LinearBuffer buffer_ =
chai::memory::LinearBuffer(1024 * 256);
;
Executor executor{&wrapper.manager_, buffer_};
executor.run();
}
Expand Down
1 change: 1 addition & 0 deletions src/ChaiVM/utils/instr2Raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ static uint8_t operation2opcode(Operation operation) {
return (uint8_t)operation;
}

// @todo #54:60min add template parameter by format and refactor naming
chai::bytecode_t instr2Raw(Operation op, RegisterId r1, RegisterId r2) {
return (operation2opcode(op)) | (r1 << 8) | (r2 << 16);
}
Expand Down
39 changes: 20 additions & 19 deletions test/ChaiVM/interpreter/executor-test-fixture.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#include "executor-test-fixture.hpp"

using chai::interpreter::Immidiate;
using namespace chai::utils::fileformat;

void ExecutorTest::loadRR(chai::interpreter::Operation op,
chai::interpreter::RegisterId reg1,
chai::interpreter::RegisterId reg2) {
chaiFile_.addInstr(chai::utils::instr2Raw(op, reg1, reg2));
Immidiate ExecutorTest::loadRR(chai::interpreter::Operation op,
chai::interpreter::RegisterId reg1,
chai::interpreter::RegisterId reg2) {
return chaiFile_.addInstr(chai::utils::instr2Raw(op, reg1, reg2));
}

void ExecutorTest::loadRI(chai::interpreter::Operation op,
chai::interpreter::RegisterId reg1,
chai::interpreter::Immidiate imm) {
chaiFile_.addInstr(chai::utils::inst2RawRI(op, reg1, imm));
Immidiate ExecutorTest::loadRI(chai::interpreter::Operation op,
chai::interpreter::RegisterId reg1,
chai::interpreter::Immidiate imm) {
return chaiFile_.addInstr(chai::utils::inst2RawRI(op, reg1, imm));
}

int ExecutorTest::loadI(chai::interpreter::Operation op,
chai::interpreter::Immidiate imm) {
Immidiate ExecutorTest::loadI(chai::interpreter::Operation op,
chai::interpreter::Immidiate imm) {
return chaiFile_.addInstr(chai::utils::instr2Raw(op, imm));
}

Immidiate ExecutorTest::loadN(chai::interpreter::Operation op) {
return chaiFile_.addInstr(chai::utils::instr2Raw(op));
}

void ExecutorTest::loadWithConst(chai::interpreter::Operation op,
int64_t data) {
chaiFile_.addWithConst(op, data);
Expand All @@ -28,19 +33,15 @@ void ExecutorTest::loadWithConst(chai::interpreter::Operation op, double data) {
chaiFile_.addWithConst(op, data);
}

int ExecutorTest::load(chai::interpreter::Operation op) {
return chaiFile_.addInstr(chai::utils::instr2Raw(op));
}

void ExecutorTest::update() {
chaiFile_.toFile(PATH);
codeManager_.load(PATH);
chaiFile_.toFile(path_);
codeManager_.load(path_);
}

void ExecutorTest::SetUp() {
PATH = std::string{"test_"}.append(std::string{
path_ = std::string{"test_"}.append(std::string{
testing::UnitTest::GetInstance()->current_test_info()->name()});
std::remove(PATH.c_str());
std::remove(path_.c_str());
}

void ExecutorTest::TearDown() { std::remove(PATH.c_str()); }
void ExecutorTest::TearDown() { std::remove(path_.c_str()); }
71 changes: 56 additions & 15 deletions test/ChaiVM/interpreter/executor-test-fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class ExecutorTest : public ::testing::Test {
protected:
static constexpr chai::interpreter::RegisterId R0 = 1;
static constexpr chai::interpreter::RegisterId R0 = 0;
static constexpr chai::interpreter::RegisterId R1 = 1;
static constexpr chai::interpreter::RegisterId R2 = 2;
static constexpr chai::interpreter::RegisterId R3 = 3;
Expand All @@ -22,33 +22,74 @@ class ExecutorTest : public ::testing::Test {
static constexpr chai::interpreter::RegisterId R9 = 9;
static constexpr chai::interpreter::RegisterId R10 = 10;
static constexpr chai::interpreter::RegisterId R11 = 11;
std::filesystem::path PATH;
std::filesystem::path path_;

/*
* @todo #42:60min Rename all load methods to more appropriate names.
/**
* These methods loads the operation in template parameter with the
* corresponding parameters.
* @param op Operation.
* @return Number of added instruction among all instructions.
*/
void loadRR(chai::interpreter::Operation op,
chai::interpreter::RegisterId reg1,
chai::interpreter::RegisterId reg2 = 0);
void loadRI(chai::interpreter::Operation op,
chai::interpreter::RegisterId reg1,
chai::interpreter::Immidiate imm);

int loadI(chai::interpreter::Operation op,
chai::interpreter::Immidiate imm);
template <chai::interpreter::Operation op>
typename std::enable_if<chai::interpreter::OP_TO_FORMAT[op] ==
chai::interpreter::R,
chai::interpreter::Immidiate>::type
load(chai::interpreter::RegisterId reg1) {
return loadRR(op, reg1, 0);
}
template <chai::interpreter::Operation op>
typename std::enable_if<chai::interpreter::OP_TO_FORMAT[op] ==
chai::interpreter::RR,
chai::interpreter::Immidiate>::type
load(chai::interpreter::RegisterId reg1,
chai::interpreter::RegisterId reg2) {
return loadRR(op, reg1, reg2);
}
template <chai::interpreter::Operation op>
typename std::enable_if<chai::interpreter::OP_TO_FORMAT[op] ==
chai::interpreter::RI,
chai::interpreter::Immidiate>::type
load(chai::interpreter::RegisterId reg1, chai::interpreter::Immidiate imm) {
return loadRI(op, reg1, imm);
}
template <chai::interpreter::Operation op>
typename std::enable_if<chai::interpreter::OP_TO_FORMAT[op] ==
chai::interpreter::I,
chai::interpreter::Immidiate>::type
load(chai::interpreter::Immidiate imm) {
return loadI(op, imm);
}
template <chai::interpreter::Operation op>
typename std::enable_if<chai::interpreter::OP_TO_FORMAT[op] ==
chai::interpreter::N,
chai::interpreter::Immidiate>::type
load() {
return loadN(op);
}

// @todo #54:60min do something to add this functionality to load Immediate
void loadWithConst(chai::interpreter::Operation op, int64_t data);

void loadWithConst(chai::interpreter::Operation op, double data);
c71n93 marked this conversation as resolved.
Show resolved Hide resolved

int load(chai::interpreter::Operation op);

void update();

void SetUp() override;

void TearDown() override;

private:
chai::interpreter::Immidiate loadRR(chai::interpreter::Operation op,
chai::interpreter::RegisterId reg1,
chai::interpreter::RegisterId reg2 = 0);
chai::interpreter::Immidiate loadRI(chai::interpreter::Operation op,
chai::interpreter::RegisterId reg1,
chai::interpreter::Immidiate imm);
chai::interpreter::Immidiate loadI(chai::interpreter::Operation op,
chai::interpreter::Immidiate imm);
chai::interpreter::Immidiate loadN(chai::interpreter::Operation op);

protected:
chai::utils::fileformat::ChaiFile chaiFile_;
chai::interpreter::CodeManager codeManager_;
chai::memory::LinearBuffer buffer_ = chai::memory::LinearBuffer(1024 * 256);
Expand Down
Loading
Loading