Witam,
napisałem program w C ze wstawkami z Assemblera. Trochę poczytałem o SSE i zabrałem się do pracy, ale wyskakuje mi następujący błąd:
asm operand 1 probably doesn't match constraints
Niestety nie widzę błędu w swoim kodzie.
#include <stdio.h>
#include <stdlib.h>
#define sizeOfNumbers 10
#define randSize 1000
struct vector
{
float x0;
float x1;
float x2;
float x3;
};
struct vector v1[sizeOfNumbers];
struct vector v2[sizeOfNumbers];
struct vector vAdd[sizeOfNumbers];
float randomNumbers()
{
for(int i=0; i<sizeOfNumbers; i++)
{
v1[i].x0 = (float)(rand()%randSize)/100;
v1[i].x1 = (float)(rand()%randSize)/100;
v1[i].x2 = (float)(rand()%randSize)/100;
v1[i].x3 = (float)(rand()%randSize)/100;
v2[i].x0 = (float)(rand()%randSize)/100;
v2[i].x1 = (float)(rand()%randSize)/100;
v2[i].x2 = (float)(rand()%randSize)/100;
v2[i].x3 = (float)(rand()%randSize)/100;
}
}
struct vector addSIMD(struct vector a, struct vector b, struct vector sum)
{
printf("dodawanko simd");
asm(
"movaps %1, %%xmm0 \n\t"
"movaps %2, %%xmm1 \n\t"
"addps %%xmm0, %%xmm1 \n\t"
"movaps %%xmm1, %0 \n\t"
:"=r"(sum)
:"r"(a),
"r"(b)
);
return sum;
}
int main(void)
{
randomNumbers();
for(int i=0; i<sizeOfNumbers; i++)
{
vAdd[i] = addSIMD(v1[i],v2[i],vAdd[i]);
}
return 0;
}
Edit:
Po zmianie "r" na "m"(z rejestrów na pamięć), program się kompiluje, ale jest nadal naruszenie ochrony pamięci(zrzut pamięci).
Dodatkowo program tworzę tak:
gcc test.c -c -o test.o
gcc test.o -o test