Repository navigation
simd: saturating narrows down the 512-bit ladder (16x32 -> 32x16 -> 64x8) - #372
Conversation
…ly casts The codec8 encode composes from the polyfill: Div, round (ties-even), floor, simd_clamp, abs, simd_ge, select and the F32x16/I32x16 casts already exist on every stable arm. Two pieces did not: - I32x16::narrow_saturate_i8 -> I8x16 and narrow_saturate_u8 -> U8x16, on all six I32x16 owners, each with its ISA's saturating pack: AVX-512 vpmovsdb / vpmovusdb (lanes raised to 0 first, the unsigned form reads them unsigned), AVX2 and AVX-only SSE2 packssdw + packsswb / packuswb, NEON sqxtn / sqxtun, wasm i16x8_narrow_i32x4 + i8x16_narrow_i16x8 / u8x16_narrow_i16x8, scalar clamp, nightly simd_clamp + cast. - The nightly realization lacked F32x16::cast_i32 and I32x16::cast_f32, which every other arm has. simd-masking-parity group 0x10xx checks both narrows against clamp over 513 vectors (edges plus random, with an anti-vacuity floor on saturated lanes in both directions), cast_f32 against 'as f32' bits and cast_i32 against 'as i32' on in-range lanes. Passes on all eight realizations: AVX-512, AVX2, AVX-only (qemu SandyBridge), v2/scalar (qemu Nehalem), NEON (qemu), wasm simd128 and wasm scalar (node), nightly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Add Carrot credits or activate Agent usage billing to use Autofix |
|
This PR merged at e07be5b, which has the off-ladder Generated by Claude Code |
Summary
The codec8 SIMD path needs the saturating narrows from i32 to i16 and from i16 to i8/u8. This adds them as steps on the 512-bit ladder (16×32, 32×16, 64×8), on every backend:
I32x16::narrow_saturating_i16(hi) -> I16x32I16x32::narrow_saturating_i8(hi) -> I8x64I16x32::narrow_saturating_u8(hi) -> U8x64Lanes
0..Ncome fromselfandN..2Nfromhi. Each lane is clamped to the narrow range.The first version of this PR narrowed
I32x16 -> I8x16/U8x16. That is a 128-bit result and is not on the ladder, so it is replaced here.vpmovsdw/vpmovswb/vpmovuswb, thenvinserti64x4(u8 first raises negative lanes to 0)packssdw/packsswb/packuswbover 16-byte quarterssqxtn/sqxtun+vcombinei16x8_narrow_i32x4,i8x16_narrow_i16x8,u8x16_narrow_i16x8clampsimd_clamp+castTwo backend notes:
I16x32/I8x64/U8x64come from the scalar backend on wasm. Their narrows are therefore implemented insimd_wasm.rs, and the scalar versions are cfg-gated off for that arm.I16x32/I8x64(+i16x32/i8x64).simd_neon.rsalready had both types, but no arm re-exported them.Nightly also keeps
F32x16::cast_i32and gainsI32x16::cast_f32, which the other backends already had.Verification
0x10xxinsimd-masking-parity:as;0x1080, the u8 lane holdingi32::MIN.#[inline(never)]wrappers, release):vshufi64x2+ onevpackssdw/vpacksswb/vpackuswbper narrow. LLVM folded themax+vpmovuswbintovpackuswb.cargo clippy --lib -D warningsis clean on v4 and v3. The 6 new doctests pass (v4, release).Not in this PR
The wasm
F32x16::mul_add/F64x8::mul_addfix comes in its own PR. Today those are unfused (two roundings), or nondeterministic underrelaxed-simd.🤖 Generated with Claude Code
https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg