logoalt Hacker News

camel-cdr11/20/20243 repliesview on HN

nth_set_bit_u64: wouldn't that be __builtin_ctzll(_pdep_u64(1<<n, v)) with BMI2?


Replies

kwillets11/21/2024

That's my guess as well.

Bitstring rank/select is a well-known problem, and the BMI and non-BMI (Hacker's Delight) versions are available as a reference.

SkiFire1311/20/2024

That's assuming you're ok with your program not running on some older cpus.

show 1 reply
stouset11/21/2024

I believe the equivalent ARM64 instructions are in SVE2 which isn’t yet supported on Apple’s M-series chips as of M4, sadly.