1 ! (c)Joe Groff bsd license
2 USING: accessors arrays compiler.test continuations generalizations
3 kernel kernel.private locals math.vectors.conversion math.vectors.simd
4 sequences stack-checker tools.test sequences.generalizations ;
5 FROM: alien.c-types => char uchar short ushort int uint longlong ulonglong float double ;
6 IN: math.vectors.conversion.tests
8 ERROR: optimized-vconvert-inconsistent
12 MACRO:: test-vconvert ( from-type to-type -- quot )
13 [ from-type to-type vconvert ] :> quot
15 effect in>> length :> inputs
16 effect out>> length :> outputs
18 inputs from-type <array> :> declaration
22 [ quot with-datastack ]
23 [ [ [ declaration declare quot call ] compile-call ] with-datastack ] bi
24 2dup = [ throw-optimized-vconvert-inconsistent ] unless
28 [ uint-4{ 5 1 2 6 } int-4 float-4 vconvert ]
29 [ bad-vconvert-input? ] must-fail-with
31 [ int-4{ 1 2 3 4 } uint-4{ 5 1 2 6 } int-4 short-8 vconvert ]
32 [ bad-vconvert-input? ] must-fail-with
34 [ uint-4{ 1 2 3 4 } int-4{ 5 1 2 6 } int-4 short-8 vconvert ]
35 [ bad-vconvert-input? ] must-fail-with
37 [ uint-4{ 5 1 2 6 } int-4 longlong-2 vconvert ]
38 [ bad-vconvert-input? ] must-fail-with
40 { float-4{ -5.0 1.0 2.0 6.0 } }
41 [ int-4{ -5 1 2 6 } int-4 float-4 test-vconvert ] unit-test
44 [ float-4{ -5.0 1.0 2.0 6.0 } float-4 int-4 test-vconvert ] unit-test
47 [ float-4{ -5.0 1.0 2.3 6.7 } float-4 int-4 test-vconvert ] unit-test
49 { double-2{ -5.0 1.0 } }
50 [ longlong-2{ -5 1 } longlong-2 double-2 test-vconvert ] unit-test
52 { longlong-2{ -5 1 } }
53 [ double-2{ -5.0 1.0 } double-2 longlong-2 test-vconvert ] unit-test
55 ! TODO we should be able to do double->int pack
56 ! [ int-4{ -5 1 12 34 } ]
57 [ double-2{ -5.0 1.0 } double-2{ 12.0 34.0 } double-2 int-4 test-vconvert ]
58 [ error>> bad-vconvert? ] must-fail-with
60 { float-4{ -1.25 2.0 3.0 -4.0 } }
61 [ double-2{ -1.25 2.0 } double-2{ 3.0 -4.0 } double-2 float-4 test-vconvert ] unit-test
63 { int-4{ -1 2 3 -4 } }
64 [ longlong-2{ -1 2 } longlong-2{ 3 -4 } longlong-2 int-4 test-vconvert ] unit-test
66 { short-8{ -1 2 3 -32768 5 32767 -7 32767 } }
67 [ int-4{ -1 2 3 -40000 } int-4{ 5 60000 -7 80000 } int-4 short-8 test-vconvert ] unit-test
69 { short-8{ -1 2 3 -32768 5 32767 -7 32767 } }
71 int-4{ -1 2 3 -40000 }
72 int-4{ 5 60000 -7 80000 } int-4 short-8 test-vconvert
75 { ushort-8{ 0 2 3 0 5 60000 0 65535 } }
76 [ int-4{ -1 2 3 -40000 } int-4{ 5 60000 -7 80000 } int-4 ushort-8 test-vconvert ] unit-test
78 { ushort-8{ 65535 2 3 65535 5 60000 65535 65535 } }
79 [ uint-4{ -1 2 3 -40000 } uint-4{ 5 60000 -7 80000 } uint-4 ushort-8 test-vconvert ] unit-test
81 [ uint-4{ -1 2 3 -40000 } uint-4{ 5 60000 -7 80000 } uint-4 short-8 test-vconvert ]
82 [ error>> bad-vconvert? ] must-fail-with
84 { ushort-8{ 0 1 2 3 128 129 130 131 } ushort-8{ 4 5 6 7 132 133 134 135 } }
86 uchar-16{ 0 1 2 3 128 129 130 131 4 5 6 7 132 133 134 135 }
87 uchar-16 ushort-8 test-vconvert
90 { double-2{ -1.25 2.0 } double-2{ 3.0 -4.0 } }
91 [ float-4{ -1.25 2.0 3.0 -4.0 } float-4 double-2 test-vconvert ] unit-test
93 { int-4{ -1 2 3 -4 } }
94 [ int-4{ -1 2 3 -4 } int-4 int-4 test-vconvert ] unit-test
96 { longlong-2{ -1 2 } longlong-2{ 3 -4 } }
97 [ int-4{ -1 2 3 -4 } int-4 longlong-2 test-vconvert ] unit-test
99 [ int-4{ -1 2 3 -4 } int-4 ulonglong-2 test-vconvert ]
100 [ error>> bad-vconvert? ] must-fail-with
102 { ulonglong-2{ 1 2 } ulonglong-2{ 3 4 } }
103 [ uint-4{ 1 2 3 4 } uint-4 ulonglong-2 test-vconvert ] unit-test
105 { longlong-2{ 1 2 } longlong-2{ 3 4 } }
106 [ uint-4{ 1 2 3 4 } uint-4 longlong-2 test-vconvert ] unit-test
108 { int-4{ 1 2 -3 -4 } int-4{ 5 -6 7 -8 } }
109 [ short-8{ 1 2 -3 -4 5 -6 7 -8 } short-8 int-4 test-vconvert ] unit-test
111 { uint-4{ 1 2 3 4 } uint-4{ 5 6 7 8 } }
112 [ ushort-8{ 1 2 3 4 5 6 7 8 } ushort-8 uint-4 test-vconvert ] unit-test
114 { longlong-2{ 1 2 } longlong-2{ 3 4 } }
115 [ uint-4{ 1 2 3 4 } uint-4 longlong-2 test-vconvert ] unit-test
117 ! TODO we should be able to do multi-tier pack/unpack
118 ! [ longlong-2{ 1 2 } longlong-2{ 3 4 } longlong-2{ 5 6 } longlong-2{ 7 8 } ]
119 [ ushort-8{ 1 2 3 4 5 6 7 8 } ushort-8 longlong-2 test-vconvert ]
120 [ error>> bad-vconvert? ] must-fail-with
122 ! [ ushort-8{ 1 2 3 4 5 6 7 8 } ]
128 longlong-2 ushort-8 test-vconvert
130 [ error>> bad-vconvert? ] must-fail-with