This problem is driving me a bit crazy. The code seems to be segmentation faulting for no good reason:
#define MULT_FLOAT4(X, Y) ({ \
asm volatile ( \
"movups (%0), %%xmm0\n\t" \
"mulps (%1), %%xmm0\n\t" \
"movups %%xmm0, (%1)" \
:: "r" (X), "r" (Y)); })
int main(void)
{
int before;
float a[4] = { 10, 20, 30, 40 };
float b[4] = { 0.1, 开发者_运维问答0.1, 0.1, 0.1 };
/* Segmentation faults if I uncomment this line below, otherwise works fine. Why?? */
int after;
MULT_FLOAT4(a, b);
return 0;
}
Note that so long as I have defined both the 'before' and 'after' variables it segmentation faults. If I just have 'before' or just have 'after' then it works fine.
I'm on Ubuntu Hardy (8.04), GCC version 4.2.4 (Ubuntu 4.2.4-1ubuntu4). Linux kernel: 2.6.24-16-generic.
Check the address of a and b. I suspect you'll find that they must be aligned to a 16 byte boundary in order to avoid a segfault. Adding __ attribute __((aligned(16)))
after their declarations should do the trick.
That's two underscores on each side of attribute and connected to it, BTW.
精彩评论