Skip to content

simx: clear bit 0 of the JALR target address (rebase of #339) - #396

Merged
tinebp merged 1 commit into
masterfrom
pr339-rebase
Aug 29, 2026
Merged

simx: clear bit 0 of the JALR target address (rebase of #339)#396
tinebp merged 1 commit into
masterfrom
pr339-rebase

Conversation

@tinebp

@tinebp tinebp commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Rebase of #339 by @cassuto onto current master — the original branch predates the 3.0 history rewrite and cannot be updated in place (its fix targeted the retired sim/simx/execute.cpp; the JALR execute path now lives in sim/simx/alu_unit.cpp).

What

  • Mask bit 0 of the SimX JALR target: warp.PC = (rs1 + imm) & ~1 (RISC-V ISA requirement).
  • Port of the conform test from Fix simx jalr target alignment #339: lands on an intentionally odd JALR target through an overlapped instruction word, so fixed and unfixed builds both decode valid instructions but produce different pass/fail signatures.

Verification (master @ 1c3403d)

  • Unfixed simx: conform fails with the bug signature (value=0x2468ace0); fixed simx: passes.
  • rtlsim (release): passes — release RTL already clears bit 0 implicitly via from_fullPC() PC truncation, so this also restores SimX↔RTL parity.
  • Full tests/regression simx suite: 81/81 pass with the fix applied.

Why CI never caught it

Only hand-written assembly can produce a misaligned JALR target (compilers never emit one), and no test exercised it. The conform test added here runs in CI via the kernel category (kernel.yaml: simx + rtlsim, both XLENs), closing the hole.

Commit is authored by @cassuto; closes #339.

🤖 Generated with Claude Code

The RISC-V ISA requires JALR to clear bit 0 of the computed target
(rs1 + imm). SimX carried the bit into the warp PC, while release RTL
builds drop it implicitly through from_fullPC() PC truncation - a
SimX<->RTL divergence reachable from hand-written assembly.

Adds a conform test that lands on an intentionally odd JALR target via
an overlapped instruction word, so fixed and unfixed builds both decode
valid instructions but produce different pass/fail signatures. Runs in
CI through the kernel category (simx + rtlsim, both XLENs).

Rebase of PR #339 (original targeted the retired sim/simx/execute.cpp).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@tinebp
tinebp merged commit d4fd7ee into master Aug 29, 2026
2 checks passed
@tinebp
tinebp deleted the pr339-rebase branch August 29, 2026 21:13
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