Repository navigation
x86/tier1: honour the zero register and 32-bit forms in AND and ORR (shifted register) - #1
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
from
October 29, 2026 15:50
90b8cdd to
1572cdb
Compare
bluetoe-99
force-pushed
the
feature/tier1-logical-32bit-xzr
branch
from
October 29, 2026 15:50
8ec5c57 to
2b35652
Compare
bluetoe-99
force-pushed
the
feature/tier1-orr-shifted-register
branch
from
October 29, 2026 19:21
1572cdb to
145baf2
Compare
bluetoe-99
force-pushed
the
feature/tier1-logical-32bit-xzr
branch
from
October 29, 2026 19:21
2b35652 to
c0b0948
Compare
In the logical (shifted register) group a register field of 31 selects the zero register, not the stack pointer stored at guest slot 31, and a write to a 32-bit W register clears bits 63:32 of the 64-bit register. The AND handler read guest slot 31 for register operands and computed every result 64 bits wide, and the ORR handler had the same 32-bit gap; both silently corrupted guest state because the corpus seeds start with zeroed registers. AND now clears the destination when either source is the zero register. The 32-bit forms zero-extend their result with a 32-bit register copy; LSR zero-extends its source first, and ASR realigns bit 31 into the 64-bit sign position before a single SAR. Flag-setting forms needing 32-bit compare semantics, W-form shift amounts above 31, and W-form rotates needing a 32-bit rotate macro are rejected explicitly instead of being computed with 64-bit rules. Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
Ten tests exercise the zero-register sources, the discarded zero-register destination, and the 32-bit shift forms with non-zero state and a stack pointer deliberately set to a sentinel value that the old code would have read through register field 31. Two further tests cover the 32-bit ORR destination: an all-ones source pair must clear bits 63:32, and a left shift of a W register must drop the bits it shifts past bit 31. 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
bluetoe-99
force-pushed
the
feature/tier1-logical-32bit-xzr
branch
from
October 29, 2026 19:46
c0b0948 to
f3da7a0
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 this changes
The logical (shifted register) group (
AND0x8A...,ORR0xAA...,ANDS0xEA..., W-forms at sf=0) obeys two ARM rules that the Tier 1 handlers did not:cpu.x[31](ARM DDI0487, "Use of the zero and stack pointers").translate_and_regfed field 31 into register allocation, soAND X8, X9, XZRcomputedX9 & SP.translate_or_reg(added in upstream PR jit: translate ORR (shifted register) instead of a plain MOV pound-emu/ballistic#108) follows this rule but not rule 2, so this PR fixes its own gap too.AND W8, W9, W10, LSR #4slides stale upper-half bits into the result, and ASR sign-extends from bit 63 instead of bit 31.The differential corpus never flagged either bug because its seeds start with all registers zeroed. With real state these are silent wrong-value corruptions, the same class as upstream PR pound-emu#108.
Encodings that cannot be done correctly without machinery that does not exist yet are rejected explicitly (
BAL_ERROR_UNKNOWN_INSTRUCTION, same pattern as the AND-immediate reject in upstream PR pound-emu#108): W-formRORat any amount (a 32-bit rotate is not a truncated 64-bit rotate, and rotate-#0is reserved at sf=0, meaning ASR pound-emu#63 only in the 64-bit form), W-form shift amounts over 31 (undefined in the 32-bit encodings), and flag-setting forms that read XZR or use W-form (flags would need 32-bit compare semantics). These previously compiled with wrong 64-bit semantics. A clean skip is better than a silent wrong value.Tests
10 new AND tests and 2 new ORR tests exercise both rules with non-zero register state and a stack-pointer sentinel. Every new test is red on the old handler (
AND X8, XZR, XZRgivesSP & SP,AND W8, W9, W10keeps the upper half) and green after (0x80000010 ASR #4gives0xF8000001viaSHL #32plusSAR #(amount+32)).ctest: 16/16.No regressions (full corpus, same seeds.bin)
ANDS W...words, 2ANDS Xwords with a slot-31 source, 1AND W... ROR #0(reserved at sf=0). Each was probed against a worker rebuilt from the branch before these two commits (it compiled the word) and the post-change worker (it rejects cleanly). All were vacuous passes: with every corpus register zeroed, the 64-bit-rule garbage happened to match the reference. They are now honest skips. (Two more seeds,0A00FC00and6A00FC00, move from a logged Unicorn skip to the ballistic skip; counters unchanged.)Not touched
The 38 WIP failures, the 6 error seeds, and
src/generated/*. No decoder regeneration; the AND/ANDS W-entries already reachtranslate_and_regthrough the existingREGISTER_32guard.Follow-ups (out of scope)
W-form
RORand 32-bit flag-setting (they need 32-bit shift/compare macros), ANDS/BICS with XZR sources, OR/EOR (immediate) translation.