Repository navigation
jit: translate ORR (shifted register) instead of a plain MOV - #108
Open
bluetoe-99 wants to merge 2 commits into
Open
bluetoe-99 wants to merge 2 commits into
bluetoe-99 wants to merge 2 commits into
Conversation
bluetoe-99
force-pushed
the
feature/tier1-orr-shifted-register
branch
2 times, most recently
from
October 29, 2026 02:37
a2dedd7 to
90b8cdd
Compare
bluetoe-99
force-pushed
the
feature/tier1-orr-shifted-register
branch
2 times, most recently
from
October 29, 2026 19:21
1572cdb to
145baf2
Compare
The decoder table generator maps every entry named ORR to OPCODE_MOV, so translate_mov_register compiled genuine three-operand ORR Xd, Xn, Xm words as a plain register copy, silently discarding the second source operand. Only the MOV (register) alias encodings (Rn = XZR) were handled correctly by that path. Dispatch ORR-named entries carrying a register operand at bit 5 to a new translate_or_reg handler implementing the logical shifted-register semantics. Field 31 reads as the zero register (not SP) per the group's semantics, matching ARM's behaviour for XZR sources and a discarded XZR destination. ORR (immediate) now aborts the block with a clear diagnostic instead of silently miscompiling as a MOV, mirroring the existing AND (immediate) guard. OR (immediate) support and latent XZR/W-form issues in translate_and_reg are left as follow-up work. Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
Nine engine-level Unity tests that compile and execute single-ORR blocks with non-zero register state: general three-register combine, LSL pound-emu#4 shift, destination aliasing (rd == rm uses the pre-shift value, rd == rn), writes to XZR discarded, XZR sources read as zero rather than the stack-pointer slot, and both-sources-zero clearing. The differential fuzzer cannot catch the miscompile this guards against: its seeds execute with zeroed registers and vary one operand field at a time, so both sources were never simultaneously non-zero and 0 | 0 compares equal to the broken copy. Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
bluetoe-99
force-pushed
the
feature/tier1-orr-shifted-register
branch
from
October 29, 2026 19:46
145baf2 to
4b7a2dd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is broken
Silent miscompile of
ORR(shifted register) in the x86 Tier 1 JIT.The decoder-table generator gives
OPCODE_MOVto every entry namedORR, becauseMOV Xd, Xmis encoded asORR Xd, XZR, Xm. Sotranslate_mov_registercompiled real three-operand words likeORR X8, X9, X10(0xAA0A0128) as a plain copyX8 = X9, silently droppingX10. No exception, no reject: just a wrong guest register value that shows up later as an unrelated crash.The differential fuzzer cannot catch this kind of bug. Its seeds run with all registers zeroed and each seed varies only one operand field at a time (
REGISTER_SEEDS = {0,1,15,30,31}), so both source registers are never non-zero at the same time, and0 | 0compares equal to the broken copy.Proof (tests passed)
New engine-level Unity suite
tests/unit/bal_tier1/test_bal_tier1_orr.ccompiles and runs single-ORR blocks with non-zero register state.ORR X8, X9, X10returns exactly X9's value (X10 is never read).0xAA0A0128before the fix: only X8's guest slot is touched, no load of X9 or X10, no OR instruction anywhere.mov r0, [rbp+0x48](X9),mov r1, [rbp+0x50](X10),mov r2, r0,or r2, r1, storer2to[rbp+0x40](X8).-Werror -Wconversion -Wsign-conversion.ctest15/15 pass.60389 seeds | 465 passed | 38 failed | 28171 skipped | 6 errors, same 38 failing seeds, same per-seed mismatch counts (pre-existing LDR register-offset/writeback and LDRAA/LDRAB failures, untouched by this PR).bal_fuzzer_worker_ballistic 0xB2401128(a true ORR-immediate) now aborts the block with a clear log line instead of silently compiling as a MOV.What the change does
case OPCODE_MOV, entries namedORRthat carry a REGISTER operand at bit position 5 dispatch to a newtranslate_or_reg. The MOV-alias entries keepoperands[1]at bit 16, so that check separates them cleanly. No decoder-table regeneration needed.translate_or_regimplements logical shifted-register semantics, including field 31 being the zero register, not SP.allocate_x86_registerloads guest slot 31 as the stack pointer, so the handler has to deal with XZR explicitly: Rn/Rm = 31 reads as zero, Rd = 31 discards the result. This also makes MOV-alias words compile correctly, since the decoder lookup returns the 3-operand entry for them.rd == rn,rd == rm) reuses already-loaded values, andrd == rmshifts use the pre-shift source. Because OR is commutative, therd == rncase needs no scratch register.0xB2000000/0x32000000base forms) now returnsBAL_ERROR_UNKNOWN_INSTRUCTIONwith a log line instead of miscompiling, the same explicit-reject pattern already used for AND (immediate). Seeds hitting it move from "passing with wrong semantics" to cleanly skipped.Left out on purpose
Found while working here, kept out to keep this PR small:
translate_and_reghas the same XZR bug (reads slot 31 as SP). Fixing it changes AND-alias behaviour and deserves its own tests and PR.OPCODE_MOValias mapping is the root cause of this whole bug class. An eventual table-level fix (separate opcodes per alias family) would remove the need for name checks entirely.Tests added
9 Unity tests: general combine, LSL #4,
rd == rmuses the pre-shift value,rd == rn, write to XZR discarded, XZR source reads as zero and not SP (an SP-slot sentinel proves it),rm == XZRkeeps rn, both sources XZR clear the destination, XZR-shaped alias word still copies correctly.Diff: +426 / -1, 3 files.