Skip to content

Add count_zeros() and count_ones() (lane-wise popcnt) - #345

Merged
Shnatsel merged 4 commits into
linebender:mainfrom
Shnatsel:simd-popcnt
Aug 25, 2026
Merged

Add count_zeros() and count_ones() (lane-wise popcnt)#345
Shnatsel merged 4 commits into
linebender:mainfrom
Shnatsel:simd-popcnt

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

The API mirrors std::simd. Unlike std::simd, we return Self from all vector types rather than creating an Unsigned associated type and returning that. The counts always fit into the signed values, and this simplifies generic code a lot. Vectors can be explicitly bitcast if the unsigned variant is needed.

The lowerings for u8/i8 and u64/i64 are identical to std::simd; for u16 and u32 we have 1.5x to 2x better throughput but worse latency (9 vs 7 cycles for u16, 14 vs 12 for u32), which seems fine for SIMD code.

Closes #341

@Shnatsel
Shnatsel added this pull request to the merge queue Aug 25, 2026
Merged via the queue into linebender:main with commit 0d2f8aa Aug 25, 2026
22 checks passed
@Shnatsel
Shnatsel deleted the simd-popcnt branch August 25, 2026 07:36
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.

lane-wise popcnt or count_ones

2 participants