Skip to content

feat(vcr-ra): uxth/uxtb mask fold, flag-off (#428, #242)#480

Merged
avrabe merged 1 commit into
mainfrom
vcr-ra/uxth-fold
Jun 25, 2026
Merged

feat(vcr-ra): uxth/uxtb mask fold, flag-off (#428, #242)#480
avrabe merged 1 commit into
mainfrom
vcr-ra/uxth-fold

Conversation

@avrabe

@avrabe avrabe commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

The fourth gale-named hot-path lever (after cmp→select / local-promotion / immediate-shift). Flag-off (SYNTH_UXTH_FOLD=1 opt-in) ⇒ bit-identical, frozen gate green; the default-on flip is the separate on-target-gated step.

What

i32.and x 0xffff lowers to movw rM,#0xffff; and rD,rN,rM because 0xffff isn't a Thumb-2 modified immediate. The peephole folds that to uxth rD,rN (and the 0xff→uxtb form), dropping the dead movw — −1 instruction, −1 live register per mask.

How

  • New ArmOp::Uxth/Uxtb + Thumb-2 and ARM32 encoders (mirror Sxth/Sxtb; 16-bit form for low regs, .W otherwise). Encoding objdump-verified (uxth r3,r0 = 0xB283).
  • fold_uxth (liveness.rs): matches movw #0xffff|#0xff + AND (commutative — mask in either operand), rewrites to uxth/uxtb. Sound unconditionally (r & 0xffffuxth, rotation 0); removal-only + rewrite-in-place ⇒ offset-neutral. The movw is dead iff the AND writes back to the mask reg (the uxth redefines it — the common and r3,r0,r3 shape) or the mask is otherwise dead-after. 6 unit tests.

Verified

  • Frozen byte gate green — flag-off bit-identical (control_step 0x00210A55, flat+inlined flight_algo 0x07FDF307, div seam preserved).
  • Differential (uxth_fold_differential.py): flag-off (0 folds) == flag-on (2 folds) == wasmtime over 7 vectors via unicorn ARM execution. ORACLE: PASS.

Next in the feature loop: VCR-RA-002 (leaf prologue), #468 (base-CSE), #472 (RISC-V port).

Refs #428, #242

🤖 Generated with Claude Code

The selector lowers a 16/8-bit mask (`i32.and x 0xffff`) by materializing the mask
into a scratch register and using register-form AND, because 0xffff is not a
Thumb-2 modified immediate (`movw rM,#0xffff; and rD,rN,rM`). The new peephole
folds that to the dedicated zero-extend `uxth rD,rN` (and the 0xff/uxtb form),
dropping the dead movw — −1 instruction, −1 live register per mask. The fourth
gale-named hot-path lever after cmp→select / local-promotion / immediate-shift.

- New ArmOp `Uxth`/`Uxtb` + Thumb-2 and ARM32 encoders (mirror the existing
  Sxth/Sxtb; 16-bit form for low regs, .W otherwise). Encoding objdump-verified
  (`uxth r3,r0` = 0xB283).
- `fold_uxth` in liveness.rs: matches `movw #0xffff|#0xff` + AND (commutative —
  mask in either operand), rewrites to uxth/uxtb, drops the movw. Sound
  unconditionally (`r & 0xffff` ≡ uxth, rotation 0); removal-only + rewrite-in-place
  ⇒ offset-neutral. The movw is dead iff the AND writes back to the mask reg (the
  uxth redefines it) or the mask is otherwise dead-after — same scaffolding as
  fold_immediate_shifts. 6 unit tests (incl. the and-writes-back-to-mask common
  case + commutative + decline-on-non-mask-const + decline-when-live).

FLAG-OFF by default (opt-in `SYNTH_UXTH_FOLD=1`): off ⇒ bit-identical, frozen byte
gate green (control_step 0x00210A55 / flight_algo 0x07FDF307 / div seam preserved).
The byte-changing default-on flip is the separate on-target-gated step.

Validated: uxth_fold.wat + uxth_fold_differential.py — flag-off (0 folds) ==
flag-on (2 folds) == wasmtime over 7 vectors, unicorn ARM exec. ORACLE: PASS.

Refs #428, #242

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.16017% with 62 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/synth-backend/src/arm_encoder.rs 0.00% 30 Missing ⚠️
crates/synth-synthesis/src/liveness.rs 87.89% 23 Missing ⚠️
crates/synth-backend/src/arm_backend.rs 28.57% 5 Missing ⚠️
crates/synth-synthesis/src/optimizer_bridge.rs 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@avrabe avrabe merged commit dfa89d3 into main Jun 25, 2026
23 of 25 checks passed
@avrabe avrabe deleted the vcr-ra/uxth-fold branch June 25, 2026 05:03
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