fwsGonzo / libriscv

The fastest RISC-V sandbox
BSD 3-Clause "New" or "Revised" License
526 stars 46 forks source link

Improve binary translation latency by forwarding counters as registers #113

Closed fwsGonzo closed 6 months ago

fwsGonzo commented 6 months ago

We should not need to store and reload the counters when entering bintr. Instead we can forward them, and then return them back again by double-returning the counters. It's not guaranteed to be faster than before, but in theory we can at least avoid one load/store, but most likely both counters. Passing PC may not be as useful.

fwsGonzo commented 6 months ago

I've made an attempt here: https://github.com/fwsGonzo/libriscv/pull/114

Did not see any improvements so far.

fwsGonzo commented 6 months ago

Merged the PR but I will keep this open until the brutal test passes with bintr again.

fwsGonzo commented 6 months ago

The problem is well understood now. The binary translation shared objects cannot really be shared across forks, at least the way they are designed right now.

fwsGonzo commented 6 months ago

I fixed the problem by accessing counters relative to the CPU which is in a register, avoiding the need for state (even internal state) in the translations.