0

Standard vanilla C++ float32x8 arrays manipulation

Free lines C/C++ 2 revisions 35 24 days ago 24 days ago
#include <iostream>

float* multiply_and_add(float* a, float* b, float* c, float* d) {
	for (int i = 0; i < 8; i++) {
		d[i] = a[i] * b[i];
		d[i] = d[i] + c[i];
	}

	return d;
}

int main() {
	float a[8] = {1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f};
	float b[8] = {1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f};
	float c[8] = {1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f};
	float d[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};

	multiply_and_add(a, b, c, d);

	for (int i = 0; i < 8; i++)
		std::cout << d[i] << std::endl;
}

This is a base snippet for this one. This is probably a useless snippet on its own.

This example is basically (a * b) + c with vectors.

Example output is:

2
6
12
20
30
42
56
72

Compilation works without anything special (g++ should also work similarly):

clang++ example.cpp -o ./example