-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1be322
commit 4ed08cd
Showing
10 changed files
with
284 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "ChaiVM/interpreter/executor.hpp" | ||
|
||
using namespace chai::interpreter; | ||
|
||
class CodeManWrapper { | ||
public: | ||
/* | ||
* @todo #32:60min Make the methods "instr2Raw" implemented only once. For | ||
* example in utils. | ||
*/ | ||
static chai::bytecode_t instr2Raw(Operation op, RegisterId r1, | ||
RegisterId r2) { | ||
return (operation2opcode(op)) | (r1 << 8) | (r2 << 16); | ||
} | ||
static chai::bytecode_t instr2Raw(Operation op, Immidiate imm) { | ||
return (operation2opcode(op)) | | ||
(static_cast<chai::bytecode_t>(imm) << 8); | ||
} | ||
static chai::bytecode_t instr2Raw(Operation op) { | ||
return (operation2opcode(op)); | ||
} | ||
|
||
public: | ||
void load(Operation op, RegisterId r1, RegisterId r2) { | ||
manager_.load(instr2Raw(op, r1, r2)); | ||
} | ||
|
||
void load(Operation op, Immidiate imm) { | ||
manager_.load(instr2Raw(op, imm)); | ||
} | ||
|
||
void load(Operation op) { manager_.load(instr2Raw(op)); } | ||
|
||
static uint8_t operation2opcode(Operation operation) { | ||
return (uint8_t)operation; | ||
} | ||
|
||
public: | ||
CodeManager manager_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
#include "codeman-wrapper.hpp" | ||
|
||
using namespace chai::interpreter; | ||
|
||
static void initCode(CodeManWrapper &codeman); | ||
|
||
static void BM_SquareEquation(benchmark::State &state) { | ||
// Perform setup here | ||
CodeManWrapper wrapper{}; | ||
initCode(wrapper); | ||
Executor executor{&wrapper.manager_}; | ||
for (auto _ : state) { | ||
executor.run(); | ||
executor.restart(); | ||
} | ||
} | ||
// Register the function as a benchmark | ||
// @todo #32:60min Measure mips here | ||
BENCHMARK(BM_SquareEquation); | ||
|
||
static void initCode(CodeManWrapper &codeman) { | ||
const RegisterId r1 = 1; | ||
const RegisterId r2 = 2; | ||
const RegisterId r3 = 3; | ||
const RegisterId r4 = 4; | ||
const RegisterId r5 = 5; | ||
const RegisterId r6 = 6; | ||
const RegisterId r7 = 7; | ||
const RegisterId r8 = 8; | ||
const RegisterId r9 = 9; | ||
const RegisterId r10 = 10; | ||
const RegisterId r11 = 11; | ||
|
||
// r1 = 1.0, r2 = -5.0, r3 = 6.0 | ||
codeman.load(Ldiaf, std::bit_cast<Immidiate>(1.0f)); | ||
codeman.load(Star, r1, 0); | ||
codeman.load(Ldiaf, std::bit_cast<Immidiate>(-5.0f)); | ||
codeman.load(Star, r2, 0); | ||
codeman.load(Ldiaf, std::bit_cast<Immidiate>(+6.0f)); | ||
codeman.load(Star, r3, 0); | ||
|
||
// r4 = -4*r1*r3 | ||
codeman.load(Ldiaf, std::bit_cast<Immidiate>(-4.0f)); | ||
codeman.load(Mulf, r1, 0); | ||
codeman.load(Mulf, r3, 0); | ||
codeman.load(Star, r4, 0); | ||
|
||
// r5 = b * b | ||
codeman.load(Ldra, r2, 0); | ||
codeman.load(Mulf, r2, 0); | ||
codeman.load(Star, r5, 0); | ||
|
||
// r6 = r5 + r4 | ||
codeman.load(Ldra, r5, 0); | ||
codeman.load(Addf, r4, 0); | ||
codeman.load(Star, r6, 0); | ||
|
||
// r6 = sqrt(r6) | ||
codeman.load(Ldra, r6, 0); | ||
codeman.load(IcSqrt); | ||
codeman.load(Star, r6, 0); | ||
|
||
// r7 = 2a | ||
codeman.load(Ldra, r1, 0); | ||
codeman.load(chai::interpreter::Mulif, std::bit_cast<Immidiate>(2.0f)); | ||
codeman.load(Star, r7); | ||
|
||
// r8 = r6 - r2 | ||
codeman.load(Ldra, r6, 0); | ||
codeman.load(Subf, r2, 0); | ||
codeman.load(Star, r8, 0); | ||
|
||
// X1 = r9 = r8 / r7 | ||
codeman.load(Ldra, r8, 0); | ||
codeman.load(Divf, r7, 0); | ||
codeman.load(Star, r9, 0); | ||
|
||
// acc = -r2 - r6 | ||
// r11 = acc / r7 | ||
codeman.load(Ldiaf, std::bit_cast<Immidiate>(0.0f)); | ||
codeman.load(Subf, r2, 0); | ||
codeman.load(Subf, r6, 0); | ||
codeman.load(Divf, r7, 0); | ||
codeman.load(Star, r11, 0); | ||
codeman.load(Ret); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
4ed08cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
8-cc9cbab0
disappeared frominclude/ChaiVM/interpreter/code-manager.hpp
), that's why I closed #18. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.4ed08cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
32-cab74994
discovered inbench/codeman-wrapper.hpp
) and submitted as #34. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.4ed08cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
32-e5a361e3
discovered inbench/interpreter_bench.cpp
) and submitted as #35. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.