Skip to content

[diskann-wide] AVX512/Neon popcount - #1310

Open
hildebrandmw wants to merge 4 commits into
mainfrom
mhildebr/popcount
Open

[diskann-wide] AVX512/Neon popcount#1310
hildebrandmw wants to merge 4 commits into
mainfrom
mhildebr/popcount

Conversation

@hildebrandmw

@hildebrandmw hildebrandmw commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Adds limited support for SIMD popcounts. These instructions are weird: AVX512-BITALG has great support, Neon only supports i8/u8, and AVX2 supports nothing. The decision made here is to only implement the SIMDPopcount trait when it maps to an instruction. Trying to emulate it on an op-level basis is disastrous for performance.

This is part of a small line of work adding better AVX-512 1-bit quantization.

AI Disclosure: the author is unable to efficiently type at the moment so had an agent do most of the work. The change set is largely mechanical.

@hildebrandmw
hildebrandmw requested review from a team and a lite review from Copilot August 4, 2026 21:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SIMDPopcount trait to diskann-wide and wires it through emulated/reference paths plus selected x86_64 AVX-512 and AArch64 Neon backends, enabling lane-wise popcount where hardware instructions exist (supporting upcoming 1-bit quantization work).

Changes:

  • Introduce and export SIMDPopcount, with implementations for Emulated and Doubled vector wrappers.
  • Add reference scalar “integer ops” helpers including expected popcount, and new popcount correctness tests.
  • Implement instruction-backed popcount for AVX-512 (avx512bitalg / avx512vpopcntdq) and Neon (vcnt*) vector types.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
diskann-wide/src/traits.rs Adds the public SIMDPopcount trait.
diskann-wide/src/lib.rs Re-exports SIMDPopcount from the crate root.
diskann-wide/src/reference.rs Renames/expands reference integer ops to include popcount expected results.
diskann-wide/src/emulated.rs Implements SIMDPopcount for the emulated backend via reference ops.
diskann-wide/src/doubled.rs Implements SIMDPopcount for Doubled<T> by delegating to halves.
diskann-wide/src/test_utils/ops.rs Adds test_popcount! and updates integer test bounds to ReferenceIntegerOps.
diskann-wide/src/arch/x86_64/v4/u8x64_.rs Adds AVX-512 byte popcount and tests.
diskann-wide/src/arch/x86_64/v4/u8x32_.rs Adds AVX-512VL byte popcount and tests.
diskann-wide/src/arch/x86_64/v4/u8x16_.rs Adds AVX-512VL byte popcount and tests.
diskann-wide/src/arch/x86_64/v4/i8x64_.rs Adds AVX-512 byte popcount and tests.
diskann-wide/src/arch/x86_64/v4/i8x32_.rs Adds AVX-512VL byte popcount and tests.
diskann-wide/src/arch/x86_64/v4/i8x16_.rs Adds AVX-512VL byte popcount and tests.
diskann-wide/src/arch/x86_64/v4/i16x32_.rs Adds AVX-512 word popcount and tests.
diskann-wide/src/arch/x86_64/v4/i16x16_.rs Adds AVX-512VL word popcount and tests.
diskann-wide/src/arch/x86_64/v4/i16x8_.rs Adds AVX-512VL word popcount and tests.
diskann-wide/src/arch/x86_64/v4/u32x16_.rs Adds AVX-512 dword popcount and tests.
diskann-wide/src/arch/x86_64/v4/u32x8_.rs Adds AVX-512VL dword popcount and tests.
diskann-wide/src/arch/x86_64/v4/u32x4_.rs Adds AVX-512VL dword popcount and tests.
diskann-wide/src/arch/x86_64/v4/i32x16_.rs Adds AVX-512 dword popcount and tests.
diskann-wide/src/arch/x86_64/v4/i32x8_.rs Adds AVX-512VL dword popcount and tests.
diskann-wide/src/arch/x86_64/v4/i32x4_.rs Adds AVX-512VL dword popcount and tests.
diskann-wide/src/arch/x86_64/v4/u64x4_.rs Adds AVX-512VL qword popcount and tests.
diskann-wide/src/arch/x86_64/v4/u64x2_.rs Adds AVX-512VL qword popcount and tests.
diskann-wide/src/arch/aarch64/u8x8_.rs Adds Neon byte popcount and tests.
diskann-wide/src/arch/aarch64/u8x16_.rs Adds Neon byte popcount and tests.
diskann-wide/src/arch/aarch64/i8x8_.rs Adds Neon byte popcount and tests.
diskann-wide/src/arch/aarch64/i8x16_.rs Adds Neon byte popcount and tests.
diskann-wide/src/arch/aarch64/double.rs Adds popcount tests for doubled Neon vectors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +527 to +531
/// Count the set bits in each lane.
///
/// This trait is only implemented for vector/architecture pairs that have native support
/// for popcounts.
pub trait SIMDPopcount {
Copilot AI review requested due to automatic review settings August 4, 2026 21:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 28 changed files in this pull request and generated no new comments.

Suppressed comments (1)

diskann-wide/src/traits.rs:531

  • The SIMDPopcount docs say it is only implemented for vector/architecture pairs with native popcount support, but the PR also implements it for Emulated<..> (and therefore Doubled<Emulated<..>>), which is not native SIMD popcount. Either adjust the docs to match the actual impl set, or remove the emulated impl if the intent is truly “native only”.
/// Count the set bits in each lane.
///
/// This trait is only implemented for vector/architecture pairs that have native support
/// for popcounts.
pub trait SIMDPopcount {

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.32258% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.47%. Comparing base (2ee97ff) to head (1ee7029).

Files with missing lines Patch % Lines
diskann-wide/src/doubled.rs 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1310   +/-   ##
=======================================
  Coverage   91.46%   91.47%           
=======================================
  Files         516      516           
  Lines       98276    98305   +29     
=======================================
+ Hits        89891    89922   +31     
+ Misses       8385     8383    -2     
Flag Coverage Δ
miri 91.47% <90.32%> (+<0.01%) ⬆️
unittests 91.14% <90.32%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
diskann-wide/src/arch/x86_64/v4/i16x16_.rs 57.14% <ø> (ø)
diskann-wide/src/arch/x86_64/v4/i16x32_.rs 57.14% <ø> (ø)
diskann-wide/src/arch/x86_64/v4/i16x8_.rs 57.14% <ø> (ø)
diskann-wide/src/arch/x86_64/v4/i32x16_.rs 30.76% <ø> (ø)
diskann-wide/src/arch/x86_64/v4/i32x4_.rs 57.14% <ø> (ø)
diskann-wide/src/arch/x86_64/v4/i32x8_.rs 30.76% <ø> (ø)
diskann-wide/src/arch/x86_64/v4/i8x16_.rs 40.00% <ø> (ø)
diskann-wide/src/arch/x86_64/v4/i8x32_.rs 33.33% <ø> (ø)
diskann-wide/src/arch/x86_64/v4/i8x64_.rs 40.00% <ø> (ø)
diskann-wide/src/arch/x86_64/v4/u32x16_.rs 42.85% <ø> (ø)
... and 13 more

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants