/*
 * SIMD is already in your laptop  —  Session 02, slide 6
 *
 * Don't run it for the output. Compile it TWO WAYS and look at the assembly:
 *
 *   gcc -O3        -S -o - 03-simd-in-your-laptop.c | grep adds    ->  addss
 *   gcc -O3 -mavx2 -S -o - 03-simd-in-your-laptop.c | grep vadd    ->  vaddps
 *
 *   addss  = add scalar single  -> 1 float  per instruction   (SISD)
 *   vaddps = add packed single  -> 8 floats per instruction   (SIMD)
 *
 * Same source. Same one core. The 's' became a 'p'. That is Flynn, in one letter.
 * Easiest way to show the class: paste this into godbolt.org, then add -mavx2.
 */

#include <stdio.h>

void add(float *a, float *b, float *c, int n)
{
    for (int i = 0; i < n; i++)
        c[i] = a[i] + b[i];
}

int main(void)
{
    float a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
    float b[8] = {10, 20, 30, 40, 50, 60, 70, 80};
    float c[8];

    add(a, b, c, 8);

    for (int i = 0; i < 8; i++)
        printf("%.0f ", c[i]);
    printf("\n");
    return 0;
}
