Add eight floats at once with _mm256_add_ps
Add eight floats at once with _mm256_add_ps from AVX in C, loading two vectors with loadu, adding them and storing the result back to memory.
AVX gives you 256-bit registers that hold eight single-precision floats. _mm256_add_ps adds two of them lane by lane in one instruction. The surrounding calls move data in and out of the register, and you build with -mavx on GCC 14 or Clang 19.
#include <immintrin.h>
#include <stdio.h>
int main(void) {
float a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
float b[8] = {10, 10, 10, 10, 10, 10, 10, 10};
float c[8];
__m256 va = _mm256_loadu_ps(a);
__m256 vb = _mm256_loadu_ps(b);
_mm256_storeu_ps(c, _mm256_add_ps(va, vb));
for (int i = 0; i < 8; i++)
printf("%g ", c[i]);
printf("\n");
}11 12 13 14 15 16 17 18Each output lane is the sum of the lanes in the same position, so the result matches a scalar loop exactly: a single addition per lane gives the same answer, with the same rounding. __m256 is a register type, not an array, so you cannot index it; go through memory to read the lanes. Check that the CPU supports AVX before executing the code: on a machine without it, the program dies with an illegal instruction. The operation is listed in the Intel Intrinsics Guide.