October 29, 2010 Re: How to initialize static array member variable? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen kjaeraas | > 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...
Who knows.
At least it was a nice exercise in writing SSE :)
|
October 29, 2010 Re: How to initialize static array member variable? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | Trass3r <un@known.com> wrote: >> 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 > > What a pity! Actually, after a bit of hacking, I have found a way: // new helper function static private bool noCharsRepeated( string s ) { foreach ( i, e1; s[0..$-1]) foreach ( e2; s[i+1..$] ) if ( e1 == e2 ) return false; return true; } /// swizzling template opDispatch( string n ) { @property Vector!(T,n.length) opDispatch( U... )( U args ) if (allCharsValid(n,"xyzw"[0..dim]) && (U.length == 0 || (U.length == 1 && is(U[0] == Vector!(T,n.length)) && noCharsRepeated(n)))) { static if ( U.length == 1 ) { static if ( n.length >= 1 ) cell[n[0]-'x'] = args[0].cell[0]; static if ( n.length >= 2 ) cell[n[1]-'x'] = args[0].cell[1]; static if ( n.length >= 3 ) cell[n[2]-'x'] = args[0].cell[2]; static if ( n.length >= 4 ) cell[n[3]-'x'] = args[0].cell[3]; } 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']); } } The signature might not exactly be clean, but it works. -- Simen |
Copyright © 1999-2021 by the D Language Foundation