mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 05:30:13 +03:00
49 lines
1.3 KiB
Text
49 lines
1.3 KiB
Text
Strict implicit conversion rules for Vector types
|
|
|
|
Previously, the compiler allowed any `__vector` type to be implicitly
|
|
convertible with any other `__vector` type.
|
|
|
|
---
|
|
int4 x = 2;
|
|
float8 y = x;
|
|
short8 z = y / 3;
|
|
---
|
|
|
|
In this release, `__vector` types now, like static arrays, can only be
|
|
implicitly converted to either qualified types of itself, or void.
|
|
|
|
---
|
|
const int4 a = 5;
|
|
int4 b = a; // OK, both are int4
|
|
void16 c = a; // OK, cast to void of same size.
|
|
float4 d = b; // Error, cannot implicitly convert int4 to float4.
|
|
---
|
|
|
|
Explicit conversions between `__vector` types can be done, but only between
|
|
vectors of the same size.
|
|
|
|
---
|
|
long2 a = 8;
|
|
short8 b = cast(short8)a; // OK
|
|
short16 c = cast(short16)b; // Error, cannot cast because of different sizes.
|
|
---
|
|
|
|
Users of the `__simd` and `__simd_sto` intrinsics will have to either add
|
|
explicit casts from void16 to the appropriate type at each use, or operate
|
|
strictly with void16 vectors until a value is required to be peeked.
|
|
|
|
---
|
|
float4 fun1(float4 a, float4 b)
|
|
{
|
|
a = cast(float4)__simd(XMM.ADDPD, a, b);
|
|
a = cast(float4)__simd(XMM.ADDSS, a, b);
|
|
return a;
|
|
}
|
|
|
|
float4 fun2(void16 a, void16 b)
|
|
{
|
|
a = __simd(XMM.ADDPD, a, b);
|
|
a = __simd(XMM.ADDSS, a, b);
|
|
return cast(float4)a;
|
|
}
|
|
---
|