Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why popcount?


popcount is extremely useful in a lot of algorithms, from RSA to chess engines to sparse arrays and tries

it's honestly pretty baffling that RISC-V doesnt have it (perils of design-by-academia)


The RISC way is to prove the exception is worth it. There are a lot of possible specialized instructions that are useful for some workloads.


ARM has it. DEC Alpha had it (before x86, even).

I get that there are a lot of narrow-use instructions but popcount is a pretty well-known and common operation.


In the Alpha case it was a very late addition, in the last widely shipping version of the chip and IIRC was speculated to be part of some supercomputer/classified use case. ARM has a history of having quirky un-RISCy instructions.

(edit: also it seems that ARM has just cnt.v8 for counting 8-bit lanes in NEON and no 64-bit scalar instruction version, interesting. Being part of NEON also means it's an optional part on ARM)


Late addition is more indicative of value than appearing in first releases. People guess about the base instruction set, but additions happen only in response to high demand.


Seriously?

Because it provides order-of magnitude speed improvements for numerous algorithms. Because it is the basis for integer log-base-2.

If you don't know what popcount is good for, or badly miss it where it is lacking, your education has suffered. That is remediable.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: