SimplifyC++ Article
Eight Operations in One Instruction — It’s Time to Make AVX2 the Baseline for Modern x86-64 Software

For the past two years, I’ve been designing an x86-64 assembler as part of MyLangTC. Along the way, problems involving both integer and floating-point arithmetic pushed me to use SIMD more extensively. When I arranged the data so that one instruction could add eight pairs of 32-bit values, I saw substantial speedups in some computational paths. That experience left me with a question for compiler and operating system developers. Why do so many releases aimed at modern hardware still target an instruction set that keeps these capabilities out of the compiler’s generated code?
Compatibility with older processors explains much of the delay. Intel shipped AVX in processors such as the Core i7-2600 in 2011 and AVX2 in processors such as the Core i7-4770 in 2013. Yet SSE2 is still the default for x64 code generation in MSVC, with /arch:AVX2 available to projects that explicitly raise their baseline. In my view, the default build targets for modern releases have been too slow to change. Compilers already have vectorizers, and modern operating systems can manage vector register state. I’m calling for AVX2 to become the minimum for releases aimed at hardware that supports it. For Linux builds that use the standardized x86-64 feature levels, x86-64-v3 is a practical baseline.
Intel Core i7-2600 ·
Intel Core i7-4770 ·
Microsoft x64 compiler options
What do we gain by moving from XMM to YMM?
SIMD, or single instruction, multiple data, applies the same operation to several elements at once. On x86-64, XMM0 is the low 128 bits of YMM0, and the same overlap applies to the other corresponding registers. AVX introduced 256-bit packed floating-point arithmetic. AVX2 extended many packed integer instructions to the same width. The number of lanes depends on the element size and the instruction.
Intel instruction set reference
| Addition | 256-bit instruction | Lanes in XMM (128 bits) | Lanes in YMM (256 bits) | Extension required for the YMM form |
|---|---|---|---|---|
| Single-precision floating point | VADDPS | 4 | 8 | AVX |
| Double-precision floating point | VADDPD | 2 | 4 | AVX |
| 32-bit integers | VPADDD | 4 | 8 | AVX2 |
| 64-bit integers | VPADDQ | 2 | 4 | AVX2 |
| 8-bit integers | VPADDB | 16 | 32 | AVX2 |
In Intel syntax, vaddps ymm0, ymm1, ymm2 adds each lane of YMM1 to the corresponding lane of YMM2 and writes eight independent results to YMM0. Summing eight lanes into a single value is a horizontal reduction and takes additional steps. The instruction vfmadd231ps ymm0, ymm1, ymm2 performs eight fused multiply-add operations with one rounding per lane. By the usual FLOP counting convention, that is 16 floating-point operations. This instruction requires FMA, which the x86-64-v3 level includes alongside AVX2 and extensions such as BMI1, BMI2, and F16C.
Intel FMA instruction reference ·
x86-64 psABI feature levels
A compiler experiment in three builds
This experiment uses GCC 14.2 on x86-64. The add_u32 function adds two arrays element by element, with arithmetic modulo 2³². The restrict qualifiers let the compiler assume that the written destination range does not overlap the input ranges it reads. The sum_f32 function reduces a floating-point array to a single value in loop order.
Save the following as kernel.c.
#include <stddef.h>
#include <stdint.h>
void add_u32(uint32_t *restrict dst, const uint32_t *restrict a,
const uint32_t *restrict b, size_t n)
{
for (size_t i = 0; i < n; ++i)
dst[i] = a[i] + b[i];
}
float sum_f32(const float *a, size_t n)
{
float sum = 0.0f;
for (size_t i = 0; i < n; ++i)
sum += a[i];
return sum;
}
Build the same source three ways, then disassemble the object files in Intel syntax.
gcc -O3 -march=x86-64 -ffp-contract=off -c kernel.c -o base.o
gcc -O3 -march=x86-64-v3 -ffp-contract=off -c kernel.c -o v3.o
gcc -O3 -march=x86-64-v3 -ffp-contract=off \
-fassociative-math -fno-signed-zeros -fno-trapping-math \
-c kernel.c -o v3-reordered.o
objdump -d -Mintel base.o v3.o v3-reordered.o
| Build target | Main integer addition loop | Floating-point reduction |
|---|---|---|
x86-64 |
paddd xmm, four elements per instruction |
addss, one element per instruction |
x86-64-v3 |
vpaddd ymm, eight elements per instruction |
vaddss, one element per instruction |
x86-64-v3 with reassociation enabled |
vpaddd ymm, eight elements per instruction |
vaddps ymm accumulates partial sums, which are then combined |
I inspected the generated instructions and checked that the two integer builds produced identical results for 68 array lengths, from 0 through 67, including loop tails and unsigned wraparound. The experiment checked code generation and correctness. Raising the target baseline was enough to widen the integer loop from four lanes to eight. The floating-point reduction stayed scalar until the third build allowed reassociation. The second build uses the VEX-encoded VADDSS, which processes one floating-point element per instruction.
When the compiler splits the reduction into partial sums, it changes where rounding occurs and can change the answer. With ordinary single-precision arithmetic, (1e20f + (-1e20f)) + 1.0f evaluates to 1, while 1e20f + ((-1e20f) + 1.0f) evaluates to 0. Programming languages should let developers state their numerical requirements explicitly, including whether particular routines may reorder operations or fuse a multiply and an add.
LLVM on vectorizing reductions ·
GCC optimization and floating-point options
Why would a compiler choose a narrower path?
LLVM’s Loop Vectorizer works across loop iterations, and its SLP Vectorizer groups independent operations within a basic block. The compiler weighs vector code against the scalar path. It must prove that operations are independent or generate runtime checks for aliasing, handle leftover elements, and estimate the cost of loads and shuffles. For example, each iteration of a[i] += a[i - 1] depends on the result of the preceding one. Efficient vectorization calls for a specialized prefix-sum algorithm. Data layout matters as well. Moving frequently used fields from an array of structures into separate, contiguous arrays can simplify loads and reduce shuffling.
LLVM vectorizers ·
GCC vectorization cost models
Compiler developers should make it easy to see why a particular loop stayed scalar. Was there a dependency between iterations, possible aliasing, a floating-point constraint, or a cost estimate that favored scalar code? Clang already provides diagnostics such as -Rpass-missed=loop-vectorize and -Rpass-analysis=loop-vectorize. These reports should be routine for anyone building a numerical library. Validate the cost models on the intended processors, and use measurements to establish when 128-bit or 256-bit vectors serve a given workload better.
LLVM vectorization diagnostics ·
GCC vector width options
Operating systems have to manage vector register state
Using AVX2 requires processor support and operating system support for the relevant register state. A program checks for AVX and OSXSAVE, uses XGETBV to read XCR0 and confirm that bits 1 and 2 enable XMM and the upper halves of YMM, and checks the AVX2 feature bit in CPUID leaf 7. The operating system preserves extended processor state across thread context switches. Linux documents how this state is enabled for user-space programs, and Microsoft introduced AVX state APIs with Windows 7 SP1. In a virtual machine, the CPU features exposed to the guest determine which instructions guest applications can use.
Intel AVX2 detection procedure ·
Linux XSTATE ·
Microsoft XState ·
QEMU CPU models
SIMD inside the kernel follows different context rules. Linux documents kernel_fpu_begin() and kernel_fpu_end() for wrapping code that needs floating-point state in supported contexts. Calling conventions matter for handwritten assembly too. On Windows x64, a callee that modifies XMM6 through XMM15 must preserve their 128-bit values. The upper halves of the corresponding YMM registers are volatile across calls. On some processors, VZEROUPPER can avoid penalties when transitioning from wide AVX instructions to legacy SSE. Its placement must account for any live values in the upper lanes. These details matter when a fast loop becomes part of a complete program.
Linux kernel floating-point API ·
Windows x64 calling convention ·
Intel optimization guidance
Where SIMD pays off in AI and data science
The gains are clearest when an algorithm does substantial work for each byte it loads. Adding two float arrays and writing the result logically moves 12 bytes per addition before any extra memory-system traffic. If those arrays exceed cache capacity and the loop saturates memory bandwidth, widening the vectors brings diminishing returns. A blocked matrix multiplication can reuse loaded data many times, giving FMA more scope to raise arithmetic throughput.
The Roofline performance model
The same instruction can also have different throughput on different processors. For register-to-register VADDPS with three YMM operands, uops.info measures a throughput of one independent instruction per cycle on Intel Haswell and two per cycle on AMD Zen 4. A dependent instruction waits three cycles for the result on both. Algorithms can use multiple independent accumulators to take advantage of that throughput when their numerical requirements allow it. Sustained clock frequency under load also affects elapsed time, and the effect varies by processor model.
uops.info VADDPS measurements ·
Intel Xeon AVX frequency behavior
In data science, filtering, comparisons, and type conversions can benefit when the data is laid out for batch processing. In AI, CPU inference can benefit in kernels for matrix multiplication and quantized weights, depending on model shape and batch size. NumPy selects optimized implementations of some operations at runtime, and llama.cpp can build CPU backends for AVX2 and newer extensions. AVX2 gives these workloads a common baseline. AVX-512 and AMX offer further specialization when the hardware supports them and the workload benefits.
NumPy CPU and SIMD optimization ·
llama.cpp build options
Raise the baseline and measure the result
The shift is already under way. RHEL 10 raised its minimum x86-64 requirement to x86-64-v3. Ubuntu 26.04 LTS made amd64v3 packages available as an option for eligible machines, and Ubuntu 26.10 published an x86-64 desktop image targeting v3. The glibc dynamic loader can select libraries built for higher feature levels through glibc-hwcaps. GCC can also generate several versions of a function and select the appropriate one at runtime on supported platforms. Users and developers should be able to tell what hardware a release requires and which instruction set the package they installed actually uses.
Red Hat ·
Ubuntu 26.04 ·
Ubuntu 26.10 ·
glibc dynamic loader ·
GCC function multiversioning
- Operating system and distribution developers. Make AVX2 a requirement for modern releases where the supported hardware permits it. Check the CPU features and operating system state in the installer or in startup code that can run before any instruction from the new baseline executes. Where older machines still need support, offer a dedicated build or select optimized libraries at load time.
- Language and compiler developers. Provide an explicit modern target, such as
-march=x86-64-v3in GCC and Clang or/arch:AVX2in MSVC, according to the platform’s requirements. Give auto-vectorization the attention it deserves. Provide vector types and operations for libraries that need direct control, expose floating-point semantics clearly, and validate vector-width decisions against measurements. GCC · Clang · MSVC - Numerical library developers. Compare 128-bit and 256-bit implementations on the same processor, with the same algorithm and precision. Test datasets that fit in cache and datasets that exceed it. Publish elapsed time and elements processed per second. Include cycles per element and memory bandwidth when they explain the results. Judge the change by its effect on the application as a whole.
My work on the MyLangTC assembler has brought me to a simple conclusion. A modern release should build on the capabilities of the hardware it was designed to run on. More than a decade after AVX2 arrived, programmers should see SIMD in the code their compiler generates and in the libraries their operating system loads, even when they write an ordinary loop. Raise the baseline wherever the hardware supports it, and make effective use of it a shared responsibility of language designers, compiler developers, and operating system developers.
What did you think?
Sign in to react or comment.
Comments
0No comments yet.