Source: https://vaibhavsagar.com/blog/2019/09/08/popcount
popcount is a CPU instruction whose only purpose is
to count how many bits are set to 1 inside a binary word (8 bits = 1 byte).
popcount(00100110) == 3 // because there are three “1” bits
popcount(01100000) == 2 // because there are two “1” bits
Each bit that is set to 1 is added to the total.
(vaibhavsagar.com)
This is literally all it does: it counts 1s. There is nothing magical hidden beyond that. (tech-in-japan.github.io)
popcountpopcount(x XOR y)
int popcount(value) {
int count = 0;
for (i = 0; i < bits_in_word; i++) {
if ((value >> i) & 1 == 1) count++;
}
return count;
}
In hardware it can run in a single cycle. (felixcloutier.com)
dest = number of bits “1” in src
No. Older CPUs like the Intel Core 2 did not have it. (softwareg.com.au)
The NSA pushed the development of hardware bit counting because counting bits is key to cryptography and espionage.
👉 Does this stream of bits actually look random?
This is where popcount comes in.
popcount(data) / total_bits
If it doesn’t give ~50/50 → weak cipher.
popcount(x XOR y)
If only a few bits change → bad algorithm.
Result: dedicated instructions → now in your CPU.
popcount was not created for games.
It was created to break ciphers and spy.
popcount = counting bitsToday you use it for AI or chess, but its origin is espionage.
popcount es una instrucción de CPU cuyo único propósito es
contar cuántos bits están en 1 dentro de una palabra binaria.
popcount(00100110) == 3 // porque hay tres bits "1"
popcount(01100000) == 2 // porque hay dos bits “1”
Cada bit que está en 1 se suma al total.
(vaibhavsagar.com)
Eso es literalmente todo lo que hace: cuenta 1s. Nada mágico escondido más allá de eso. (tech-in-japan.github.io)
popcountpopcount(x XOR y)
int popcount(value) {
int count = 0;
for (i = 0; i < bits_in_word; i++) {
if ((value >> i) & 1 == 1) count++;
}
return count;
}
En hardware puede ejecutarse en un solo ciclo. (felixcloutier.com)
dest = número de bits “1” de src
No. CPUs viejos como Intel Core 2 no la tenían. (softwareg.com.au)
La NSA empujó el desarrollo de hardware para contar bits porque contar bits es clave en cripto y espionaje.
👉 ¿Este flujo de bits parece realmente aleatorio?
Ahí entra popcount.
popcount(datos) / total_bits
Si no da ~50/50 → cifrado débil.
popcount(x XOR y)
Si pocos bits cambian → algoritmo malo.
Resultado: instrucciones dedicadas → hoy en tu CPU.
popcount no nació para juegos.
Nació para romper cifrados y espiar.
popcount = contar bitsHoy lo usás para IA o ajedrez, pero el origen es espionaje.