This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: A bug in IA32 assembler
- To: "H . J . Lu" <hjl at lucon dot org>
- Subject: Re: A bug in IA32 assembler
- From: Richard Henderson <rth at redhat dot com>
- Date: Fri, 29 Jun 2001 10:03:14 -0700
- Cc: gcc at gcc dot gnu dot org, binutils at sourceware dot cygnus dot com
- References: <20010627234857.A23201@lucon.org> <20010628225833.Q4573@bubble.local> <20010628093749.B31850@lucon.org> <20010629102120.V4573@bubble.local> <20010628181154.A7899@lucon.org> <20010628185526.A16798@redhat.com> <20010628190330.A8724@lucon.org> <20010628230303.A16961@redhat.com> <20010629001556.A13433@lucon.org>
On Fri, Jun 29, 2001 at 12:15:56AM -0700, H . J . Lu wrote:
> This one:
>
> asm("movaps (%0),%%xmm0" //SSE
> :
> :"g"(A));
This one is wrong because A is an array, which decomposes to a pointer,
which has the constant value A.2. And you've told the compiler that
immediates are acceptable. So it prints A.2 as an immediate.
It's also wrong in that you're _not_ telling the compiler that you are
reading from memory. So it'll be happy to move stores across this asm,
or even remove them as dead.
> asm("movaps %%xmm0,(%0)":"=g"(C)); //SSE
Likewise, you're not telling the compiler that you are storing to memory.
The easiest way to write things correctly is like so.
r~
#include <stdio.h>
typedef struct
{
float x[4] __attribute__((aligned(16)));
} V4SF;
static void dump (const char *name, const V4SF *v)
{
int i;
printf("float %s=(", name);
for(i = 0; i < 4; i++)
printf("%f,", v->x[i]);
printf("\b)\n");
}
int main()
{
static V4SF A = {1.,1.,1.,1.};
static V4SF B = {0.,1.,2.,3.};
static V4SF C;
dump("A", &A);
dump("B", &B);
asm("movaps %0,%%xmm0" : :"m"(A));
asm("movaps %0,%%xmm1" : :"m"(B));
asm("addps %xmm1,%xmm0");
// asm("mulps %xmm1,%xmm0");
asm("movaps %%xmm0,%0" : "=m"(C));
dump("C", &C);
return 0;
}