I'm trying out g++ inline assembly and sse and wrote a first program. It segfaults - why?
#include <stdio.h>
float s[128*4] __attribute__((aligned(16)));
#define r0 3
#define r1 17
#define r2 110
#define rs0 "3"
#define rs1 "17"
#define rs2 "110"
int main () {
s[r0*4+0] = 2.0; s[r0*4+1] = 3.0; s[r0*4+2] = 4.0; s[r0*4+3] = 5.0;
s[r1*4+0] = 3.5; s[r1*4+1] = 3.5; s[r1*4+2] = 3.5; s[r1*4+3] = 3.5;
asm (
"\n\t .intel_syntax noprefix"
"\n\t mov edx, s"
"\n\t movaps xmm0, [edx + " rs0 "*16]"
"\n\t movaps xmm1, [edx + " rs1 "*16]"
"\n\t mulps xmm0, xmm1"
"\n\t movaps [edx + " rs2 "*16], xmm0"
"\n\t .att_syntax"
);
printf ("%f %f %f %f\n", s[r2*4+0], s[r2*4+1], s[r2*4+2], s[r2*4+3]);
}
And why doesn't gdb allow me to single-step the assembly instructions? Do I need to write asm ("..") around every line?