Spokes.wiki Search About
Tech Article source ↗ source url updated Thu Jun 18 2026 00:00:00 GMT+0000 (Coordinated Universal Time)

Hamming weight (Wikipedia)

Wikipedia’s article on Hamming weight — the reference write-up of popcount, covering the named-constant SWAR algorithm, the method ladder’s exact operation counts, the hardware instruction timeline, and applications. A clean secondary source that pins down the numbers the bit-twiddling-hacks and count-set-bits-so pages gesture at.

What it pins down

  • The SWAR popcount64 constants, by name: m1 = 0x5555… (the 2-bit lanes), m2 = 0x3333… (4-bit), m4 = 0x0f0f… (8-bit), and h01 = 0x0101010101010101 — the last is the multiplier whose one byte-sum-via-multiply step replaces the final shift-and-add. This is the canonical SWAR popcount written with names instead of magic numbers.
  • Exact operation counts for the ladder: the optimized parallel method is 17 arithmetic operations, versus 24 for the naive approach and Wegner’s sparse method at 3 ops + 1 branch per set bit (the Kernighan v &= v-1 style — cheap only on sparse words).
  • The POPCNT hardware timeline: AMD Barcelona added POPCNT via SSE4a in 2007; Intel followed in the Core i7 (Nehalem) under SSE4.2 in November 2008. ARM has VCNT in Advanced SIMD/NEON; RISC-V has CPOP in the Bit-Manipulation (B) extension. So popcount is the bit trick that earned a dedicated instruction on every major ISA — the sharpest case of branchless-programming‘s “hardware wins now.”
  • Language support dates: C++20’s std::popcount; GCC’s __builtin_popcount since version 3.4 (2004).

Applications it lists

RSA cryptography (low-Hamming-weight public exponents cut the number of modular multiplications), error-correcting / coding theory, and chess-engine bitboard evaluation — the same correctness-critical niches the spoke’s synthesis argues are where popcount stayed load-bearing.

Tier

T1 — Wikipedia as a well-sourced reference article on a settled technical topic; the numbers and dates are verifiable against primary ISA docs.

population-count · swar · branchless-programming · bit-twiddling-hacks · count-set-bits-so · hackers-delight