Unrolling loops
xania.org·5d
🚀Compiler Optimizations
Preview
Report Post

Written by me, proof-read by an LLM. Details at end.

A common theme for helping the compiler optimise is to give it as much information as possible. Using the right signedness of types, targeting the right CPU model, keeping loop iterations independent, and for today’s topic: telling it how many loop iterations there are going to be ahead of time.

Taking the range-based sum example from our earlier post on loops, but using a std::span1, we can explore this ability. Let’s take a look at what happens if we use a dynamically-sized span - we’d expect it to look very similar to the std::vector version:

The compiler doesn’t know …

Similar Posts

Loading similar posts...