Benchmark code for the NuInterpreter.

This commit is contained in:
Maxim Poliakovski 2020-11-15 23:12:23 +01:00
parent d659253f91
commit cc56e391bd
1 changed files with 41 additions and 9 deletions

View File

@ -3,6 +3,8 @@
#include "cpu/ppc/ppcemu.h"
#include "cpu/ppc/ppcmmu.h"
#include "devices/mpc106.h"
#include "jittables.h"
#include "nuinterpreter.h"
#include <thirdparty/loguru/loguru.hpp>
uint32_t cs_code[] = {
@ -17,6 +19,14 @@ uint32_t cs_code[] = {
0x7C650194, 0x4E800020
};
/* set up vCPU registers for benchmark code execution */
void setup_regs() {
ppc_state.pc = 0;
ppc_state.gpr[3] = 0x1000; // buf
ppc_state.gpr[4] = 0x8000; // len
ppc_state.gpr[5] = 0; // sum
}
int main(int argc, char** argv) {
int i;
@ -38,6 +48,8 @@ int main(int argc, char** argv) {
return -1;
}
init_jit_tables();
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
/* load executable code into RAM at address 0 */
@ -51,16 +63,22 @@ int main(int argc, char** argv) {
mem_write_byte(0x1000+i, rand() % 256);
}
/* prepare benchmark code execution */
ppc_state.pc = 0;
ppc_state.gpr[3] = 0x1000; // buf
ppc_state.gpr[4] = 0x8000; // len
ppc_state.gpr[5] = 0; // sum
setup_regs();
ppc_exec_until(0xC4);
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
LOG_F(INFO, "\nRunning with the NuInterpreter");
setup_regs();
NuInterpExec(0);
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
LOG_F(INFO, "\nBenchmarking the old Interpreter:");
// run the clock once for cache fill etc.
auto start_time = std::chrono::steady_clock::now();
auto end_time = std::chrono::steady_clock::now();
@ -68,10 +86,7 @@ int main(int argc, char** argv) {
LOG_F(INFO, "Time elapsed (dry run): %lld ns", time_elapsed.count());
for (i = 0; i < 5; i++) {
ppc_state.pc = 0;
ppc_state.gpr[3] = 0x1000; // buf
ppc_state.gpr[4] = 0x8000; // len
ppc_state.gpr[5] = 0; // sum
setup_regs();
auto start_time = std::chrono::steady_clock::now();
@ -85,6 +100,23 @@ int main(int argc, char** argv) {
LOG_F(INFO, "Time elapsed (run #%d): %lld ns", i, time_elapsed.count());
}
LOG_F(INFO, "\nBenchmarking the NuInterpreter:");
for (i = 0; i < 5; i++) {
setup_regs();
auto start_time = std::chrono::steady_clock::now();
NuInterpExec(0);
auto end_time = std::chrono::steady_clock::now();
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
LOG_F(INFO, "Time elapsed (run #%d): %lld ns", i, time_elapsed.count());
}
delete(grackle_obj);
return 0;