Skip to content

x86: model shift-count masking; opt-in masked-shift selection (#11, approved trusted-base change) - #32

Merged
AananthV merged 2 commits into
masterfrom
issue-11-shift-mask
Oct 22, 2026
Merged

AananthV merged 2 commits into
masterfrom
issue-11-shift-mask

Conversation

@AananthV

Copy link
Copy Markdown
Owner

Closes #11. Trusted-base change, approved by the owner, who applied approved: trusted-base on #11 and confirmed in chat.

Trusted part: exactly the approved text

The six *_rcl cases in x86/Asm.v now mask the shift count: 31 for sall/shrl/sarl, 63 for the q forms. I checked the diff line by line against the proposal posted on #11. Nothing else in trusted files changed except the flag line in extraction/extraction.v. No printer change.

Validation: asm_difftest group shift against the extracted new semantics: all counts 0..255 with garbage in the upper bits of %rcx, about 20k tests per instruction, 0 mismatches, 100% defined (previously 6–13% defined).

Verified part

  • New operators Oshlmask/Oshrmask/Oshrumask and their 64-bit variants, with masked semantics.
  • A selection rule behind -fshift-mask (off by default) for x << (y & 31) etc., including the low word of a 64-bit y & 31.
  • Asmgen emits the plain %cl shift.
  • Existing shifts are covered by a refinement lemma (shift_mask_lessdef).

Results

  • Flag off: generated code byte-identical on all test/c, big and PolyBench files.
  • With -fshift-mask: only nsievebits changes. It is −6.3% (interleaved timing, 94.1 → 88.2 ms).

Protocol checklist (#1)

  • Trusted files touched: x86/Asm.v (approved text), plus the flag line in extraction/extraction.v.
  • check_axioms.sh: adds only Compopts.optim_shiftmask.
  • make proof: x86_64 (clean rebuild), x86_32, aarch64, arm, powerpc, rv64.
  • make -C test all test: 154 passed, both by default and with CCOMPOPTS=-fshift-mask.
  • Ledger: entry 4 added to faster-compcert/TRUSTED_BASE.md.

Trusted-base change approved in issue #11: the variable-count shifts
Psall_rcl, Pshrl_rcl and Psarl_rcl now mask the count to 5 bits, and
Psalq_rcl, Pshrq_rcl and Psarq_rcl to 6 bits, as the hardware does
(Intel SDM, SAL/SAR/SHL/SHR).  This refines the previous semantics,
which were undefined for larger counts and agree elsewhere.

New operators Oshlmask/Oshrmask/Oshrumask and their 64-bit variants
have the masked semantics.  With -fshift-mask (off by default),
selection compiles x << (y & 31) and the like, including the low word
of a 64-bit y & 31, to them, and Asmgen emits the plain %cl shift
without the and.  The plain shift operators use the refined
instructions through a lemma that the masked result is at least as
defined as the unmasked one.

Without -fshift-mask the generated code is unchanged.  nsievebits:
-6.3% with the flag.
@AananthV
AananthV merged commit eff645e into master Oct 22, 2026
@AananthV
AananthV deleted the issue-11-shift-mask branch October 22, 2026 21:17
@AananthV AananthV mentioned this pull request Oct 22, 2026
16 of 17 tasks
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.

Model x86 shift-count masking in Asm semantics

1 participant