www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20112] New: __vector casts don't do type conversions


          Issue ID: 20112
           Summary: __vector casts don't do type conversions
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: thomas.bockman gmail.com

This program should print 3, but instead it prints 1077936128, as if I had
asked for a reinterpret cast instead of conversion.

void main() {
    import std.stdio;
    __vector(float[4]) f = [3, 2, 1, 0];
    __vector(int[4]) i = cast(__vector(int[4])) f;

This problem affects nearly all combinations of component types. The compiler
needs to emit actual conversion instructions, not just typed moves. From my
research, the fastest combination on X86_64 with AVX seems to be:

0) VPMOVSX or VPMOVZX to extend byte, ubyte, short, or ushort
1) VCVT to convert between any combination of int, uint, long, ulong, float, or
2) VPSHUFB to truncate int/uint or long/ulong to short/ushort or byte/ubyte

Aug 06 2019