Repository navigation
simd: x86-64-v2 realization (SSE4.2 without AVX) via the scalar backend - #353
Merged
Merged
Conversation
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
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
Contributor
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (11)
✨ Finishing Touches
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 |
AdaWorldAPI
marked this pull request as ready for review
October 10, 2026 10:58
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_guardAVX2 startup floor. No runtime feature checks.What changes
all(target_arch = "x86_64", target_feature = "sse4.2", not(target_feature = "avx")). Reached withtarget-cpu=nativeon a v2-only CPU, or with the new.cargo/config-v2.toml(-Ctarget-cpu=x86-64-v2).simd.rssends this arm tosimd_scalar.rs. Every type insimd_avx2.rs/simd_avx512.rswraps 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.simd_scalar.rsgainsF32Mask16::to_bitmaskandunsafe F32x16::gather(same contract as the AVX2 polyfill). The onegathercall site, inhpc/cam_pq.rs, gets a// SAFETY:comment.cpu_guard: the AVX2 floor exemptssse4.2 && !avx2, which is exactly the AVX arm plus the v2 arm. The startup message namesconfig-v2.toml.simd_avx2directly now go through thecrate::simdfacade or are gated off v2. That includessimd_avx2's owntests,u8x32_testsandf16_precision_testsmodules.realization/v2row insimd-matrix.yaml, and av2-qemuarm inscripts/masking-parity.sh.Evidence
masking-parity.sh v2-qemupasses all 15 groups underqemu-x86_64-static -cpu Nehalem. The objdump witness finds no%ymm,%zmm, mask register or VEX op. Disable run: with thesimd.rsrouting reverted, the binary SIGILLs under Nehalem.simd_avx2's own test modules. No library path faulted. After gating them, the full v2 suite passes: 2474 passed, 0 failed, 31 ignored.-D warningsclean on v2, v3, v4, avx and baseline builds. Codegen witness avx2/avx512 PASS.cargo fmt --checkclean.gatherCONDITIONAL, satisfied by the call-site SAFETY comment;to_bitmaskPARITY-OK.Open
crate::simd_avx2stays public on v2 builds and nothing checks for AVX2 at startup there, so a direct caller SIGILLs. This is documented in thesimd.rsmodule doc; the safe path is thecrate::simdre-exports.Plan:
.claude/plans/simd-sse-v2-tier-v1.md.🤖 Generated with Claude Code
https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
Generated by Claude Code