Re: inline asm with sse problem
wojtekb82_23
wojtekb82_23@o2.pl
Thu Feb 7 13:45:00 GMT 2008
Dnia 7 lutego 2008 2:29 Tom St Denis <tstdenis@ellipticsemi.com> napisał(a):
> > I have the code [appendix 1] that I compile using [appendix 2] on system
> > [appendix 3].
> > I get a Segmentation fault at line:
> > 0x080487ca : movups (%esi),%xmm0
> > 0x080487cd : addps (%ebx),%xmm0
> > 0x080487d0 : movups %xmm0,(%ebx)
> > What am I doing wrong?
>
> What is the alignment of %ebx? If it's not 16 byte aligned you're probably going to get a fault.
>
Thanks, but I still get the same error with alignment:
#include <iostream>
using namespace std;
int main() {
void* p;
void* q;
if (posix_memalign(&p, 16, 4*sizeof(float)) < 0) {
cerr << "ERR" << endl;
return 1;
}
float* dst = static_cast<float*>(p);
if (posix_memalign(&q, 16, 4*sizeof(float)) < 0) {
cerr << "ERR" << endl;
return 1;
}
float* src = static_cast<float*>(q);
for(int i = 0; i<4; i++)
{
dst[i] = 0;
src[i] = 1;
}
cout << dst[0] << " " << dst[1] << " " << dst[2] << " " << dst[3] << endl;
asm ("movups 0(%[src]), %%xmm0\n\t"
"addps 0(%[dst]), %%xmm0\n\t"
"movups %%xmm0, 0(%[dst])\n\t"
: [dst] "=r" (dst)
: [src] "r" (src)
: "xmm0");
cout << dst[0] << " " << dst[1] << " " << dst[2] << " " << dst[3] << endl;
return 0;
}
And what about the "wrong" compilation when passing -O0?
Regards,
WB.
More information about the Gcc-help
mailing list