[go: up one dir, main page]

RISC-V: Deduplicate `Add` and `C.Add` OpCodes.

Closes RV-421

What

Deduplicate ADD and C.ADD OpCodes.

ADD deduplicates into LI rd, 0 for the case where both inputs are x0, and into MV rd, rs1 for the case where either is x0. When both input registers are non-x0, we have a fully NonZeroXRegister ADD.

C.ADD deduplicates into ADD rd_rs1, rd_rs1, rs2 with all NonZeroXRegister.

NB: This removes the recent work in moving C.ADD into the ICB, but going forward it is better to combine into add for reducing the number of JIT implementations needed.

Why

Part of the opcode refinement work. These opcodes overlap in resulting states after translation, making them good candidates for grouping.

How

Introduce a new args constructor that removes XRegister from the parsing of ADD. Remove CADD from the list of internal opcodes, as it will now be ran as ADD rd_rs1, rd_rs1, rs2, since now run_add only takes NonZeroXRegister inputs.

Manually Testing

make -C src/riscv all

Benchmarking

master This MR Improvement
M3 MBP 5.982 TPS 5.999 TPS 0.28%
Benchmark Machine 3.452 TPS 3.476 TPS 0.70%

Regressions

Previously Add and CAdd instructions have both changed representation in the block cache.

Those that were previously Add will now either have a different opcode Li and/or have XRegister changed to NonZeroXRegister, which has a different representation in the hash.

Those that were previously CAdd will now be Add, with rs1 also now being a used field rather than the default, meaning these will also change in the block cache, hence a hash change in both commits.

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/riscv
    • dune build src/lib_riscv
    • dune 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.
Edited by Neelay Sant

Merge request reports

Loading