RISC-V: support all branching instructions in JIT
Closes RV-505
What
JIT-support for all branching instructions.
Additionally, we give all branching instructions more explicit names - to help avoid the consistent issue of mistaking one for the other.
Would recommend reviewing commit by commit.
Why
Branching instructions appear throughout many blocks. The time spent between blocks (fetching a new one etc) is high, and therefore the JIT must support blocks which may branch (exiting the block) but in many cases also fall-through to the next instruction when the branching condition is not met.
How
We introduce two new functions: run_branch, run_branch_compare_zero taking a predicate for the comparison. Inlining reduces this all away for interpretation mode - indeed the output assembly for branching instructions is the same.
In the JIT, we insert a jump to the end, if the predicate condition holds - and otherwise we continue in what we call the 'fallthrough' block (where later instructions will continue to be lowered).
Manually Testing
make -C src/riscv all
Benchmarking
master |
This MR | Improvement | |
|---|---|---|---|
| AMD 64 Linux | 5.052 TPS | 5.050 TPS | +0.2% |
| Benchmark Machine | 3.805 TPS | 3.811 TPS | -0.2% |
Tasks for the Author
-
Link all Linear issues related to this MR using magic words (e.g. part of, relates to, closes). -
Eliminate dead code and other spurious artefacts introduced in your changes. -
Document new public functions, methods and types. -
Make sure the documentation for updated functions, methods, and types is correct. -
Add tests for bugs that have been fixed. -
Put in reasonable effort to ensure that CI will pass. make -C src/riscvdune build src/lib_riscvdune build src/rust_deps
-
Benchmark performance and populate the table above if needed. -
Explain changes to regression test captures when applicable. -
Write commit messages to reflect the changes they're about. -
Self-review your changes to ensure they are high-quality. -
Complete all of the above before assigning this MR to reviewers.
Summary by CodeRabbit
-
New Features
- Enhanced branch operations now support a broader range of comparison conditions, including equality, inequality, and signed/unsigned tests.
-
Bug Fixes
- Improved handling of program counter updates based on new branching logic.
-
Refactor
- Streamlined control-flow logic by replacing legacy branch methods with more descriptive instruction names.
-
Tests
- Added comprehensive tests for branching scenarios, ensuring improved reliability under various conditions.