Skip to content

Commit e14ede2

Browse files
joevtdingusdev
authored andcommitted
bench1: Add benchmark for ppc_exec.
1 parent bc05593 commit e14ede2

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,13 @@ if (DPPC_BUILD_PPC_TESTS)
180180
endif()
181181

182182
if (DPPC_BUILD_BENCHMARKS)
183-
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
183+
add_compile_options("-DPPC_BENCHMARKS")
184+
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp"
185+
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
186+
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h"
187+
)
184188
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
185-
$<TARGET_OBJECTS:cpu_ppc>
189+
# $<TARGET_OBJECTS:cpu_ppc>
186190
$<TARGET_OBJECTS:debugger>
187191
$<TARGET_OBJECTS:devices>
188192
$<TARGET_OBJECTS:machines>

benchmark/bench1.cpp

+27-20
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
2727
#include <thirdparty/loguru/loguru.hpp>
2828
#include <debugger/debugger.h>
2929

30+
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
31+
power_on = false;
32+
}
33+
3034
uint32_t cs_code[] = {
3135
0x3863FFFC, 0x7C861671, 0x41820090, 0x70600002, 0x41E2001C, 0xA0030004,
3236
0x3884FFFE, 0x38630002, 0x5486F0BF, 0x7CA50114, 0x41820070, 0x70C60003,
@@ -36,7 +40,7 @@ uint32_t cs_code[] = {
3640
0x80C30008, 0x7CA50114, 0x80E3000C, 0x7CA53114, 0x85030010, 0x7CA53914,
3741
0x4200FFE0, 0x7CA54114, 0x70800002, 0x41E20010, 0xA0030004, 0x38630002,
3842
0x7CA50114, 0x70800001, 0x41E20010, 0x88030004, 0x5400402E, 0x7CA50114,
39-
0x7C650194, 0x4E800020
43+
0x7C650194, /* 0x4E800020 */ 0x00005AF0
4044
};
4145

4246
// 0x7FFFFFFC is the max
@@ -123,26 +127,29 @@ int main(int argc, char** argv) {
123127
}
124128
LOG_F(INFO, "Overhead Time: %lld ns", overhead);
125129

126-
for (i = 0; i < test_iterations; i++) {
127-
uint64_t best_sample = -1;
128-
for (j = 0; j < test_samples; j++) {
129-
ppc_state.pc = 0;
130-
ppc_state.gpr[3] = 0x1000; // buf
131-
ppc_state.gpr[4] = test_size; // len
132-
ppc_state.gpr[5] = 0; // sum
133-
power_on = true;
134-
135-
auto start_time = std::chrono::steady_clock::now();
136-
ppc_exec_until(0xC4);
137-
auto end_time = std::chrono::steady_clock::now();
138-
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
139-
if (time_elapsed.count() < best_sample)
140-
best_sample = time_elapsed.count();
130+
for (int theproc = 0; theproc < 2; theproc++) {
131+
LOG_F(INFO, "Doing %s", theproc ? "ppc_exec_until" : "ppc_exec");
132+
for (i = 0; i < test_iterations; i++) {
133+
uint64_t best_sample = -1;
134+
for (j = 0; j < test_samples; j++) {
135+
ppc_state.pc = 0;
136+
ppc_state.gpr[3] = 0x1000; // buf
137+
ppc_state.gpr[4] = test_size; // len
138+
ppc_state.gpr[5] = 0; // sum
139+
power_on = true;
140+
141+
auto start_time = std::chrono::steady_clock::now();
142+
(theproc) ? ppc_exec_until(0xC4) : ppc_exec();
143+
auto end_time = std::chrono::steady_clock::now();
144+
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
145+
if (time_elapsed.count() < best_sample)
146+
best_sample = time_elapsed.count();
147+
}
148+
if (ppc_state.gpr[3] != checksum)
149+
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
150+
best_sample -= overhead;
151+
LOG_F(INFO, "(%d) %lld ns, %.4lf MiB/s", i+1, best_sample, 1E9 * test_size / (best_sample * 1024 * 1024));
141152
}
142-
if (ppc_state.gpr[3] != checksum)
143-
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
144-
best_sample -= overhead;
145-
LOG_F(INFO, "(run #%d) Time: %lld ns Performance: %.4lf MiB/s", i, best_sample, 1E9 * test_size / (best_sample * 1024 * 1024));
146153
}
147154

148155
delete(grackle_obj);

cpu/ppc/ppcexceptions.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
3131

3232
jmp_buf exc_env; /* Global exception environment. */
3333

34+
#if !defined(PPC_TESTS) && !defined(PPC_BENCHMARKS)
3435
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
3536
#ifdef CPU_PROFILING
3637
exceptions_processed++;

0 commit comments

Comments
 (0)