~/talk

Branchless Programming in C++

Talkat CppCon 2021 · on Sunday, 2021-10-24· [web-performance]
slides:none on file

Concrete code transformations and measurements determine value: a simple if (b) s += x change yields 2.5x speedup on the presented machine; a poorly predicted if (a[i] && b[i]) case runs about 4x slower than a branchless rewrite. Benchmarks use perf + Google Benchmark and show branch-mispredictions dropping from ~10% mispredict to <0.1%, with wins from replacing short‑circuit logic with bitwise/arithmetic or using boolean-indexed arrays when the overall outcome is predictable.

AI-written summary · about

  1. 0:00Hardware and pipelining
  2. 10:11Data dependencies
  3. 14:00Branch prediction
  4. 17:21Register aliasing
  5. 20:41Branch misprediction cost
  6. 23:10Branchless programming
  7. 25:23Misprediction benchmarks
  8. 30:42The CPU predictor
  9. 34:03Q&A and mitigations
  10. 38:22Logical branch elimination
  11. 43:23Branchless arithmetic
  12. 52:11Array indexing optimization
  13. 55:28Compiler optimization limits
  14. 1:00:16Summary and Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.