Skip to content

Commit

Permalink
updated dhrystone.riscv to run forever, added google benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
markzakharov committed Dec 2, 2022
1 parent db52ca0 commit 48b5b9b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
Binary file modified conf/dhrystone.riscv
Binary file not shown.
14 changes: 13 additions & 1 deletion emul/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ cc_binary(
deps = [
":emul",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main" # Only if hello_test.cc has no main()
"@com_google_googletest//:gtest_main"
],
)

cc_binary(
name = "emul_dromajo_bench",
srcs = [
"emul_dromajo_bench.cpp",
"emul_dromajo.cpp",
],
deps = [
":emul",
"@com_google_benchmark//:benchmark",
],
)
44 changes: 44 additions & 0 deletions emul/emul_dromajo_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This file is distributed under the BSD 3-Clause License. See LICENSE for details.

#include "benchmark/benchmark.h"
#include "emul_dromajo.hpp"

Emul_dromajo* dromajo_ptr;

static void BM_InstructionExecuteAndDecode(benchmark::State& state) {
for (auto _ : state) {
dromajo_ptr->skip_rabbit(0, 1);
Dinst *dinst = dromajo_ptr->peek(0);
dinst->recycle();
}
}
BENCHMARK(BM_InstructionExecuteAndDecode);

static void BM_InstructionExecute(benchmark::State& state) {
for (auto _ : state)
dromajo_ptr->skip_rabbit(0,1);
}
BENCHMARK(BM_InstructionExecute);

int main(int argc, char* argv[]) {
std::ofstream file;
file.open("emul_dromajo_test.toml");

file << "[soc]\n";
file << "core = \"c0\"\n";
file << "emul = \"drom_emu\"\n";
file << "\n[drom_emu]\n";
file << "num = \"1\"\n";
file << "type = \"dromajo\"\n";
file.close();

Config configuration;
configuration.init("emul_dromajo_test.toml");

char benchmark_name[] = "dhrystone.riscv";

Emul_dromajo dromajo_emul(configuration);
dromajo_emul.init_dromajo_machine(benchmark_name);
dromajo_ptr = &dromajo_emul;
benchmark::RunSpecifiedBenchmarks();
}
20 changes: 11 additions & 9 deletions emul/emul_dromajo_test.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// This file is distributed under the BSD 3-Clause License. See LICENSE for details.

#include "emul_dromajo.hpp"

#include <assert.h>
Expand Down Expand Up @@ -65,14 +67,14 @@ TEST_F(Emul_Dromajo_test, dhrystone_test) {
Emul_dromajo dromajo_emul = *dromajo_ptr;
EXPECT_FALSE(dromajo_ptr == NULL);

dromajo_emul.skip_rabbit(0, 553);
dromajo_emul.skip_rabbit(0, 560);
Dinst *dinst = dromajo_emul.peek(0); //csrr
EXPECT_EQ(0x0000000080002ae4, dinst->getPC());
EXPECT_EQ(0x0000000080002aaa, dinst->getPC());
const Instruction *inst = dinst->getInst();
EXPECT_EQ(15, inst->getDst1());
dinst->recycle();

dromajo_emul.skip_rabbit(0, 187);
dromajo_emul.skip_rabbit(0, 197);
dinst = dromajo_emul.peek(0); //bge
EXPECT_EQ(0x0000000080002094, dinst->getPC());
EXPECT_EQ(0x00000000800020a4, dinst->getAddr());
Expand All @@ -92,17 +94,17 @@ TEST_F(Emul_Dromajo_test, dhrystone_test) {

dromajo_emul.skip_rabbit(0, 2); //addi
dinst = dromajo_emul.peek(0);
EXPECT_EQ(0x0000000080002b46, dinst->getPC());
EXPECT_EQ(0x0000000080002b38, dinst->getPC());
inst = dinst->getInst();
EXPECT_EQ(14 ,inst->getSrc1());
EXPECT_EQ(14, inst->getDst1());
EXPECT_EQ(8 ,inst->getSrc1());
EXPECT_EQ(12, inst->getDst1());
EXPECT_TRUE(inst->isALU());
dinst->recycle();

dromajo_emul.skip_rabbit(0, 7); //sw
dromajo_emul.skip_rabbit(0, 5); //sw
dinst = dromajo_emul.peek(0);
EXPECT_EQ(0x0000000080002b5a, dinst->getPC());
EXPECT_EQ(0x0000000080025f18, dinst->getAddr());
EXPECT_EQ(0x0000000080002b46, dinst->getPC());
EXPECT_EQ(0x0000000080025658, dinst->getAddr());
inst = dinst->getInst();
EXPECT_EQ(8 ,inst->getSrc1());
EXPECT_EQ(15 ,inst->getSrc2());
Expand Down

0 comments on commit 48b5b9b

Please sign in to comment.