help with MMX and inline asm (all ok)
Andrea Pretto
andrea_pretto@yahoo.it
Sat Apr 10 11:27:00 GMT 2004
Ian Lance Taylor wrote:
>This works also, with no inline assembler. With -mmx
it generates
>paddd. Without -mmx it does the vector addition
using ordinary x86
>instructions.
>
>Ian
>
>#include <stdio.h>
>#include <string.h>
>
>//file: mmx.c
>// gcc -o mmx -Wall -mmmx mmx.c ( it run also without
-mmmx flag)
>
>typedef int v2si __attribute__ ((vector_size (8)));
>
>int main ( void ){
> int v[2] = { 5, 8};
> int t[2] = { 6, 17};
> int r[2] = { 0, 0};
> v2si rv;
> printf("V: %i %i\n",v[0], v[1]);
> printf("T: %i %i\n",t[0], t[1]);
> printf("R: %i %i\n",r[0], r[1]);
> rv = *(v2si *) &v[0] + *(v2si *) &t[0];
> memcpy (&r, &rv, sizeof r);
> printf("\n\nV: %i %i\n",v[0], v[1]);
> printf("T: %i %i\n",t[0], t[1]);
> printf("R: %i %i\n",r[0], r[1]);
> return 0;
>}
>
I have already tried with a similar method, just with
the example in GCC manual, but GCC give me a "invalid
operands to binari +" ( also with your code).
However its not important. Instead of " *(v2si *)
&v[0] + *(v2si *) &t[0]; ", I use " v2si
__builtin_ia32_paddd (v2si, v2si)".
The problem was move the data to register, and now
with your aid I resolved it.
#include <stdio.h>
#include <string.h>
//file: mmx.c
// gcc -o mmx -Wall -mmmx mmx.c ( it run also without
-mmmx flag)
typedef int v2si __attribute__ ((vector_size (8)));
int main ( void ){
int v[2] = { 5, 8};
int t[2] = { 6, 17};
int r[2] = { 0, 0};
v2si rv,vv,tt;
printf("V: %i %i\n",v[0], v[1]);
printf("T: %i %i\n",t[0], t[1]);
printf("R: %i %i\n",r[0], r[1]);
memcpy(&vv, &v, sizeof v);
memcpy(&tt, &t, sizeof t);
//rv = *(v2si *) &v[0] + *(v2si *) &t[0];
rv = __builtin_ia32_paddd (vv, tt);
memcpy (&r, &rv, sizeof r);
printf("\n\nV: %i %i\n",v[0], v[1]);
printf("T: %i %i\n",t[0], t[1]);
printf("R: %i %i\n",r[0], r[1]);
return 0;
}
Thank you very much Ian.
______________________________________________________________________
Yahoo! Mail: 6MB di spazio gratuito, 30MB per i tuoi allegati, l'antivirus, il filtro Anti-spam
http://it.yahoo.com/mail_it/foot/?http://it.mail.yahoo.com/
More information about the Gcc-help
mailing list