I'm trying to learn to work with SIMD instructions in C. I decided to start working with SSE. I am using Windows 8.1 and am coding with Codeblocks in a Windows environment. My CodeBlocks settings are set to use an Intel i7 (which I have), so SSE is enabled. My program compiles just fine, but I get an error as soon as runtime hits. The error is "(0xC0000005)". Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <xmmintrin.h>
float ScalarSSE(float *m1, float *m2) {
float prod;
int i;
__m128 X, Y, Z;
for(i=0; i<5; i+=4) {
X = _mm_load_ps(&*m1);
Y = _mm_load_ps(&*m2);
X = _mm_mul_ps(X, Y);
Z = _mm_add_ps(X, Z);
}
for(i=0; i<4; i++) {
prod += Z[i];
}
return prod;
}
int main() {
int i;
float *s1 = calloc(1,sizeof (float));
float *s2 = calloc(1,sizeof (float));
for(i=0; i<100; i++) {
*s1 = 2;
*s2 = 2;
float scalar_product_sse = ScalarSSE(s1, s2);
}
printf("Done");
free (s1);
free (s2);
}
I cannot use debug mode as I am not in a project nor know how to open up a project in CodeBlocks (it gives me errors :( )
I am wondering how to make this work without any errors. Thanks!