Bug 9039 – __vector() support in template type resolution

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-17T07:37:00Z
Last change time
2012-11-19T17:00:23Z
Assigned to
nobody
Creator
turkeyman

Comments

Comment #0 by turkeyman — 2012-11-17T07:37:06Z
It would be really convenient if I could do this: template someTemplate(T : __vector(U[N]), U, size_t N) { // code... } Where T is a simd ('__vector()') type, and I could infer U and N this way. This would allow me to build a bunch of simd related templates in a sane way, and conveniently add simd awareness to existing templates in std.traits. Currently they tend to look like this (testing 'is' every possible type that matches): template isSIMD(T) { static if(is(T == double2) || is(T == float4) || is(T == long2) || is(T == ulong2) || is(T == int4) || is(T == uint4) || is(T == short8) || is(T == ushort8) || is(T == byte16) || is(T == ubyte16) || is(T == void16)) enum bool isVector = true; else enum bool isVector = false; } You'll even notice there is a bug in this code; 256bit vector types were added more recently, and this code wasn't updated... It would all work properly (and future-proof) if I could do it this way: template isSIMD(T : __vector(U[N]), U, size_t N) { enum bool isSIMD = true; } template isSIMD(T) { enum bool isSIMD = false; } And obvious extrapolations: elementType!(), numElements!(), etc. I could then also add support for SIMD types to the std.traits templates such as Signed!, Unsigned!, etc, rather trivially, and also simplify a lot of other code in the std.simd WIP.
Comment #1 by bugzilla — 2012-11-17T13:16:08Z
This already works (it's in the test suite): void BaseTypeOfVector(T : __vector(T[N]), size_t N)(int i) { assert(is(T == int)); assert(N == 4); } void test7411() { BaseTypeOfVector!(__vector(int[4]))(3); }
Comment #2 by turkeyman — 2012-11-17T15:19:13Z
Huzzah! :) It didn't work when I first tried it some time back. I should have tried it again!
Comment #3 by bugzilla — 2012-11-19T16:39:41Z
Guess we can close this, then!
Comment #4 by turkeyman — 2012-11-19T17:00:23Z
(In reply to comment #3) > Guess we can close this, then! Yeah go for it. Sorry for opening a redundant ticket >_<