← Back to the chapter · Next detail →

Technical detail · Software Optimization Techniques

Compiler optimization modes

18.7 Compiler Optimization Modes

Optimization flags express a preference to a particular toolchain; they do not guarantee a fixed list of transformations. In common GCC- and Clang-style workflows, a speed-focused -O3 build may inline more aggressively, unroll or vectorize loops, reorder instructions, and create separate fast paths for alignment or aliasing cases. A size-focused -Os build usually discourages growth, favors shorter encodings, and may keep branches or calls that a speed build removes. Inspect the compiler version, generated code, link map, and measurements rather than assigning universal behavior to the flag name.

Use a four-result comparison for the production workload:

BuildFlash bytesHot-path timeWhole-cycle energyWhy it may win
Balanced optimizationMeasureMeasureMeasureStable baseline with moderate code growth
Speed-focused (-O3-style)Often largerOften shorterDepends on active-time reduction and fetch/cache effectsA deadline-bound hot loop dominates energy
Size-focused (-Os-style)Often smallerMay be longerDepends on flash fetch, cache fit, and added active timeFlash/update slot or instruction-fetch pressure dominates
Custom pass setToolchain-specificToolchain-specificMust be measuredOne known transformation helps while another causes regression

A speed build can reduce energy by returning to sleep sooner, yet lose that gain if code growth causes more flash wait states or instruction-cache misses. A size build can reduce fetch energy, yet keep the core awake longer. The winning flag is the one that lowers measured charge per useful task while preserving timing, stack, numerical, and update-slot requirements.

← Back to the chapter · Next detail →