Skip to content

feat: add RISC-V 64-bit JIT backend#147

Closed
CN-TangLin wants to merge 3 commits into
qmonnet:mainfrom
CN-TangLin:feat/jit-multi-arch
Closed

feat: add RISC-V 64-bit JIT backend#147
CN-TangLin wants to merge 3 commits into
qmonnet:mainfrom
CN-TangLin:feat/jit-multi-arch

Conversation

@CN-TangLin

Copy link
Copy Markdown

Description

This PR adds a complete RISC-V 64-bit (rv64) backend for the JIT compiler.

Key Features

  • Full support for RV64 instruction set (ALU, ALU64, jumps, memory operations).
  • Two-pass compilation strategy (calculating instruction sizes, then emitting machine code).
  • Proper handling of BPF calling conventions and stack frame alignment.
  • Added zero-division protection for BPF_DIV and BPF_MOD.
  • Unified 32-bit zero-extension logic for ALU32 operations.

Testing

  • Passed existing architecture-independent tests.
  • Added 20 new #[cfg(target_arch = "riscv64")] specific unit tests for instruction generation validation.
  • Successfully integrated and tested within StarryOS (an OS kernel).

Looking forward to your review!

@qmonnet qmonnet left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, and thanks!

I haven't been through the code in details yet, but please:

  • Drop the formatting changes from your first commit, they don't seem relevant and they make it harder to review. If they come from rustfmt, I'm OK to take them, but as a separate commit.
  • Motivate the change in the second commit. Why do you need the jit module to be public? (The reason should also appear in the commit description)

The `jit` module is made public because it allows external crates (such as OS kernels integrating rbpf) to access the JIT compiler and structures like `JitMemory` directly, enabling custom JIT memory management or AOT compilation scenarios.
@CN-TangLin CN-TangLin force-pushed the feat/jit-multi-arch branch from 2197a55 to 5036199 Compare May 29, 2026 23:49
@qmonnet

qmonnet commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Thanks, the split will make it easier to review. I haven't had time to go through the details of the backend yet.

One question: Did you notice that there is a (not-really-documented) cranelift feature, which brings a JIT-compiler for the local architecture, and already has, as far as I understand, a backend for riscv64? Would it be enough for your use case, or is there a specific advantage to use a separate backend? I won't be able to really maintain the riscv64 JIT if it breaks so if this can be addressed with the existing feature, it would be just as well.

@CN-TangLin CN-TangLin closed this Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants