Skip to content

cpu: lower VEX.128 saturating, multiply and compare word forms - #1308

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
tedin7:x2w-c3-vex-words2
Nov 24, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
tedin7:x2w-c3-vex-words2

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

What

  • tools/cpu_vex_aot.py lowers ten more VEX.128 16-bit forms as explicit per-lane C++: vpaddsw, vpaddusw, vpsubsw, vpsubusw, vpmullw, vpmulhuw, vpmaxuw, vpminuw, vpcmpeqw, vpcmpgtw.
  • tests/cpu/vex_words.asm adds sat_words, mul_minmax_words and cmp_words (register and memory sources, both compare operand orders). vex_words.def and the export list in CMakeLists.txt gain the three names.
  • tests/cpu/vex_words_check.py compares the three new functions, native and lifted, with an independent per-lane integer model, in addition to the existing native vs lifted comparison (same 4096 edge and random pairs, guard zones, aliasing, RCX == RDX, misaligned buffers).
  • Negative control: the existing LOGICAL_SHIFT altered build also swaps vpmulhuw for vpmulhw in mul_minmax_words. Its lifted DLL must match the altered model and differ from the original in at least one output.
  • docs/experiments.md: supported forms, semantics note, new reference and control paragraphs.

Why

These forms were rejected as unsupported. Semantics are those of the integer instructions: signed and unsigned clamps, signed vs unsigned multiply high, unsigned min/max, compare masks of all ones or zeros. They read no MXCSR bits, raise no exceptions and have no NaN or signed-zero cases. VEX.128 zeroes the upper YMM bits, which the profile never reads (unchanged). No constant folding is used.

Overlap with open PR #1188 (cpu/vex-pf-consumers): it changes CMakeLists.txt (a different region, the cpu_vex_parity block), docs/experiments.md (new section at the end), tools/ffx_version_query.py, tools/x87_lower.py, tests/cpu/vex_parity.* and x87 tests. It does not touch tools/cpu_vex_aot.py or tests/cpu/vex_words*. No textual conflict expected beyond possible adjacent-hunk context in the two shared files.

Tested

Linux (this branch, commit 5bcba0c):

  • python3 -B tests/docs_links_check.py passed; python3 -B tests/bidi_controls_check.py passed.
  • python -m py_compile tools/cpu_vex_aot.py tests/cpu/vex_words_check.py passed.
  • vex_words_check.check_rejected_encodings() (the Linux-runnable part) passed: 9 rejected encodings.
  • The three new function bodies (plus the altered vpmulhw variant) were assembled with GNU as, run natively on an AVX2 host, lifted with cpu_vex_aot.lift, compiled with g++ and run through the check's inputs(): native, lifted and reference() agree on all 4096 pairs for each function; the altered native differs from the original model in 4071 of 4096.
  • Six translator mutations (vpmulhuw signed, vpaddusw unclamped, vpsubsw unclamped, vpmaxuw signed, vpcmpgtw unsigned, vpcmpeqw giving 1) each fail the model comparison.

Windows, not run locally:

cmake --build --preset dev --target cpu_vex_words_original_lifted cpu_vex_words_altered_lifted
ctest --preset dev --no-tests=error -R '^cpu_aot_vex_words$' -V

The Windows MSVC/ML64 test was NOT run locally. The full vex_words_check.py main path needs ML64-assembled DLLs and ctypes.windll, so it ran only in CI-style pieces above. The fixture was hand-mirrored to GNU as syntax for the Linux run, so the MASM source itself is unassembled until CI.

@tedin7
tedin7 marked this pull request as ready for review November 24, 2026 07:36
@tedin7

tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at 4f3a1320:

  • Debug (--preset dev): 5/5 PASS (1.10s: cpu_aot_vex_words 1.04s, plus cpu_aot_avx_int_regs, cpu_aot_avx_int_ymm_addsub, cpu_aot_avx_int_ymm_minmax, cpu_aot_avx_move_regs)
  • Release /O2 (--preset release): 5/5 PASS (1.14s, build 1.88s: cpu_aot_vex_words 0.84s, plus the 4 AVX suites)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T07:40:26.915278Z 4f3a132 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@R0Y00
R0Y00 merged commit 687312d into R0Y00:main Nov 24, 2026
5 checks passed
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.

2 participants