]> gitweb.factorcode.org Git - factor.git/blob - basis/math/vectors/conversion/conversion-tests.factor
85416f294ee27a04fc62222f53e513d75a53ae15
[factor.git] / basis / math / vectors / conversion / conversion-tests.factor
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
7
8 ERROR: optimized-vconvert-inconsistent
9     unoptimized-result
10     optimized-result ;
11
12 MACRO:: test-vconvert ( from-type to-type -- quot )
13     [ from-type to-type vconvert ] :> quot
14     quot infer :> effect
15     effect in>> length :> inputs
16     effect out>> length :> outputs
17
18     inputs from-type <array> :> declaration
19
20     [
21         inputs narray
22         [ quot with-datastack ]
23         [ [ [ declaration declare quot call ] compile-call ] with-datastack ] bi
24         2dup = [ optimized-vconvert-inconsistent ] unless
25         drop outputs firstn
26     ] ;
27
28 [ uint-4{ 5 1 2 6 } int-4 float-4 vconvert ]
29 [ bad-vconvert-input? ] must-fail-with
30
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
33
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
36
37 [ uint-4{ 5 1 2 6 } int-4 longlong-2 vconvert ]
38 [ bad-vconvert-input? ] must-fail-with
39
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
42
43 { int-4{ -5 1 2 6 } }
44 [ float-4{ -5.0 1.0 2.0 6.0 } float-4 int-4 test-vconvert ] unit-test
45
46 { int-4{ -5 1 2 6 } }
47 [ float-4{ -5.0 1.0 2.3 6.7 } float-4 int-4 test-vconvert ] unit-test
48
49 { double-2{ -5.0 1.0 } }
50 [ longlong-2{ -5 1 } longlong-2 double-2 test-vconvert ] unit-test
51
52 { longlong-2{ -5 1 } }
53 [ double-2{ -5.0 1.0 } double-2 longlong-2 test-vconvert ] unit-test
54
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
59
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
62
63 { int-4{ -1 2 3 -4 } }
64 [ longlong-2{ -1 2 } longlong-2{ 3 -4 } longlong-2 int-4 test-vconvert ] unit-test
65
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
68
69 { short-8{ -1 2 3 -32768 5 32767 -7 32767 } }
70 [
71     int-4{ -1 2 3 -40000 }
72     int-4{ 5 60000 -7 80000 } int-4 short-8 test-vconvert
73 ] unit-test
74
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
77
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
80
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
83
84 { ushort-8{ 0 1 2 3 128 129 130 131 } ushort-8{ 4 5 6 7 132 133 134 135 } }
85 [
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
88 ] unit-test
89
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
92
93 { int-4{ -1 2 3 -4 } }
94 [ int-4{ -1 2 3 -4 } int-4 int-4 test-vconvert ] unit-test
95
96 { longlong-2{ -1 2 } longlong-2{ 3 -4 } }
97 [ int-4{ -1 2 3 -4 } int-4 longlong-2 test-vconvert ] unit-test
98
99 [ int-4{ -1 2 3 -4 } int-4 ulonglong-2 test-vconvert ]
100 [ error>> bad-vconvert? ] must-fail-with
101
102 { ulonglong-2{ 1 2 } ulonglong-2{ 3 4 } }
103 [ uint-4{ 1 2 3 4 } uint-4 ulonglong-2 test-vconvert ] unit-test
104
105 { longlong-2{ 1 2 } longlong-2{ 3 4 } }
106 [ uint-4{ 1 2 3 4 } uint-4 longlong-2 test-vconvert ] unit-test
107
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
110
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
113
114 { longlong-2{ 1 2 } longlong-2{ 3 4 } }
115 [ uint-4{ 1 2 3 4 } uint-4 longlong-2 test-vconvert ] unit-test
116
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
121
122 ! [ ushort-8{ 1 2 3 4 5 6 7 8 } ]
123 [
124     longlong-2{ 1 2 }
125     longlong-2{ 3 4 }
126     longlong-2{ 5 6 }
127     longlong-2{ 7 8 }
128     longlong-2 ushort-8 test-vconvert
129 ]
130 [ error>> bad-vconvert? ] must-fail-with