Topics / Bit tricks and strength reduction
Performance topic
Bit tricks and strength reduction
Replace expensive operations with cheap ones: shifts for divisions, popcount and count-leading-zeros, multiply-by-reciprocal, bit masks instead of sets.
1,973proven techniques
29pitfalls: tried, then slower
838repositories
107from papers
Examples from real commits
openfheorg/openfhe-development
56×
Extract all base-2^d digits in one pass: bias once by H, then each digit is a shift-and-mask window minus h, top window unmasked.
proof: commit →
apache/doris
7×
For constant exponent 2, replace libm pow with x*x for the leading block prefix whose bases are integers with |x|<=2^26, where the square is exact.
proof: commit →
NVIDIA/cudf
6.6×
Represent NFA state as a single uint64_t bitmask to eliminate per-thread global memory access.
proof: commit →
rui314/mold
5.1×
Compile 64+ complex glob patterns into one bit-parallel NFA, one bit per state, advancing 64 states per machine word per input byte.
proof: commit →
apache/arrow-rs
3.4×
Constant-time byte-parallel compress: three SWAR suffix-network shift rounds on all bytes at once, then one multiply by 0x0101..01 to place each byte.
proof: commit →
sgl-project/sglang
3×
Extract int4 nibbles with lop3 mask-and-OR against a fp16 magic constant, then fix the bias with one half2 sub or fma, avoiding per-element shifts and converts.
proof: commit →
VcDevel/Vc
3×
Use inline assembly vmovd instead of _mm_cvtsi128_si32 to extract the first 32-bit lane.
proof: commit →
rive-app/rive-runtime
1.9×
Evaluate the normal curve as exp2(-t_*t_) by pre-scaling the argument by sqrt(log2(e)), replacing natural exp with the cheaper base-2 exponential.
proof: commit →
Languages
- C++848
- C515
- Rust187
- CUDA77
- Go50
- Python40
Hardware
- x86605
- CPU479
- ARM201
- NVIDIA GPU107
- GPU60
Fields
- general520
- data & compression379
- math299
- graphics224
- CPU204
Where these come from
Repositories with the most techniques on this topic in the database:
z88dk/z88dk · 14zeux/meshoptimizer · 12simdjson/simdjson · 10WojciechMula/base64simd · 10abseil/abseil-cpp · 10ptitSeb/box64 · 10v8/v8 · 9flagos-ai/FlagGems · 9stenzek/duckstation · 9torvalds/linux · 8
Ask Claude for the full answer
Each technique comes with its bottleneck, measured speedup, trade-offs, conditions and the commit or paper behind it, served to Claude through MCP.
claude mcp add --transport http adtomic https://www.adtomic.co/mcp
Related topics
BatchingSpecialization, templates and JITReducing synchronizationPipelining and async overlapBit packing and smaller types