Function multiversioning compiles one function several times for different instruction sets and chooses a version at run time by the processor’s features: GCC’s target_clones("avx2", "default") attribute builds both and dispatches when the program loads.
-ffast-math the sum changed. Best of five runs, g++ 11.4. Measured on a laptop (Intel Core Ultra 7 155H) under WSL2, no isolated cores, pinned to one CPU. Data: bench_flags.py.