Hasty Briefsbeta

Bilingual

Matt Godbolt's blog

15 hours ago
  • Giving the compiler compile-time known loop count (e.g., via `std::span<int, 8>`) enables loop unrolling optimization.
  • A dynamically-sized span (`std::span<int>`) results in a straightforward loop with counter and branch per iteration.
  • Unrolling eliminates loop counter and conditional branch, saving instructions and allowing further pattern detection like using `ldmib` for multiple loads.
  • Compilers may partially unroll, speculatively unroll, or fall back to regular looping depending on heuristics and iteration count (e.g., at 50 iterations it gives up).
  • Checking hot loops and providing compile-time loop counts sets the compiler up for success; profile-guided optimization (PGO) can also help improve guesses.