This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: inline asm with sse problem
- From: wojtekb82_23 <wojtekb82_23 at o2 dot pl>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 07 Feb 2008 14:45:03 +0100
- Subject: Re: inline asm with sse problem
- References: <.1202347789@magma.ca>
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.