01 // Compute scalar product in C: 02 float scalarproduct(float x[], float y[]) 03 { 04 return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3]; 05 } 06 07 // Compute scalar product in Assembler: 08 float scalarproductAssembler(float x[], float y[]) 09 { 10 vector tmp; 11 asm( 12 "movl %1, %%esi;" 13 "movl %2, %%edi;" 14 "movaps (%%esi), %%xmm0;" 15 "mulps (%%edi), %%xmm0;" 16 "movaps %%xmm0, %0;" 17 :"=g"(tmp) /* Output */ 18 :"r"(x),"r"(y) /* Input */ 19 ); 20 return tmp.f[0] + tmp.f[1] + tmp.f[2] + tmp.f[3]; 21 }