Skip to content

Conversation

@jserv
Copy link
Contributor

@jserv jserv commented Jan 5, 2026

This refactors JIT code generation by:

  1. Simplifying RVOP macro from 3 to 2 parameters, removing now-unused DSL-based GEN blocks from rv32_template.c. This eliminates ~1300 lines of dead code that was obsoleted when rv32_jit.c was added (commit 9cd48ea).
  2. Introducing JIT helper macros in rv32_jit.c to reduce duplication:
    • GEN_BRANCH/GEN_CBRANCH for conditional branches
    • GEN_ALU_IMM/GEN_ALU_REG for arithmetic operations
    • GEN_SHIFT_IMM/GEN_SHIFT_REG for shift operations
    • GEN_SLT_IMM/GEN_SLT_REG for set-less-than operations
    • GEN_LOAD/GEN_STORE for memory operations with MMIO support
  3. Adding symbolic constants (JCC_*) in jit.h for jump condition codes, improving cross-architecture clarity.
  4. Removing the deprecated gen-jit-template.py that was no longer used after the manual JIT handler approach was adopted.

The interpreter and JIT now have clear separation of concerns:

  • rv32_template.c: Pure interpreter semantics
  • rv32_jit.c: Native code generation with helper macros

Close #511


Summary by cubic

Refactors Tier-1 JIT codegen to use shared helper macros and symbolic jump codes, simplifying the interpreter API and clearly separating interpreter semantics from native code generation. This reduces duplicated code and improves cross-architecture clarity (x86-64 and Arm64).

  • Refactors
    • Simplified RVOP from 3 to 2 parameters; removed obsolete DSL GEN blocks in rv32_template.c.
    • Added JIT helper macros in rv32_jit.c (branches, ALU imm/reg, shifts imm/reg, slt imm/reg, load/store with MMIO).
    • Introduced JCC_* constants in jit.h for condition codes used by both architectures.
    • Removed deprecated tools/gen-jit-template.py.
    • Added docs/codegen.md covering tiers, emit API, register allocation, and MMIO handling.
    • Established clear file roles: rv32_template.c for interpreter; rv32_jit.c for native codegen.

Written for commit d8129e5. Summary will update on new commits.

This refactors JIT code generation by:
1. Simplifying RVOP macro from 3 to 2 parameters, removing now-unused
   DSL-based GEN blocks from rv32_template.c.
   This eliminates ~1300 lines of dead code that was obsoleted when
   rv32_jit.c was added (commit 9cd48ea).
2. Introducing JIT helper macros in rv32_jit.c to reduce duplication:
   - GEN_BRANCH/GEN_CBRANCH for conditional branches
   - GEN_ALU_IMM/GEN_ALU_REG for arithmetic operations
   - GEN_SHIFT_IMM/GEN_SHIFT_REG for shift operations
   - GEN_SLT_IMM/GEN_SLT_REG for set-less-than operations
   - GEN_LOAD/GEN_STORE for memory operations with MMIO support
3. Adding symbolic constants (JCC_*) in jit.h for jump condition codes,
   improving cross-architecture clarity.
4. Removing the deprecated gen-jit-template.py that was no longer used
   after the manual JIT handler approach was adopted.

The interpreter and JIT now have clear separation of concerns:
- rv32_template.c: Pure interpreter semantics
- rv32_jit.c: Native code generation with helper macros

Close #511
@jserv jserv requested a review from vacantron January 5, 2026 01:59
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 7 files

Copy link
Contributor Author

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Benchmarks

Details
Benchmark suite Current: d8129e5 Previous: 5326a16 Ratio
Dhrystone 1901 Average DMIPS over 10 runs 1606 Average DMIPS over 10 runs 0.84
Coremark 1016.605 Average iterations/sec over 10 runs 958.749 Average iterations/sec over 10 runs 0.94

This comment was automatically generated by workflow using github-action-benchmark.

@jserv jserv added this to the release-2026.1 milestone Jan 5, 2026
@jserv jserv merged commit 399e657 into master Jan 8, 2026
23 checks passed
@jserv jserv deleted the refine-codegen branch January 8, 2026 06:50
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.

jit: Refine code generation

2 participants