Skip to content

fix(encoder): route AND/CMN immediates through ThumbExpandImm — close the class#266

Merged
avrabe merged 1 commit into
mainfrom
fix/close-dataproc-imm-class-and-cmn
Jun 5, 2026
Merged

fix(encoder): route AND/CMN immediates through ThumbExpandImm — close the class#266
avrabe merged 1 commit into
mainfrom
fix/close-dataproc-imm-class-and-cmn

Conversation

@avrabe

@avrabe avrabe commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

The last two unguarded data-processing immediate encoders:

  • AND.W immediate raw-packed i:imm3:imm8 (correct only <=0xFF, silently wrong above — the fold guard kept it in range, but the encoder itself was unsafe).
  • CMN.W immediate fell back to a silent 0xBF00 NOP for imm > 0xFF.

Both now go through the shared try_thumb_expand_imm (#255): encode any valid modified immediate correctly, else Err. This closes the silent-miscompile class across the whole data-proc immediate family — AND/ORR/EOR/CMP/CMN/ADD/SUB/ADDS/SUBS now share one correct, Ok-or-Err path (#251/#253/#255/#259 lineage).

Behavior-frozen

For imm <= 0xFF the encoding is byte-identical (try_thumb_expand_imm returns the same field), so folding output is unchanged — the three differentials stay result-identical (control_step 0x00210A55, flight_seam 0x07FDF307, div_const 338/338). Test and_cmn_immediate_thumb_expand_else_error: byte-range unchanged; a replicated modified immediate now encodes; 0x101 errors (AND was raw-pack, CMN a NOP).

Part of #242.

🤖 Generated with Claude Code

… the class

The last two unguarded data-processing immediate encoders:
- AND.W immediate raw-packed i:imm3:imm8 (correct only <=0xFF, silently wrong
  above — the fold guard kept it in range, but the encoder itself was unsafe).
- CMN.W immediate fell back to a silent 0xBF00 NOP for imm > 0xFF.

Both now go through the shared `try_thumb_expand_imm` (added in #255): encode any
valid modified immediate correctly, else `Err` (forcing register materialization).
This closes the silent-miscompile class across the whole data-proc immediate
family — AND/ORR/EOR/CMP/CMN/ADD/SUB/ADDS/SUBS now share one correct, Ok-or-Err
path (#251/#253/#255/#259 lineage).

Behavior-frozen: for imm <= 0xFF the encoding is byte-identical (try_thumb_expand_imm
returns the same field), so the cmp/cmn/and folding output is unchanged — the
three differentials stay result-identical (control_step 0x00210A55, flight_seam
0x07FDF307, div_const 338/338). Test and_cmn_immediate_thumb_expand_else_error:
byte-range unchanged, a replicated modified immediate now encodes, and 0x101
errors (AND was raw-pack, CMN was a NOP).

Part of #242.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@avrabe avrabe merged commit 4c3e6f6 into main Jun 5, 2026
@avrabe avrabe deleted the fix/close-dataproc-imm-class-and-cmn branch June 5, 2026 05:27
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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