Skip to content

jit: implement LDR pre-/post-index writeback and scale imm12 by access size - #110

Open
bluetoe-99 wants to merge 3 commits into
pound-emu:mainfrom
bluetoe-99:feature/tier1-ldr-prepost-index
Open

bluetoe-99 wants to merge 3 commits into
pound-emu:mainfrom
bluetoe-99:feature/tier1-ldr-prepost-index

Conversation

@bluetoe-99

@bluetoe-99 bluetoe-99 commented Oct 29, 2026 •

Copy link
Copy Markdown

translate_ldr ignored the addressing-mode bits: every immediate-offset load ran as a plain load with no base update, and the unsigned offset was scaled by the destination width instead of the access size.

Now:

  • imm9 group (operands[2] = immediate at bit 12, width 9): imm9 is sign-extended and unscaled. Post-index (bits 11-10 = 01) loads at the base address, pre-index (= 11) at base + imm9, and both update Rn = base + imm9.
  • LDRAA/LDRAB (same imm9 position): load at base + ZeroExt(imm9) << 3, matching the reference engine and the architecture (the offset is scaled by 8, and Rn is updated only in the pre-index form). Pointer authentication is still not applied, the load executes plain.
  • imm12 group (operands[2] = immediate at bit 10, width 12): scaled by the access size from bits 31-30 (1/2/4/8), not by the destination width.
  • The Rn update is computed into a scratch register from the original base before the store to Rt and applied after it, so Rt == Rn resolves to the updated base. The architecture calls that case (writeback register equal to the destination) CONSTRAINED UNPREDICTABLE; resolving it as "the base update wins" matches the reference engine.
  • Register-offset entries (immediate index flag at bit 12) keep the existing lowering. How that group models Rm is a separate known issue.

fuzzer: skip seeds the oracle cannot execute before counting Ballistic errors

The driver checked Ballistic's status before the oracle's. Seeds where both engines fault (e.g. reads ending past the guest page) were counted as errors even though the oracle refused to run them. Checking the oracle first makes the skip symmetric with the existing unknown-instruction rule.

tests

16 unit tests (Rt==Rn pre/post, LDRAA/LDRAB pre/post, imm12 byte/halfword/word scaling). Each form runs with distinct non-zero base and destination registers and a sentinel destination, so the writeback value and the loaded value can never accidentally come out equal.

Fuzz (full 60389-seed corpus, same seeds.bin for both runs):

  • main de07fcaa: 465 passed | 38 failed | 28171 skipped | 6 errors
  • this branch: 707 passed | 26 failed | 28253 skipped | 6 errors

Every mismatch seed this branch reports was replayed through main's build: all 26 failures and all 5 non-baseline error seeds fail identically on unmodified main (they sit after the driver's 6-error stop in main's run). All 16 unique mismatch seeds main reports are fixed; 1 of main's 6 errors is fixed (395FFC00) and 4 become oracle skips. No seed that main passes is newly failing or newly erroring. The remaining 397FFC00 error: guest_read has no size argument and always reads 8 bytes, follow-up.

translate_ldr ignored the addressing-mode bits: every immediate-offset
load executed as a plain load with no base update, and the unsigned
imm12 offset was scaled by the destination width instead of the
access size.

Imm9 group: imm9 is sign-extended and unscaled; post-index loads at
the base address and pre-index at base + imm9, both updating
Rn = base + imm9. LDRAA/LDRAB scale the offset by 8 and update Rn only
in the pre-index form (pointer authentication is still not applied).
Imm12 group: scale by the access size from bits 31-30 (1/2/4/8). The
Rn update is computed into a scratch register from the original base
before the Rt store and applied after it, so Rt == Rn resolves to the
updated base, matching the reference engine's choice for this
CONSTRAINED UNPREDICTABLE case. Register-offset entries keep their
existing lowering; that group's Rm modelling is a separate issue.

Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
Sixteen tests cover Rt == Rn in both pre- and post-index form,
LDRAA/LDRAB with and without writeback, and imm12 byte, halfword and
word scaling. Every form runs with distinct non-zero base and
destination registers and a sentinel destination, so the writeback
value and the loaded value can never coincide by accident.

Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
The driver checked Ballistic's status before the oracle's, so seeds
where both engines fault (e.g. a read ending past the guest page)
were counted as Ballistic errors even though the reference oracle
refused to run them. Checking the oracle first makes the skip
symmetric with the existing unknown-instruction rule.

Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
@bluetoe-99
bluetoe-99 force-pushed the feature/tier1-ldr-prepost-index branch from 877a93a to 38a2bc3 Compare October 29, 2026 19:46
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