www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9039] New: __vector() support in template type resolution

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: turkeyman gmail.com



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: -------
Nov 17 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9039


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com



13:16:08 PST ---
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);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 17 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9039




Huzzah! :)
It didn't work when I first tried it some time back. I should have tried it
again!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 17 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9039


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME



16:39:41 PST ---
Guess we can close this, then!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 19 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9039





 Guess we can close this, then!
Yeah go for it. Sorry for opening a redundant ticket >_< -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 19 2012