[Issue 9039] New: __vector() support in template type resolution
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Nov 17 07:37:09 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9039
Summary: __vector() support in template type resolution
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: turkeyman at gmail.com
--- Comment #0 from Manu <turkeyman at gmail.com> 2012-11-17 07:37:06 PST ---
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.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list