|
| 1 | +// RUN: %ldc -run %s |
| 2 | + |
| 3 | +import core.simd; |
| 4 | +import ldc.intrinsics; |
| 5 | + |
| 6 | +void main() |
| 7 | +{ |
| 8 | + // Float-to-float: narrowing (double -> float) |
| 9 | + const double2 d2 = [ 1.5, -2.5 ]; |
| 10 | + const f2_narrow = llvm_convertvector!(float2)(d2); |
| 11 | + assert(f2_narrow is [ 1.5f, -2.5f ]); |
| 12 | + |
| 13 | + // Float-to-float: widening (float -> double) |
| 14 | + const float2 f2 = [ 3.25f, -1.75f ]; |
| 15 | + const d2_widen = llvm_convertvector!(double2)(f2); |
| 16 | + assert(d2_widen is [ 3.25, -1.75 ]); |
| 17 | + |
| 18 | + // Int-to-int: widening signed (short -> int) |
| 19 | + const short4 s4 = [ 1, -2, 3, -4 ]; |
| 20 | + const i4_widen = llvm_convertvector!(int4)(s4); |
| 21 | + assert(i4_widen is [ 1, -2, 3, -4 ]); |
| 22 | + |
| 23 | + // Int-to-int: widening unsigned (ushort -> uint) |
| 24 | + const ushort4 us4 = [ 1, 2, 3, 4 ]; |
| 25 | + const ui4_widen = llvm_convertvector!(uint4)(us4); |
| 26 | + assert(ui4_widen is [ 1, 2, 3, 4 ]); |
| 27 | + |
| 28 | + // Int-to-int: narrowing (long -> int) |
| 29 | + const long4 l4 = [ 1000000L, -2000000L, 3000000L, -4000000L ]; |
| 30 | + const i4_narrow = llvm_convertvector!(int4)(l4); |
| 31 | + assert(i4_narrow is [ 1000000, -2000000, 3000000, -4000000 ]); |
| 32 | + |
| 33 | + // Int-to-float: signed |
| 34 | + const int4 i4 = [ 1, -2, 3, -4 ]; |
| 35 | + const f4_from_i4 = llvm_convertvector!(float4)(i4); |
| 36 | + assert(f4_from_i4 is [ 1.0f, -2.0f, 3.0f, -4.0f ]); |
| 37 | + |
| 38 | + // Int-to-float: unsigned |
| 39 | + const uint4 ui4 = [ 1, 2, 3, 4 ]; |
| 40 | + const f4_from_ui4 = llvm_convertvector!(float4)(ui4); |
| 41 | + assert(f4_from_ui4 is [ 1.0f, 2.0f, 3.0f, 4.0f ]); |
| 42 | + |
| 43 | + // Float-to-int: signed dest |
| 44 | + const float4 f4 = [ 1.5f, -2.7f, 3.2f, -4.9f ]; |
| 45 | + const i4_from_f4 = llvm_convertvector!(int4)(f4); |
| 46 | + assert(i4_from_f4 is [ 1, -2, 3, -4 ]); |
| 47 | + |
| 48 | + // Float-to-int: unsigned dest |
| 49 | + const float4 f4p = [ 1.5f, 2.7f, 3.2f, 4.9f ]; |
| 50 | + const ui4_from_f4 = llvm_convertvector!(uint4)(f4p); |
| 51 | + assert(ui4_from_f4 is [ 1, 2, 3, 4 ]); |
| 52 | +} |
0 commit comments