Figuring out how many bits in a group of bits are set to 1, known as computing "population count", Hamming weight, or "bit summation", among others, has various applications.
It is also fairly cheap to implement in hardware to be executed as fast as a fixed point addition if not faster.
Likely for these reasons, CDC 6600 (1964) had CXi (47)
described as Count the number of 1's in Xk to Xi specifically included in its quite short list of instructions, although IBM STRETCH (1961) had that capability first as a by-product of all logical operations.
Then, in the list of processors with the "popcount" instruction there are large gaps. Since CDCs and Crays, and until very late 1990s, only SPARC (designed in mid-1980s) had the POPC
instruction.
Not a single IBM processor (not counting the aforementioned IBM STRETCH where there was no need for a separate instruction), not a single DEC processor (the instruction first appeared in an Alpha CPU when it was already Compaq's), not a single Motorola processor, not a single Intel or AMD processor until late 2000s, ...
As a result, innumerably many a software engineer had to implement the functionality of POPCOUNT
by hand with various degrees of efficiency (even GCC introduced __builtin_popcount
only in mid-2000s), and to endure silly interview questions about its efficient implementations.
What was going on? The wiki page doesn't discuss that aspect, but the many-decades long omission is so glaring that there had to be some musings on the subject by people "in the know".
I'm not asking people to speculate here; I'm asking for references to existing material about the lack of POPCOUNT in most of the CPUs of the last quarter of the XX century.
std::bitset::count()
usingpopcnt
or equivalent sincebitset
was invented (1994?). When they actually started doing so requires more research. See: stackoverflow.com/a/45189920/966071bitmap.h