public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* vector bug?
@ 2004-03-19 15:34 Not Real
  2004-03-19 15:38 ` Segher Boessenkool
  0 siblings, 1 reply; 3+ messages in thread
From: Not Real @ 2004-03-19 15:34 UTC (permalink / raw)
  To: gcc-help

Hi, I'm using gcc 3.4.0 20040305, on a pentium 4 red
hat system.  I'm trying to use the vector extensions. 
When I compile the following code with -O0 or -O1, it
does as I expect (it prints whatever was input plus
{1,2,3,4}.  When I compile with -O2 or -O3 on the
other hand, it prints garbage.  From the disassembly,
it is apparent that it is just not putting the right
arguments on the stack for the printf call.  Is my
code incorrect, or is this an optimization bug?

#include <stdio.h>

int main() {
  typedef int v4si __attribute__ ((mode(V4SI)));
  
  int vals[4];
  int ins[4];

  scanf("%d %d %d %d", &ins[0], &ins[1], &ins[2],
&ins[3]);
  v4si a = *(v4si*)ins, b = {1, 2, 3, 4}, c;

  c = a + b;
  *(v4si*)vals = c;
  printf("%d %d %d %d\n", vals[0], vals[1], vals[2],
vals[3]);
}

__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com

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

* Re: vector bug?
  2004-03-19 15:34 vector bug? Not Real
@ 2004-03-19 15:38 ` Segher Boessenkool
  0 siblings, 0 replies; 3+ messages in thread
From: Segher Boessenkool @ 2004-03-19 15:38 UTC (permalink / raw)
  To: Not Real; +Cc: gcc-help

>   v4si a = *(v4si*)ins, b = {1, 2, 3, 4}, c;

>   *(v4si*)vals = c;

You can't do this.  Your accessing an object of one type
(int) as an other type (v4si).

You'll have to go through a union to do this safely
(this is a GCC extension).  Like:

	union { v4si v; int i[4]; } convert;
	convert.v = c;

...and then print convert.i[0] etc.


Segher

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

* vector bug?
@ 2004-03-19 15:37 Not Real
  0 siblings, 0 replies; 3+ messages in thread
From: Not Real @ 2004-03-19 15:37 UTC (permalink / raw)
  To: gcc-help

Hi, I'm using gcc 3.4.0 20040305, on a pentium 4 red
hat system.  I'm trying to use the vector extensions. 
When I compile the following code with -O0 or -O1, it
does as I expect (it prints whatever was input plus
{1,2,3,4}.  When I compile with -O2 or -O3 on the
other hand, it prints garbage.  From the disassembly,
it is apparent that it is just not putting the right
arguments on the stack for the printf call.  Is my
code incorrect, or is this an optimization bug?

#include <stdio.h>

int main() {
  typedef int v4si __attribute__ ((mode(V4SI)));
  
  int vals[4];
  int ins[4];

  scanf("%d %d %d %d", &ins[0], &ins[1], &ins[2],
&ins[3]);
  v4si a = *(v4si*)ins, b = {1, 2, 3, 4}, c;

  c = a + b;
  *(v4si*)vals = c;
  printf("%d %d %d %d\n", vals[0], vals[1], vals[2],
vals[3]);
}


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com

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

end of thread, other threads:[~2004-03-19 12:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-19 15:34 vector bug? Not Real
2004-03-19 15:38 ` Segher Boessenkool
2004-03-19 15:37 Not Real

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).