[Issue 20112] New: __vector casts don't do type conversions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 7 01:46:16 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20112

          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 at puremagic.com
          Reporter: thomas.bockman at 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;
    writeln(i[0]);
}

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
double
2) VPSHUFB to truncate int/uint or long/ulong to short/ushort or byte/ubyte

--


More information about the Digitalmars-d-bugs mailing list