How to initialize static array member variable?

Simen kjaeraas simen.kjaras at gmail.com
Fri Oct 1 04:47:24 PDT 2010


Simen kjaeraas <simen.kjaras at gmail.com> wrote:

> Trass3r <un at known.com> wrote:
>
>> Here's a basic D2 fixed-size vector implementation for you to study:  
>> http://sfml.svn.sourceforge.net/viewvc/sfml/branches/sfml2/DSFML/import/dsfml/system/vector.d?view=markup
>
> I can't help but wonder if those neat SSE functions are a waste.
> Functions that use inline assembly cannot be inlined, and thus aren't
> necessarily faster than using good old x87. Now, if only DMD had some
> intrinsics for that...

Oh, and also (if you don't mind my nitpicking), have you profiled
invSqrt compared to 1/sqrt? Last time I did, I found that invSqrt
was about 50% slower than 1/sqrt.

The one thing I missed when looking at the code was swizzling, so
I implemented it. Feel free to include it if you want, I will
demand nothing for it:


     @property Vector!(T,n.length) opDispatch(string n)() const
         if (allCharsValid(n,"xyzw"[0..dim]))
     {
         static if (n.length == 2) return  
Vector!(T,n.length)(cell[n[0]-'x'], cell[n[1]-'x']);
         static if (n.length == 3) return  
Vector!(T,n.length)(cell[n[0]-'x'], cell[n[1]-'x'], cell[n[2]-'x']);
         static if (n.length == 4) return  
Vector!(T,n.length)(cell[n[0]-'x'], cell[n[1]-'x'], cell[n[2]-'x'],  
cell[n[3]-'x']);
     }

bool allCharsValid( string s, string valid )
{
     foreach ( e1; s )
     {
         bool b = false;
         foreach (e2; valid)
             b |= e1 == e2;
         if (!b)
             return false;
     }
     return true;
}

I also wanted to allow for swizzled setters, but apparently that's
currently not possible[1].

[1]: http://d.puremagic.com/issues/show_bug.cgi?id=620
-- 
Simen


More information about the Digitalmars-d-learn mailing list