Repository navigation
simd: additive float/mask/integer API on every backend + IEEE bit-exact CI gate (+ wide/pulp inventory docs) - #435
Merged
Conversation
Feature matrix, ten tech-debt items and an ideas-to-steal table from six Haiku substrate-mapper runs, counts re-run by the orchestrator. Headline: AVX2 F64x8 compare/select are scalar loops (simd_avx2.rs:982, :1153); the root cause is a single u8 mask shape on every tier; F64x4 has no compares on any stable arm (F64Mask4 exists only in simd_nightly). Mandelbrot bench is prepared with pre-registered predictions, not yet run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
AdaWorldAPI
marked this pull request as ready for review
November 17, 2026 13:20
Codex Review Summary: ✅ CompletedThis 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. |
…ct runtime-dispatch row ndarray has src/simd_runtime/ (feature runtime-dispatch, one LazyLock fn pointer per op); the first revision said it had none — no mapper unit covered that directory. Adds the target_arch / target_feature coverage matrix (wasm, AMX, SVE, relaxed-simd, NEON tiers) and the bf16 comparison: wide has no bf16, pulp only feature tokens, ndarray hardware conversions plus AMX tiles but scalar-only simd_half and NEON stubs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
…AVX-512 first P0: finish F32x8/F64x4 (compares, min/max, mul_add) on every stable arm, masks that match each tier (vector on AVX2, kmask on AVX-512), and mask any/all/none. P1: masked tail load/store, float classification and reciprocals, widening/high-half multiply, AVX2 integer burn-down ordered by measured cost. P2: bf16 debt, AVX-512 FP16 probe, run-time dispatch per kernel. Each item names its witness; three operator questions are open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
…k API F1 (plan simd-fruits-integration-v1): F32x8/F64x4 gain compares, min/max/ clamp, sqrt, round (ties-even), floor, reduce_min/max and to_bits/from_bits on every stable arm, all AVX1 so one body serves AVX-512, AVX2 and AVX. New F32Mask8(__m256)/F64Mask4(__m256d) lane masks; F64Mask4 is no longer nightly-only. Scalar F32Mask8Scalar/F64Mask4Scalar renamed and exported. F2: AVX2 F32Mask16/F64Mask8 are pairs of those lane masks (fields private), so F32x16/F64x8 compare, select, min/max, sqrt, round, floor and reduce through two 256-bit ops instead of per-lane loops (removes the TD1 scalar compares at simd_avx2.rs:644/982/1153). AVX2 simd_min/max now use vminps/ vminpd, matching AVX-512 on NaN (second operand wins). F3: from_bitmask/any/all/none and & | ^ ! on every mask on every arm (simd_mask_api.rs macro for bitmask masks; by hand for vector masks; nightly gains none + operators). raster.rs mask_and uses a & b. Verified: lib tests native (AVX-512) 2743 and v3 2692 passed; new tests/simd_lane_masks.rs 7/7 on native, v3, avx, v2 and aarch64 (qemu); disable run (AVX2 to_bitmask <<4 -> <<3) turns 2 of them red; masking- parity native, wasm, wasm-scalar, neon-qemu, avx-qemu, v2-qemu PASS; clippy -D warnings, fmt and facet-stride guard clean; doctests 59 passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
…n all arms Plan simd-fruits-integration-v1 F5, drafted by one Sonnet worker per backend file (avx512, avx2, scalar, neon, wasm), reviewed and verified here. - classification composes the existing compares (x != x; |x| < inf; |x| == inf) - copysign: AVX-512 one vpternlog (imm 0xD8 = c ? b : a); AVX/AVX2 and/andnot/or; NEON vbslq; wasm v128_bitselect; scalar f32::copysign - recip: exact 1/x; recip_approx: vrcp14 (2^-14) on AVX-512 incl. VL 256-bit, vrcpps (1.5*2^-12) on AVX f32, exact elsewhere (documented per arm) - nightly backend gains the same six methods and the missing F64x4::from_bits Verified: tests/simd_float_classify.rs 3/3 on native(v4), v3, avx, v2, aarch64 (qemu) and nightly-simd; measured recip_approx worst rel. error v4 3.96e-5, v3 2.99e-4; disable run (copysign imm 0xE4) red; lib 2743 (v4) / 2692 (v3) passed; masking-parity wasm, wasm-scalar, neon-qemu PASS; F5 doctests 36/36 on v4 and v3; clippy -D warnings, fmt, facet-stride guard clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
Plan simd-fruits-integration-v1 F6 (drafted per backend file by Sonnet, reviewed and verified here; NEON I16x32 by the orchestrator). - mul_widen_even: exact u32*u32->u64 of the even lanes. AVX-512 vpmuludq; AVX2 two 256-bit vpmuludq, AVX-only arm four 128-bit SSE2; NEON vmovn_u64 + vmull_u32; wasm and-mask + i64x2_mul; nightly reinterpret+mask. - mul_high: vpmulhuw / vpmulhw (AVX-512BW, AVX2 256-bit, SSE2 128-bit); NEON I16x32 vmull_s16 + vshrn_n_s32::<16>; scalar and nightly widen-shift. - IFMA mul52 deferred (plan note): no non-IFMA realization fits R2 + W1a. Verified: tests/simd_widen_mul.rs 3/3 on native(v4), v3, avx, v2, aarch64 (qemu) and nightly-simd; disable run (AVX2 mulhi epu16 -> epi16) red; lib 2743 (v4) / 2692 (v3); doctests 6/6; masking-parity wasm, wasm-scalar, neon-qemu PASS; clippy -D warnings, fmt, facet-stride guard clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
…drift) F7 (plan simd-fruits-integration-v1, drafted by Sonnet, verified here): AVX2 U8x64::saturating_add/sub compose two native U8x32 halves (vpaddusb/vpsubusb); mask_blend(u64) expands the bitmask to MSB byte masks with a shuffle-free SWAR multiply and blends with two vpblendvb. Measured D-ADD-PM on a pinned v3 build (best of 50): add_pm 285.6 -> 48.6 ns per 64 lanes, sub_pm 289.6 -> 52.1 ns; the decode path stays ~133 ns, so AVX2 add_pm now beats it 2.7x. CI fixes for failures since the F1 commit: - tests/*, nostd, blas-msrv: without the SIMD modules are not built and impl_bitmask_mask_api was unused under -D warnings; the module is now cfg(feature = "std") and the macro allows unused. - realization/avx2: the mask-pair logic macro sat after GEN-TERNLOG-END, which tools/gen_ternlog_bodies.py owns; moved above BEGIN. Verified: tests/simd_u8x64_blend.rs 3/3 and add_pm 11/11 on native(v4), v3, avx, v2; lib 2743 (v4) / 2692 (v3); masking-parity native, avx-qemu, v2-qemu PASS; cargo check --no-default-features (+approx,serde) clean with -D warnings; gen_ternlog_bodies.py --check current; clippy, fmt and facet-stride guard clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
ndarray::simd exists only with std; the tests/1.99.0 CI row builds the integration tests with --no-default-features and failed on the new files. Same #![cfg(feature = "std")] as tests/add_pm.rs. Verified: cargo test --no-run --no-default-features with -D warnings builds clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
…ypes Plan simd-fruits-integration-v1 F4, drafted by Sonnet in one new file (src/simd_partial.rs), reviewed and verified here. load_partial(&[T]) takes lanes 0..min(len, LANES) and zero-fills the rest; store_partial(&mut [T]) writes only lanes 0..min(len, LANES). Types: F32x16, F64x8, F32x8, F64x4, U8x64, I32x16, U32x16. - AVX-512: _mm512_maskz_loadu_* / _mm512_mask_storeu_* with a low-n-bit k-mask (AVX-512BW for U8x64); masked-off lanes are never accessed. - AVX (F32x8 / F64x4): vmaskmovps / vmaskmovpd with an i < n lane mask. - every other arm/type: one copy_from_slice into a zeroed buffer + load. Verified: tests/simd_partial.rs 3/3 on native(v4), v3, avx, v2, aarch64 (qemu) and nightly-simd; disable run (mask enables lane n) crashes with SIGSEGV on the empty-slice case, so the correct mask provably never touches the dangling pointer; lib 2743 (v4) / 2692 (v3); doctests 14/14; masking- parity wasm, wasm-scalar, neon-qemu, avx-qemu PASS; clippy -D warnings, fmt, facet-stride guard, ternlog generator check and the no-default- features test build all clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
Operator ruling: breaking changes are not acceptable. This restores both exactly, keeping the vectorized internals. 1. AVX2 F32Mask16 / F64Mask8 are `pub u16` / `pub u8` bitmasks again, byte-identical struct definitions to master; hpc/splat3d/raster.rs is back to master. Compares still run per 256-bit half (vcmpp* packed with vmovmskp* via a crate-internal from_halves); select re-expands each half with F32Mask8/F64Mask4::from_bitmask and blends with vblendvp*. The new operators/any/all/none/from_bitmask come from impl_bitmask_mask_api!. 2. AVX2 simd_min / simd_max / reduce_min / reduce_max keep master's f32::min NaN semantics: the F32x8/F64x4 halves use vminp*/vmaxp* plus an unordered compare that blends in self where other is NaN; reductions are a NaN-ignoring tree and return +/-INFINITY for an all-NaN vector, the same as master's fold(INFINITY, f32::min). Verified: every pub fn/struct/type/use/mod/const line of master is present unchanged on the branch (14 files, 0 missing); new compatibility tests nan_min_max_reduce_* go red when the NaN blend is removed; lib 2743 (v4) / 2692 (v3); all five parity test files pass on native(v4), v3, avx, v2, aarch64 (qemu) and nightly-simd; masking-parity native, wasm, wasm-scalar, neon-qemu, avx-qemu, v2-qemu PASS; doctests 89/89; clippy -D warnings, fmt, facet-stride guard, ternlog generator check and no-default-features test build clean. Plan F2 and the blackboard record the correction and the additions-only rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
…every CPU Operator rule: every method is IEEE bit-exact and identical on every arm. recip_approx returned arm-dependent bits (1/3.0 gave 3eaaaa80 on AVX-512 vrcp14, 3eaaa000 on AVX vrcpps, 3eaaaaab on the exact arms), so it is removed from simd_avx512, simd_avx2, simd_scalar, simd_neon, simd_wasm and the nightly backend, with its tolerance test. recip (exact IEEE 1/x) stays. Plan F5 and the blackboard record the removal and the rule; plan F12 (fast/exact variants) is rejected for the same reason. Verified: the five parity test files pass on native(v4), v3, avx, v2, aarch64 (qemu) and nightly-simd; masking-parity wasm and neon-qemu PASS; clippy -D warnings, fmt and facet-stride guard clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
…aches; withdraw plan F8
The operator pointed at these as the pattern to learn from, not as code to
change. Blackboard entry states the pattern (widen once, compute exactly in
the wide type, one certified rounding at the edge, fallbacks bit-identical
to hardware, existing behaviour never altered). Plan F8 ("bf16 debt") is
marked withdrawn. No source file is touched.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
Adds check_ieee_bit_exact to crates/simd-masking-parity, the program every row of the SIMD realization matrix already runs. For F32x16, F64x8, F32x8 and F64x4 it compares + - * /, sqrt, single-rounded mul_add, round (ties to even), floor, abs, copysign, recip, the six compares, is_nan / is_finite / is_infinite and simd_min / simd_max lane by lane with the scalar IEEE operation (specials plus random bit patterns), and the slice add_mul_f32 / add_mul_f64 at ten remainder lengths. Every result is folded into an FNV-1a digest that must equal IEEE_GOLDEN, one constant for all realizations, so a green row proves the same bits as every other row. The native binary prints the digest. Not pinned (documented in the group comment): NaN sign/payload, min/max of +0 against -0, min/max with a NaN operand on the 512-bit types (pre-existing AVX-512 vminps behaviour, untouched), and reductions. Verified: digest 0xee52c9e7819d32c3 printed on native (v4), pinned v3, avx-qemu, v2-qemu, neon-qemu and nightly; wasm, wasm-scalar and wasm-relaxed return rc=0 against the same constant. Disable run: making F32x16::recip an estimate (vrcp14) fails with code 0xC00A. No library source is changed; the workflow file only gains a comment. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
AdaWorldAPI
pushed a commit
that referenced
this pull request
Nov 17, 2026
Adds section 7 to the wide/pulp comparison and a blackboard entry. AVX-512: all 30 probe symbols are identical before and after. AVX2: LLVM had already vectorized master's lane loops, so most of the F2 rewrite is neutral; the compares are 3 instructions longer; F64x8::reduce_min/max regressed 1.9x; real gains are U8x64::mask_blend (10x), F32x16 compare+select (2.4x) and F32x16 reductions (1.6x). Docs only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
AdaWorldAPI
pushed a commit
that referenced
this pull request
Nov 17, 2026
…_max PR #435 replaced it with a hand-written NaN-ignoring vminpd/vblendvpd tree through the 256-bit halves, which the before/after probe showed to be 1.9x slower (2.15 -> 4.03 ns per call, 21 -> 27 instructions). The original body, an iterator fold over the fixed-size lane array (the shape simd_ops is built on), lowers to a short vminsd chain. Results are bit-identical either way. Verified: probe back to ~2.0 ns and 21 instructions, result fingerprint unchanged; tests/simd_lane_masks (incl. the NaN compatibility tests) and simd_float_classify pass on v3 and avx; lib 2692 passed on v3; masking-parity with the IEEE digest passes on pinned v3 and avx-qemu; clippy, fmt, guard and the ternlog generator check clean. AVX-512 code is untouched. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW
AdaWorldAPI
added a commit
that referenced
this pull request
Nov 17, 2026
simd(avx2): fix F64x8::reduce_min/max regression from #435 + before/after disassembly write-up
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.
Implements P0 F1–F3 and P1 F4–F7 of
.claude/plans/simd-fruits-integration-v1.md. The plan came out of the wide/pulp comparison in.claude/knowledge/simd-crate-comparison-wide-pulp-2026-11-17.md, which is also in this PR.The contract this PR is held to
The SIMD facade is a polyfill: the same syntax and the same bits on every CPU, and existing behaviour never changes.
The reference for this pattern is the existing code:
BF16x16: bf16 is a storage format. Widening is lossless, and the single rounding step is certified byte-identical to the hardware instruction.add_mul_f32/add_mul_f64: arithmetic stays in the wide type, with one single-rounded FMA per lane. The tail gives the same bits as the body.as_chunks::<N>(): chunks are&[T; N], with no copy.None of that reference code is modified.
Additions
F32x8andF64x4get the full float API on every stable backend:F32Mask8/F64Mask4masks (F64Mask4was nightly-only before).F32x16/F64x8compare, select, min/max, sqrt, round and floor now run as two 256-bit operations instead of per-lane loops. Representation and results are unchanged.from_bitmask,any,all,noneand& | ^ !.is_nan,is_finite,is_infinite,copysign, andrecip(exact1/x).U32x16::mul_widen_even(returnsU64x8),U16x32::mul_highandI16x32::mul_high.load_partial/store_partialfor the chunk types. AVX-512 and AVX use masked memory operations; the other backends do one buffer copy.U8x64saturating add/sub andmask_blendare vectorized. D-ADD-PMadd_pmon a pinned v3 build went from 285.6 to 48.6 ns per 64 lanes.IEEE bit-exact gate in CI (
c05a872)crates/simd-masking-paritygains a 26th check group,check_ieee_bit_exact. Every row of the SIMD realization matrix already runs that program, so the gate applies to AVX2, AVX-512, host-native, AVX, x86-64-v2, NEON, wasm simd128, wasm scalar, wasm relaxed and nightly without a new job.F32x16,F64x8,F32x8andF64x4. Inputs are special values plus random bit patterns, including subnormals, NaN and Inf. The operations covered are:+ - * /,sqrt, single-roundedmul_add,round,floor,abs,copysign,recip;is_nan/is_finite/is_infinite;simd_min/simd_max;add_mul_f32/add_mul_f64at ten remainder lengths.IEEE_GOLDEN = 0xEE52_C9E7_819D_32C3. A green row therefore proves the same bits as every other row.recipinto an estimate fails with code0xC00A.Not pinned by the gate:
simd_min/simd_maxof+0against-0.simd_min/simd_maxwith a NaN operand on the 512-bit types. On AVX-512 these are the rawvminps/vmaxps(the second operand wins); the other backends ignore the NaN. This is master's behaviour, left untouched and only skipped by the gate. The 256-bit types are checked with NaN operands.reduce_sum: their summation order belongs to each backend.Corrections made during review
0553c7b: reverted two breaking changes from an earlier revision.F32Mask16(pub u16)/F64Mask8(pub u8)definitions are byte-identical to master again, andhpc/splat3d/raster.rsis unchanged from master.simd_min/simd_max/reduce_*keep master'sf32::minNaN semantics. Thenan_min_max_reduce_*tests pin this.e830466: removedrecip_approx. It was an estimate that returned different bits on different CPUs.pub fn/struct/type/use/mod/constline on master is still present unchanged (0 missing across the 14 changed source files).select. It loses nothing, but it is a pack-and-expand on every use.is_nanoranytakes precedence over a downstream trait method with the same name on these types.Verification (local, AVX-512 host)
tests/simd_{lane_masks,float_classify,widen_mul,u8x64_blend,partial}.rspass on native (v4), v3, avx, v2, aarch64 (qemu) and nightly-simd. Each feature has a deliberate-break run that fails.-D warnings, fmt, the facet-stride guard,tools/gen_ternlog_bodies.py --checkand the--no-default-featurestest build are all clean.Not done
🤖 Generated with Claude Code
https://claude.ai/code/session_01XAqKMQaYXab73XQdjqZfAW