Why it matters

Bit hacks power tight loops and codecs. Understanding them saves branches and cycles.

Advertisement

The architecture

Branchless abs; branchless min/max; round-up to next pow2; bit-parallel byte swap.

Modern compilers may synthesize hacks automatically.

Bit hacks catalogBranchless abssign xor addRound to pow2shift + or foldByte swapBSWAP intrinsicSean Anderson's page is the canonical reference; keep unit tests for each hack
Bit hacks catalog.
Advertisement

How it works end to end

Sean Anderson's page as reference.

Compiler autovectorization may compete.

Test edge cases carefully.