public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re:Re: help with MMX and inline asm (all ok)
@ 2004-04-10 11:27 Andrea Pretto
  0 siblings, 0 replies; 2+ messages in thread
From: Andrea Pretto @ 2004-04-10 11:27 UTC (permalink / raw)
  To: gcc-help

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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re:Re: help with MMX and inline asm (all ok)
@ 2004-04-09  9:09 Andrea Pretto
  0 siblings, 0 replies; 2+ messages in thread
From: Andrea Pretto @ 2004-04-09  9:09 UTC (permalink / raw)
  To: gcc-help

All ok

----------------------------------------------------
#include <stdio.h>

//file: mmx.c
// gcc -o mmx -Wall -mmmx mmx.c ( it run also without
-mmmx flag)

int main ( void ){
  int v[2] = { 5, 8};
  int t[2] = { 6, 17};
  int r[2] = { 0, 0};
  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]);
    asm (
       "movq %0 , %%mm1\n\t"
       "movq %1 , %%mm0\n\t"
       "paddd %%mm0, %%mm1\n\t"
       "movq %%mm1, %2\n\t"
       :"=m" (v[0]) // %0 first array
       :"m" (t[0]), // %1 second array
       "m" (r[0]) // %2 result
       );
   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;
}
-----------------------------------------------

______________________________________________________________________
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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-04-10 11:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-10 11:27 Re:Re: help with MMX and inline asm (all ok) Andrea Pretto
  -- strict thread matches above, loose matches on Subject: below --
2004-04-09  9:09 Andrea Pretto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).