
Restructure Loops So Compilers Can Vectorise Reductions, Gathers and Early Exits
Rewrite float reductions, indirect gathers and early-exit loops in C so GCC and Clang vectorize them, using partial sums and blocked scans.
Tag
6 posts

Rewrite float reductions, indirect gathers and early-exit loops in C so GCC and Clang vectorize them, using partial sums and blocked scans.

Use arm_neon.h to write NEON vector loops in C for AArch64: float32x4_t, vld1q_f32, vaddq_f32, vfmaq_f32 and vaddvq_f32, with a full dot product and its output.

Convert a 128-bit SSE integer loop to 256-bit AVX2: new types, a step of eight, the -mavx2 flag, runtime dispatch and the lane-crossing trap.

Add two float arrays of any length with SSE intrinsics in C: a four-wide main loop, a scalar tail, unaligned loads and the assembly you should see.

Learn what SIMD means, how a vector register splits into lanes, and how C intrinsics map to instructions, with a first program that adds four floats at once.

Learn SIMD from scratch with C intrinsics for SSE, AVX2 and ARM NEON: loads, arithmetic, masks, shuffles, reductions, tails, dispatch, testing and pitfalls.