Skip to content

jit: translate ADD/SUB (shifted register) second operand - #109

Open
bluetoe-99 wants to merge 2 commits into
pound-emu:mainfrom
bluetoe-99:feature/tier1-add-sub-shifted
Open

bluetoe-99 wants to merge 2 commits into
pound-emu:mainfrom
bluetoe-99:feature/tier1-add-sub-shifted

Conversation

@bluetoe-99

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

Copy link
Copy Markdown

Tier 1 rejects every ADD/SUB (shifted register) encoding whose shift amount is non-zero ("does not support shift amounts != 0 yet"), so ADD X8, X9, X10, LSL #4, and shifted SUB, CMP, CMN too, never compile. These are some of the most common address-arithmetic forms in real AArch64 code.

This translates the shifted operand for 64-bit (X) operands the way translate_and_reg already does it: copy Rm into a scratch register and fold the shift there, so the guest Rm mapping survives. For the rd == 31 flags-only case the scratch holds the shifted operand, so the arithmetic folds into Rn's host copy and its mapping is invalidated. That is the same clobber trick the existing rd == rm subtraction collision uses.

Still cleanly rejected, unchanged: 32-bit (W) shifted operands (the shift macros do not do 32-bit windowing) and ROR or reserved shift types.

Part of #76.

Verification

  • Per the merge gate from [76] EMMISION:Translate shifted register [AND|ANDS] Rd, Rn, Rm #86 (Oct 8): "must first pass the fuzzer". This PR introduces zero new failures, see before/after below.
  • Full fuzzer before/after on de07fcaa: 465 | 38 failed | 28171 skipped | 6 errors becomes 473 | 38 failed | 28163 skipped | 6 errors. The 38-failure and 6-error seed sets are byte-identical.
  • All 14 shifted X-form add/sub words in the corpus now compile (was 0/14). Exactly 8 lie inside the fuzzer's error window, and the +8 pass delta maps to their seed indices (268, 269, 765, 766, 5393, 5394, 5485, 5486). The other 6 sit past the 6th error and are never counted.
  • New unit suite test_bal_tier1_add_sub.c (12 tests): LSL/LSR/ASR, LSL [ENGINE] Make Debugging Guest Code Easier Without GDB #63, rd == rm and rd == rn aliases, shifted CMP/CMN flag state with no-clobber sentinels on Rd, Rn and SP, and two unshifted regressions.
  • ctest green.

@bluetoe-99 bluetoe-99 closed this Oct 29, 2026
@bluetoe-99
bluetoe-99 deleted the feature/tier1-add-sub-shifted branch October 29, 2026 04:53
@bluetoe-99
bluetoe-99 restored the feature/tier1-add-sub-shifted branch October 29, 2026 04:56
@bluetoe-99 bluetoe-99 reopened this Oct 29, 2026
@bluetoe-99
bluetoe-99 force-pushed the feature/tier1-add-sub-shifted branch 2 times, most recently from 48edd76 to 9a7c193 Compare October 29, 2026 19:21
The add/subtract (shifted register) encodings were rejected whenever
the shift amount was non-zero, so ADD Xd, Xn, Xm, LSL #s - one of the
most common address-arithmetic forms in real AArch64 code - never
compiled, and shifted SUB, CMP and CMN failed the whole block too.

Fold the shifted operand into a scratch copy of Rm (the idiom
translate_and_reg uses) so the guest Rm mapping survives. For the
rd == 31 flags-only case the arithmetic folds into Rn's host copy and
its mapping is invalidated, the same clobber idiom the existing
rd == rm subtraction collision uses. 32-bit W shifted operands (the
shift macros do not perform 32-bit windowing) and ROR/reserved shift
types stay cleanly rejected.

Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
Twelve engine-level tests: LSL/LSR/ASR shifted operands including
LSL pound-emu#63, the rd == rm and rd == rn aliases, shifted CMP/CMN flag
state, no-clobber sentinels proving the scratch folding leaves Rd, Rn
and the stack pointer untouched, and two unshifted regressions.

Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
@bluetoe-99
bluetoe-99 force-pushed the feature/tier1-add-sub-shifted branch from 9a7c193 to 5f93db4 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