Skip to content

Commit

Permalink
Start using prepared calls for benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Jun 20, 2024
1 parent 2f136a5 commit d60adf3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
6 changes: 3 additions & 3 deletions engine/scripts/src/gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ PUBLIC(void benchmarks())
measure("VM function call overhead",
[] {
});
measure("Full thread creation overhead", full_thread_function);
measure("Oneshot thread creation overhead", oneshot_thread_function);
measure("Direct thread creation overhead", direct_thread_function);
//measure("Full thread creation overhead", full_thread_function);
//measure("Oneshot thread creation overhead", oneshot_thread_function);
//measure("Direct thread creation overhead", direct_thread_function);
measure("Dynamic call handler x4 (inline)", inline_dyncall_handler);
measure("Dynamic call handler x4 (call)", opaque_dyncall_handler);

Expand Down
13 changes: 13 additions & 0 deletions engine/src/script/script_bench.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "script.hpp"
#include <strf/to_cfile.hpp>
#define USE_PREPARED_CALLS 1
#ifdef USE_PREPARED_CALLS
#include <libriscv/prepared_call.hpp>
#endif

using gaddr_t = Script::gaddr_t;

Expand All @@ -22,13 +26,22 @@ inline int64_t perform_test(Script::machine_t& machine, gaddr_t func)
machine.memory.set_stack_initial(
machine.cpu.reg(riscv::REG_SP) - 2048);
// Warmup once
#ifdef USE_PREPARED_CALLS
riscv::PreparedCall<Script::MARCH, void()> caller(machine, func);
caller();
#else
machine.vmcall(func);
#endif
asm("" : : : "memory");
t0 = time_now();
asm("" : : : "memory");
for (int i = 0; i < ROUNDS; i++)
{
#ifdef USE_PREPARED_CALLS
caller();
#else
machine.vmcall(func);
#endif
}
asm("" : : : "memory");
t1 = time_now();
Expand Down
4 changes: 2 additions & 2 deletions engine/src/script/script_remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ void Script::machine_remote_setup()
if (remote_script != nullptr && cpu.pc() < REMOTE_IMG_BASE)
{
auto& remote_machine = remote_script->machine();
return remote_machine.memory.exec_segment_for(cpu.pc());
return *remote_machine.memory.exec_segment_for(cpu.pc());
}

return cpu.empty_execute_segment();
return *cpu.empty_execute_segment();
});
}

Expand Down
2 changes: 1 addition & 1 deletion ext/libriscv

0 comments on commit d60adf3

Please sign in to comment.