Skip to content

Commit

Permalink
Add experimental inaccurate dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Jun 24, 2024
1 parent 25818f8 commit 6f239c7
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 2 deletions.
7 changes: 5 additions & 2 deletions emulator/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ static void run_program(
debug.simulate();
} else {
// Normal RISC-V simulation
machine.simulate(cli_args.fuel);
if (cli_args.accurate)
machine.simulate(cli_args.fuel);
else
machine.cpu.simulate_inaccurate(machine.cpu.pc());
}
} catch (riscv::MachineException& me) {
printf("%s\n", machine.cpu.current_instruction_to_string().c_str());
Expand Down Expand Up @@ -342,7 +345,7 @@ static void run_program(
const auto retval = machine.return_value();
printf(">>> Program exited, exit code = %" PRId64 " (0x%" PRIX64 ")\n",
int64_t(retval), uint64_t(retval));
if (cli_args.accurate || !riscv::binary_translation_enabled)
if (cli_args.accurate)
printf("Instructions executed: %" PRIu64 " Runtime: %.3fms Insn/s: %.0fmi/s\n",
machine.instruction_counter(), runtime.count()*1000.0,
machine.instruction_counter() / (runtime.count() * 1e6));
Expand Down
2 changes: 2 additions & 0 deletions lib/libriscv/bytecode_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "cpu_dispatch.cpp"

#include "cpu_inaccurate_dispatch.cpp"

namespace riscv
{
INSTANTIATE_32_IF_ENABLED(CPU);
Expand Down
6 changes: 6 additions & 0 deletions lib/libriscv/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ namespace riscv
/// @return Returns true if the machine stopped normally, otherwise an execution timeout happened.
bool simulate(address_t pc, uint64_t icounter, uint64_t maxcounter);

/// @brief Simulate faster by not counting instructions, and consequently
/// not checking for timeouts. This is useful when there is another
/// layer of timeout checking, like signal handling.
/// @param pc The starting address
void simulate_inaccurate(address_t pc);

// Step precisely one instruction forward from current PC.
void step_one();

Expand Down
Loading

0 comments on commit 6f239c7

Please sign in to comment.