Skip to content

simd: x86-64-v2 realization (SSE4.2 without AVX) via the scalar backend - #353

Merged
AdaWorldAPI merged 5 commits into
masterfrom
ccr-9f3b8075-74u47l
Oct 10, 2026
Merged

AdaWorldAPI merged 5 commits into
masterfrom
ccr-9f3b8075-74u47l

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

Adds a compile-time SIMD realization for x86-64-v2 builds: SSE4.2 without AVX (Nehalem/Westmere, Silvermont-class Atom, VMs that hide AVX). Baseline x86-64 builds (no SSE4.2) are unchanged: they keep the AVX2 arm and the cpu_guard AVX2 startup floor. No runtime feature checks.

What changes

  • Selection: all(target_arch = "x86_64", target_feature = "sse4.2", not(target_feature = "avx")). Reached with target-cpu=native on a v2-only CPU, or with the new .cargo/config-v2.toml (-Ctarget-cpu=x86-64-v2).
  • Routing: simd.rs sends this arm to simd_scalar.rs. Every type in simd_avx2.rs/simd_avx512.rs wraps a 256- or 512-bit register, so none can be the v2 realization; plain [T; N] arrays that LLVM compiles to SSE are used instead.
  • API gap: simd_scalar.rs gains F32Mask16::to_bitmask and unsafe F32x16::gather (same contract as the AVX2 polyfill). The one gather call site, in hpc/cam_pq.rs, gets a // SAFETY: comment.
  • cpu_guard: the AVX2 floor exempts sse4.2 && !avx2, which is exactly the AVX arm plus the v2 arm. The startup message names config-v2.toml.
  • Tests: tests that called simd_avx2 directly now go through the crate::simd facade or are gated off v2. That includes simd_avx2's own tests, u8x32_tests and f16_precision_tests modules.
  • CI: new realization/v2 row in simd-matrix.yaml, and a v2-qemu arm in scripts/masking-parity.sh.

Evidence

  • masking-parity.sh v2-qemu passes all 15 groups under qemu-x86_64-static -cpu Nehalem. The objdump witness finds no %ymm, %zmm, mask register or VEX op. Disable run: with the simd.rs routing reverted, the binary SIGILLs under Nehalem.
  • Per-test sweep of all 2541 v2 lib tests, each in its own process under Nehalem: 28 SIGILLs, all in simd_avx2's own test modules. No library path faulted. After gating them, the full v2 suite passes: 2474 passed, 0 failed, 31 ignored.
  • Clippy -D warnings clean on v2, v3, v4, avx and baseline builds. Codegen witness avx2/avx512 PASS. cargo fmt --check clean.
  • sentinel-qa: gather CONDITIONAL, satisfied by the call-site SAFETY comment; to_bitmask PARITY-OK.

Open

crate::simd_avx2 stays public on v2 builds and nothing checks for AVX2 at startup there, so a direct caller SIGILLs. This is documented in the simd.rs module doc; the safe path is the crate::simd re-exports.

Plan: .claude/plans/simd-sse-v2-tier-v1.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh


Generated by Claude Code

A build with sse4.2 but not avx (target-cpu=native on Nehalem/Westmere or
Silvermont, or the new .cargo/config-v2.toml) now takes simd_scalar.rs,
which LLVM vectorizes to SSE: the simd_avx2/simd_avx512 types wrap 256/512-bit
registers and cannot serve a build without AVX. Baseline builds (no sse4.2)
are unchanged and keep the AVX2 arm and its startup floor.

- simd.rs: the AVX2 arms and the x86 U8x32 export exclude the v2 arm; the
  scalar module and its full re-export list include it.
- simd_scalar.rs: F32Mask16::to_bitmask and F32x16::gather, the two x86 APIs
  x86-gated code uses (aabb.rs, cam_pq.rs); same contracts as the AVX2
  polyfill.
- cpu_guard: the AVX2 floor is exempt on the v2 arm too (the two exempt arms
  together are exactly sse4.2 without avx2); the message names config-v2.
- scripts/masking-parity.sh v2-qemu: config-v2 build under qemu -cpu Nehalem.

Plan: .claude/plans/simd-sse-v2-tier-v1.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
…l site

On the v2 arm the simd_avx2/simd_avx512 modules still compile but are not the
selected realization, so tests that call them directly fault (SIGILL) under
qemu -cpu Nehalem. saturating_abs_is_exact_for_all_256_i8_values now goes
through crate::simd and so tests every arm's own type; the two tests of
simd_avx2 items (dot_i8, the 256-bit integer methods) are gated off v2.

sentinel-qa (gather): CONDITIONAL on the pre-existing missing SAFETY comment
at cam_pq.rs's call site; added. The scalar gather docs now state that
offsets are signed, as the AVX2 docs do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
…ations

A per-test sweep of all 2541 lib tests under qemu -cpu Nehalem found 28
SIGILLs, all in simd_avx2's tests, u8x32_tests and f16_precision_tests,
which call AVX2 intrinsics directly. No library path faulted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: d9de9c29-7cb6-4631-9293-a21a2a0c861f

📥 Commits

Reviewing files that changed from the base of the PR and between db4daa8 and 6ca7efd.


📒 Files selected for processing (11)
  • .cargo/config-v2.toml
  • .claude/blackboard.md
  • .claude/plans/simd-sse-v2-tier-v1.md
  • .github/workflows/simd-matrix.yaml
  • CLAUDE.md
  • scripts/masking-parity.sh
  • src/cpu_guard.rs
  • src/hpc/cam_pq.rs
  • src/simd.rs
  • src/simd_avx2.rs
  • src/simd_scalar.rs

 ___________________________________
< Mission: Impossible - Rogue Code. >
 -----------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.


Comment @coderabbitai help to get the list of available commands.

@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review October 10, 2026 10:58
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@AdaWorldAPI
AdaWorldAPI merged commit baeac24 into master Oct 10, 2026
27 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