#include #include #include #include #include #include //sse2 //macro to print a __m128 vector #define PVEC(a) \ { \ float tp[4]; \ _mm_storeu_ps ( tp ,a); \ printf("VEC %7.1f %7.1f %7.1f %7.1f \n", \ tp[0], \ tp[1], \ tp[2], \ tp[3]); \ } \ main(int argc, char** argv) { __m128 vec1,vec2; //vectors containing 4 32-bits floats float a,b,c,d; a=12.0; b=13.0; c=15.0; d=29.0; vec1 = _mm_set_ps( a,b,c,d); // 1) set the value in the vector PVEC(vec1); // print the vector with the macro above vec2 = _mm_set1_ps( 10); // 2)set four times the same value in second vector vec1 = _mm_add_ps(vec1,vec2); // 3) add the two vectors together printf(" + \n"); PVEC(vec2); printf(" = \n"); PVEC(vec1); // see result vec1 = _mm_mul_ps(vec1,vec2); // 4) multiply the two vectors printf(" x \n"); PVEC(vec2); printf(" = \n"); PVEC(vec1); // see result float res[4]; _mm_storeu_ps ( res ,vec1);// 5) store back result printf("%7.1f %7.1f %7.1f %7.1f \n",res[0],res[1],res[2],res[3]); }