[clug] gcc3.3 + 3dNOW bug?

Paul Matthews plm at pcug.org.au
Sat Sep 11 02:28:04 GMT 2004


Hi Guys,

I was mucking around with 3dNOW and gcc3.3, and I think I've found a 
bug. Thought I might post it here first. As you can see, the result in 
vector 'c' is correct, but the input vector 'a' has been damaged.

$ cat test.cc

#include <stdio.h>

typedef int V2SF __attribute__((mode(V2SF)));

struct vec2f {
   union {
     V2SF vec;
     struct {
       float x;
       float y;
     };
   };

   vec2f(){};
   vec2f( const vec2f& v )
   : vec(v.vec)
     {};
   vec2f( const V2SF& v )
   : vec(v)
     {};
   vec2f( float x, float y)
   : x(x), y(y)
     {};
};


inline vec2f mul( const vec2f &a, const vec2f &b )
{ return vec2f( __builtin_ia32_pfmul(a.vec,b.vec) ); }


int main()
{
   vec2f a( 1.0, 2.0 );
   vec2f b( 3.0, 4.0 );

   printf( "a = %g %g\n", a.x, a.y );
   printf( "b = %g %g\n", b.x, b.y );
   printf( "mul\n" );
   vec2f c = mul(a,b);
   printf( "a = %g %g\n", a.x, a.y );
   printf( "b = %g %g\n", b.x, b.y );
   printf( "c = %g %g\n", c.x, c.y );
   return 0;
};


$ g++ -o test -O3 -fno-strict-aliasing -march=athlon-xp
       -mmmx -msse -m3dnow test.cc
$ ./test
a = 1 2
b = 3 4
mul
a = 1 0
b = 3 4
c = 3 8



More information about the linux mailing list