mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-01-26 10:33:01 +00:00
Add virtual CPU benchmarking code.
This commit is contained in:
parent
b81de4af48
commit
6124dfd897
@ -89,6 +89,16 @@ else()
|
|||||||
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
|
||||||
|
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||||
|
$<TARGET_OBJECTS:cpu_ppc>
|
||||||
|
$<TARGET_OBJECTS:devices>
|
||||||
|
$<TARGET_OBJECTS:execution>
|
||||||
|
$<TARGET_OBJECTS:machines>
|
||||||
|
$<TARGET_OBJECTS:loguru>)
|
||||||
|
|
||||||
|
target_link_libraries(bench1 cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET testppc POST_BUILD
|
TARGET testppc POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
91
benchmark/bench1.cpp
Normal file
91
benchmark/bench1.cpp
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <chrono>
|
||||||
|
#include "cpu/ppc/ppcemu.h"
|
||||||
|
#include "cpu/ppc/ppcmmu.h"
|
||||||
|
#include "devices/mpc106.h"
|
||||||
|
#include <thirdparty/loguru/loguru.hpp>
|
||||||
|
|
||||||
|
uint32_t cs_code[] = {
|
||||||
|
0x3863FFFC, 0x7C861671, 0x41820090, 0x70600002, 0x41E2001C, 0xA0030004,
|
||||||
|
0x3884FFFE, 0x38630002, 0x5486F0BF, 0x7CA50114, 0x41820070, 0x70C60003,
|
||||||
|
0x41820014, 0x7CC903A6, 0x84030004, 0x7CA50114, 0x4200FFF8, 0x5486E13F,
|
||||||
|
0x41820050, 0x80030004, 0x7CC903A6, 0x80C30008, 0x7CA50114, 0x80E3000C,
|
||||||
|
0x7CA53114, 0x85030010, 0x7CA53914, 0x42400028, 0x80030004, 0x7CA54114,
|
||||||
|
0x80C30008, 0x7CA50114, 0x80E3000C, 0x7CA53114, 0x85030010, 0x7CA53914,
|
||||||
|
0x4200FFE0, 0x7CA54114, 0x70800002, 0x41E20010, 0xA0030004, 0x38630002,
|
||||||
|
0x7CA50114, 0x70800001, 0x41E20010, 0x88030004, 0x5400402E, 0x7CA50114,
|
||||||
|
0x7C650194, 0x4E800020
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* initialize logging */
|
||||||
|
loguru::g_preamble_date = false;
|
||||||
|
loguru::g_preamble_time = false;
|
||||||
|
loguru::g_preamble_thread = false;
|
||||||
|
|
||||||
|
loguru::g_stderr_verbosity = 0;
|
||||||
|
loguru::init(argc, argv);
|
||||||
|
|
||||||
|
MPC106* grackle_obj = new MPC106;
|
||||||
|
|
||||||
|
/* we need some RAM */
|
||||||
|
if (!grackle_obj->add_ram_region(0, 0x9000)) {
|
||||||
|
LOG_F(ERROR, "Could not create RAM region");
|
||||||
|
delete(grackle_obj);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
|
||||||
|
|
||||||
|
/* load executable code into RAM at address 0 */
|
||||||
|
for (i = 0; i < sizeof(cs_code); i++) {
|
||||||
|
mem_write_dword(i*4, cs_code[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
srand(0xCAFEBABE);
|
||||||
|
|
||||||
|
for (i = 0; i < 32768; i++) {
|
||||||
|
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
|
||||||
|
|
||||||
|
ppc_exec_until(0xC4);
|
||||||
|
|
||||||
|
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||||
|
|
||||||
|
// run the clock once for cache fill etc.
|
||||||
|
auto start_time = std::chrono::steady_clock::now();
|
||||||
|
auto end_time = std::chrono::steady_clock::now();
|
||||||
|
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||||
|
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
|
||||||
|
|
||||||
|
auto start_time = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
ppc_exec_until(0xC4);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user