Master the fundamental concepts of compiler optimization techniques through this focused micro-challenge.
__builtin_expect(expr, c) tells GCC/Clang the probability of a branch, influencing layout so the hot path falls through. Linux kernel likely()/unlikely() macros wrap it. Mis-hinting can slow code by fighting the hardware predictor.
Mark error checks as cold. Keep the common path straight-line when possible.
cLoading…
perf stat -e branch-misses before sprinkling hintsKeep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will add branch hints to a hot path and compare assembly layout. This exercise requires explaining when hints helped versus when the predictor already learned the branch.
Document one invariant you will assert in tests and how you would detect its violation from observable symptoms.
Demonstrate branch prediction hints with performance measurement.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github