Skip to content

fix(rsp): BREAK in a taken branch delay slot halts at the branch target - #43

Merged
doublegate merged 2 commits into
mainfrom
fix/rsp-status-and-break
Jul 22, 2026
Merged

fix(rsp): BREAK in a taken branch delay slot halts at the branch target#43
doublegate merged 2 commits into
mainfrom
fix/rsp-status-and-break

Conversation

@doublegate

Copy link
Copy Markdown
Owner

Motivation

Continues Phase 2 (§v0.3.0, RSP category Failed: 0). After the vector ISA
and the reserved VZERO family landed (#41, #42), the RSP category had three
non-vector failures left. This fixes one of them — RSP BREAK (within delay slot).

The bug

When a BREAK executes in the delay slot of a taken branch, the RSP halts
with the PC at the branch target, not the sequential address: the redirect the
branch already latched still wins. su_step was dropping the pending
after_delay target on the halt path and using BREAK's own sequential result,
so the suite's beq r0,r0,+6 -> break stopped at 0x8 instead of 0x1C.

The fix

The halt path uses after_delay.unwrap_or(next). A delay-slot BREAK after a
taken branch follows the branch; a plain BREAK, and a BREAK after an
untaken branch, still halt sequentially. Two regressions cover both
directions — the taken case reddens under the old set_pc(next).

Result

Suite-wide n64-systemtest failures drop 97 -> 96. The RSP category is now
down to the two RSP STATUS: start-valid tests, which are really RDP DPC
register-file tests (FREEZE bit, START/END/CURRENT, START_VALID state machine) —
substantial RDP work that belongs with the "RDP command list" criterion, tracked
as follow-up. Phase 1 categories remain at 0.

Gates run locally

cargo fmt --all --check, cargo clippy --workspace --all-targets -D warnings,
cargo test --workspace, RUSTDOCFLAGS=-D warnings cargo doc --workspace --no-deps, the no_std build, and pre-commit run markdownlint --all-files — all
green. The n64-systemtest runner confirms the 97->96 drop and Phase 1 at 0.

🤖 Generated with Claude Code

When a BREAK sits in the delay slot of a *taken* branch, the RSP halts with the
PC at the branch target, not the sequential address -- the redirect the branch
already latched still wins. `su_step` was discarding the pending `after_delay`
target on the halt path and using BREAK's own sequential result, so
n64-systemtest's `RSP BREAK (within delay slot)` (beq r0,r0,+6 -> break) stopped
at 0x8 instead of 0x1C.

The halt path now uses `after_delay.unwrap_or(next)`, so a delay-slot BREAK
follows the branch while a plain BREAK, and a BREAK after an *untaken* branch,
still halt sequentially. Two regressions cover both directions; the taken case
reddens under the old `set_pc(next)`.

Suite-wide n64-systemtest failures drop 97 -> 96 (the RSP category is now down
to the two RDP DPC-register `start-valid` tests). Phase 1 categories still 0.

Gates: fmt, clippy, workspace test, rustdoc, no_std, markdownlint green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: cecd3f38-5f98-4e8c-8309-5f9c9f980d74

📥 Commits

Reviewing files that changed from the base of the PR and between d4b291f and f2ed338.

📒 Files selected for processing (1)
  • docs/rsp.md

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Corrected program-counter handling when BREAK occurs in the delay slot of a taken branch, so halting now matches the branch target rather than the sequential address.
    • Kept existing behaviour for untaken branches, which still halt at the sequential address.
  • Tests
    • Added regression tests covering BREAK in taken vs untaken branch delay slots.
  • Documentation
    • Updated RSP documentation with the precise halt-location rule for BREAK in branch delay slots, including taken and untaken examples.

Walkthrough

The scalar unit now halts at a taken branch’s redirect target when BREAK executes in its delay slot. Regression tests cover taken and untaken branches, and the RSP specification documents the resulting PC behaviour.

Changes

BREAK delay-slot behaviour

Layer / File(s) Summary
Halt PC selection and regression coverage
crates/rustyn64-rsp/src/su.rs
BREAK prioritises the latched branch redirect when present, with tests covering redirected and sequential halt PCs.
RSP specification clarification
docs/rsp.md
Documents the halted PC for BREAK in taken and untaken branch delay slots.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 8 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title is correctly scoped and concise, but the subject is written in third-person present tense rather than imperative mood. Rewrite the subject in imperative form, for example: "fix(rsp): handle BREAK in taken branch delay slots".
Changelog Entry For User-Visible Changes ⚠️ Warning FAIL: the merge-base range does not touch CHANGELOG.md, though CONTRIBUTING.md says user-visible changes go under [Unreleased]. Add a short [Unreleased] bullet in CHANGELOG.md for this user-visible RSP BREAK delay-slot fix, matching the repo rule and PR template.
✅ Passed checks (8 passed)
Check name Status Explanation
Description check ✅ Passed The description matches the fix and regression coverage in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Oracle Number Is Stated ✅ Passed PASS: the PR description states the measured n64-systemtest effect (97 -> 96), and docs/rsp.md records the pinned taken/untaken oracle cases.
Docs-As-Spec Sync ✅ Passed PASS: crates/rustyn64-rsp/src/su.rs changes BREAK delay-slot behaviour and docs/rsp.md adds the matching spec rule in the same PR.
Measured, Never Tuned ✅ Passed PASS: no new measured constant/timing value was added; the delay-slot BREAK rule is backed by n64-systemtest and no accuracy-ledger entry was needed.
Unsafe Stays Out Of The Chip Crates ✅ Passed PASS: the diff only touches su.rs/docs; no unsafe syntax appears in the PR, and all chip/core crates still carry #![forbid(unsafe_code)].

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/rsp.md`:
- Around line 161-166: Add provenance for the BREAK delay-slot behavior
described in docs/rsp.md: either record the measurement, including its source,
in docs/accuracy-ledger.md and link the exact n64-systemtest case from this
passage, or replace it with a citation to the authoritative manual/wiki section
stating the rule. Ensure the SPEC text no longer presents the invariant without
a verifiable reference.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8df951d2-e2a2-4ff6-b48c-27da785e0635

📥 Commits

Reviewing files that changed from the base of the PR and between 7065ae9 and d4b291f.

📒 Files selected for processing (2)
  • crates/rustyn64-rsp/src/su.rs
  • docs/rsp.md

Comment thread docs/rsp.md Outdated
Adopts CodeRabbit's review comment on PR #43. The rule is an oracle-pinned
behaviour, not a measured timing constant, so it does not belong in
docs/accuracy-ledger.md; instead the SPEC text now names the exact
n64-systemtest cases (`RSP BREAK (within delay slot)` and its untaken sibling in
src/tests/rsp/op_break.rs) and the `su::tests` regressions that pin both
directions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@doublegate
doublegate merged commit 8c05cea into main Jul 22, 2026
9 checks passed
@doublegate
doublegate deleted the fix/rsp-status-and-break branch July 22, 2026 01:02
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.

1 participant