Skip to content

jit: sign-extend LDRSB/LDRSH/LDRSW destination loads - #3

Open
bluetoe-99 wants to merge 2 commits into
feature/engine-sized-guest-readfrom
feature/ldr-signed-extend
Open

bluetoe-99 wants to merge 2 commits into
feature/engine-sized-guest-readfrom
feature/ldr-signed-extend

Conversation

@bluetoe-99

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

Copy link
Copy Markdown
Owner

Tier 1 zero-extended every sized load, but the vendored ARM spec sign-extends the signed variants:

  • LDRSB: "loads a byte ... sign-extends it to either 32 bits or 64 bits"
  • LDRSH: "loads a halfword ... sign-extends it to 32 bits or 64 bits"
  • LDRSW: "loads a word ... sign-extends it to 64 bits"

The destination width is already in the decoder table: LDRSB/LDRSH have paired entries whose destination operand type carries the W/X split (for example 0x39800000 REGISTER_64 vs 0x39C00000 REGISTER_32), and LDRSW has a single REGISTER_64 entry. This replaces the truncation for those mnemonics with SHL (64-access_size_bits) plus SAR (both existing 64-bit macros, already used by the shifted-register logical translations), and reuses the existing 32-bit-move macro to stop the extension at bit 31 for W destinations.

Fuzzer (full corpus, same seed order as baseline): fixes 50 previously-failing seeds, 0 new failures, 0 new errors vs main.

This is stacked on feature/engine-sized-guest-read (fork PR #2 head): the hunk sits inside the translate_ldr region that the LDR pre/post and sized-guest-read chain rewrote, and it depends on that access-size scaling.

@bluetoe-99
bluetoe-99 force-pushed the feature/ldr-signed-extend branch from e7ac320 to bcc060b Compare October 29, 2026 15:50
@bluetoe-99
bluetoe-99 force-pushed the feature/engine-sized-guest-read branch from 3a5a81a to 646707a Compare October 29, 2026 15:50
@bluetoe-99 bluetoe-99 changed the title compiler: sign-extend LDRSB/LDRSH/LDRSW destination loads jit: sign-extend LDRSB/LDRSH/LDRSW destination loads Oct 29, 2026
@bluetoe-99
bluetoe-99 force-pushed the feature/engine-sized-guest-read branch from 646707a to c057245 Compare October 29, 2026 19:21
@bluetoe-99
bluetoe-99 force-pushed the feature/ldr-signed-extend branch from bcc060b to baa3092 Compare October 29, 2026 19:21
@bluetoe-99
bluetoe-99 force-pushed the feature/engine-sized-guest-read branch from c057245 to f6f6822 Compare October 29, 2026 19:46
@bluetoe-99
bluetoe-99 force-pushed the feature/ldr-signed-extend branch from baa3092 to b05a6f7 Compare October 29, 2026 19:46
The truncation block keyed only on the access-size field, so the
signed variants were zero-extended. The vendored spec sign-extends
them: LDRSB/LDRSH to 32 or 64 bits per the destination entry, LDRSW
always to 64. Shift the loaded sign into bit 63 and restore with SAR
(existing 64-bit macros); W destinations reuse the existing 32-bit
move to stop at bit 31.

Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
Seven cases over LDRSB/LDRSH/LDRSW with bit 7/15/31 set, covering both
destination widths, and unscaled pre-index writeback; positive-value
controls pin that non-negative loads are bit-identical to the old
masks.

Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com>
@bluetoe-99
bluetoe-99 force-pushed the feature/engine-sized-guest-read branch from f6f6822 to 45d9d99 Compare October 29, 2026 20:22
@bluetoe-99
bluetoe-99 force-pushed the feature/ldr-signed-extend branch from b05a6f7 to 2154396 Compare October 29, 2026 20:22
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