Repository navigation
Add U64x8::sum8_u8_add_masked, a vertical masked byte sum - #390
Merged
Merged
Conversation
Lane j gains the sum of the bytes 8j..8j+8 of a U8x64 whose keep bit is set, accumulated per lane with no horizontal reduction (vpsadbw on the kept bytes on x86, pairwise widening adds on NEON and wasm). Realized in every backend: AVX-512, AVX2, AVX, NEON, wasm, scalar and nightly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMjKnig6MXTd41Lf2v
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMjKnig6MXTd41Lf2v
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
October 29, 2026 21:12
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. |
# Conflicts: # .claude/blackboard.md
This was referenced Oct 29, 2026
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.
Summary
Adds one facade word,
U64x8::sum8_u8_add_masked, a vertical masked byte sum with one realization per backend. It was missing from the facade and was recorded as a gap in #389 (draft, probe).The word
Lane
jgains the sum of the bytesa[i],iin8j..8j+8, whose bitiinkeepis set.Why: candidate E in #389 needs a masked byte sum for the power-of-two anchor term. With
|b| = low7 + 128*bit7,a*|b| = a*low7 + 128*(sum of a where bit 7 of b is set). The facade only hadU8x64::sum_bytes_u64, which reduces horizontally on every call.Realizations
One per backend, no shared body.
simd_avx512.rs)_mm512_maskz_mov_epi8,_mm512_sad_epu8against zero,_mm512_add_epi64. Disassembly: kmovq, vmovdqu8 (zero-masked), vpxor, vpsadbw, vpaddq.simd_avx2.rs, not on the AVX-only arm)I32x16::dot4_u8_i8_add_masked(variable shift, multiply by 0x0101_0101, shift by 32, compare against BIT_IN_BYTE), AND,_mm256_sad_epu8,_mm256_add_epi64, two halves. LLVM emits 2 vpshufb while spreading the mask bytes; the source contains no shuffle, and the existing masked byte-dot lowers the same way.simd_avx.rs)mask_byte_spread,_mm_cmpeq_epi8, AND,_mm_sad_epu8per 16-byte quarter,_mm_add_epi64.simd_neon.rs)vtstq_u8mask frommask_byte_spread, AND,vpaddlq_u8,vpaddlq_u16,vpaddlq_u32,vaddq_u64. Cross-compiled assembly: uaddlp, uaddlp, uadalp (LLVM fused the final add into the accumulate). No scalar loop.simd_wasm.rs)mask_byte_spreadviai8x16_eq, AND,u16x8_extadd_pairwise_u8x16,u32x4_extadd_pairwise_u16x8; each u64 lane is(x & 0xFFFF_FFFF) + (x >> 32), added withi64x2_add. No shuffle.simd_scalar.rs)simd_nightly/u_word_types.rs)Mask::from_bitmask(keep).select(...), bytes reinterpreted as u64x8 viafrom_ne_bytes, SWAR fold (8 to 16 to 32 to 64 bits).Tests
In
src/simd.rs, moduledot4_nibble_facade_parity:sum8_masked_matches_reference: 57 byte vectors x 8 random masks x 5 mask patterns (0, all, alternating, 0x8000_0000_0000_0001, random) x 3 accumulators (0, u64::MAX, random). Over 5,000 checks; wrap is exercised.sum8_masked_gates_each_byte_by_its_own_bit: each of the 64 bits alone, and all-but-one.sum8_masked_all_kept_agrees_with_sum_bytes: equalsU8x64::sum_bytes_u64when all bytes are kept; 1,000 accumulating calls.Also:
crates/wasm-simd-parityandcrates/neon-simd-parity: code 0x506 (per-bit gating) and 0x507 (random corpus, including u64::MAX accumulators).Passed on: native AVX-512 VNNI, config-v4, config-v3 (AVX2), config-avx (qemu SandyBridge), config-v2 (scalar, qemu Nehalem), aarch64 (qemu), nightly-simd.
scripts/wasm-parity.shandscripts/neon-parity.shpass; NEON assembly rung 3 passes.Disable runs, each red:
Lint: clippy
-D warningsclean on native, v3, avx and aarch64; rustfmt clean. The facet-stride guard (no shuffle, no scalar loop in non-scalar backends, no u8/i8 mixing in added lines) reports nothing.Benchmark
Out-of-tree bench crate: 4,096 random byte vectors with random masks, medians of 1,001 runs, on an AVX-512 VNNI Xeon.
sum8_u8_add_masked, per 64 bytesNEON and wasm were not timed; qemu and node timings are not meaningful.
Consumer
examples/u9_abacus/anchor.rsin #389 (candidate E's anchor term). Not wired in this PR.Not in this PR
Generated by Claude Code