[macstl-dev] gcc 3.3 on YellowDogLinux
Glen Low
glen.low at pixelglow.com
Fri Mar 25 22:33:05 WST 2005
On 25/03/2005, at 9:42 PM, Michael LeBlanc wrote:
>> About the cast, is the intent just to change type? You don't want
>> any code generated, do you?
>
> A simple cast compiles. Here's the generated code code:
>
> lis 11,_ZZNK9generatorILj0EEclEvE2un at ha
> la 11,_ZZNK9generatorILj0EEclEvE2un at l(11)
> lis 9,zz at ha
> la 9,zz at l(9)
> lvx 0,0,11
> stvx 0,0,9
>
> which is as simple as you can get.
Now we're getting somewhere, at least we know mainline gcc borks when
typedef'ing a __vector type within a C++ scope (class scope). Need to
test whether this is OK for a namespace that surrounds the struct
generator, since I'd rather the typedef be hidden in stdext::impl.
As for the cast, it's just changing type. All constant generation is
bottlenecked at compile time through the generator class, so there's
opportunity to substitute generation sequences via explicit
specialization that avoids the slow L2 cache loads. At the generator
level it really doesn't matter whether it's a char, short, int or
float, we just want the bit pattern.
> More silliness. On line 29 below, replace "VUC" by "(VUC)", a C-style
> cast, and it draws a parse error.
>
> 1 #include <altivec.h>
> 2
> 3 #ifdef USE_TYPEDEF
> 4 typedef __vector unsigned int VUT;
> 5 typedef __vector unsigned char VUC;
> 6 #endif
> 7
> 8 template <unsigned int v0> struct generator
> 9 {
> 10 #ifdef USE_TYPEDEF
> 11 VUT
> 12 #else
> 13 __vector unsigned int
> 14 #endif
> 15 operator() () const
> 16 {
> 17 union union_type
> 18 {
> 19 unsigned int val [4];
> 20 __vector unsigned int vec;
> 21 };
> 22 static const union_type un = {v0, v0, v0, v0};
> 23 return un.vec;
> 24 }
> 25 };
> 26
> 27 __vector unsigned char zz =
> 28 // static_cast <VUC>
> 29 VUC
> 30 (generator <0> () ())
> 31 ;
Perhaps, but just plain VUC is a syntax error since it's not a cast.
You need to cast with (VUC).
I've seen a gcc version 4.0 that doesn't like static_cast to a __vector
type, and prefers the C-style cast as you've said. If (VUC) doesn't
work, then you have to use (__vector unsigned char) after all.
After all this messiness, take heart. The evil that lies in the heart
of SIMD compilers was meant to be well hidden in vec_altivec.h and
vec_mmx.h. If we do our job well, the library clients need never see or
touch this stuff themselves.
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
aim: pixglen
More information about the macstl-dev
mailing list