]> gitweb.factorcode.org Git - factor.git/blob - basis/math/vectors/conversion/conversion-tests.factor
Switch to https urls
[factor.git] / basis / math / vectors / conversion / conversion-tests.factor
1 ! Copyright (C) 2009 Joe Groff.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays compiler.test continuations generalizations
4 kernel kernel.private locals math.vectors.conversion math.vectors.simd
5 sequences stack-checker tools.test sequences.generalizations ;
6 FROM: alien.c-types => char uchar short ushort int uint longlong ulonglong float double ;
7 IN: math.vectors.conversion.tests
8
9 ERROR: optimized-vconvert-inconsistent
10     unoptimized-result
11     optimized-result ;
12
13 MACRO:: test-vconvert ( from-type to-type -- quot )
14     [ from-type to-type vconvert ] :> quot
15     quot infer :> effect
16     effect in>> length :> inputs
17     effect out>> length :> outputs
18
19     inputs from-type <array> :> declaration
20
21     [
22         inputs narray
23         [ quot with-datastack ]
24         [ [ [ declaration declare quot call ] compile-call ] with-datastack ] bi
25         2dup = [ optimized-vconvert-inconsistent ] unless
26         drop outputs firstn
27     ] ;
28
29 [ uint-4{ 5 1 2 6 } int-4 float-4 vconvert ]
30 [ bad-vconvert-input? ] must-fail-with
31
32 [ int-4{ 1 2 3 4 } uint-4{ 5 1 2 6 } int-4 short-8 vconvert ]
33 [ bad-vconvert-input? ] must-fail-with
34
35 [ uint-4{ 1 2 3 4 } int-4{ 5 1 2 6 } int-4 short-8 vconvert ]
36 [ bad-vconvert-input? ] must-fail-with
37
38 [ uint-4{ 5 1 2 6 } int-4 longlong-2 vconvert ]
39 [ bad-vconvert-input? ] must-fail-with
40
41 { float-4{ -5.0 1.0 2.0 6.0 } }
42 [ int-4{ -5 1 2 6 } int-4 float-4 test-vconvert ] unit-test
43
44 { int-4{ -5 1 2 6 } }
45 [ float-4{ -5.0 1.0 2.0 6.0 } float-4 int-4 test-vconvert ] unit-test
46
47 { int-4{ -5 1 2 6 } }
48 [ float-4{ -5.0 1.0 2.3 6.7 } float-4 int-4 test-vconvert ] unit-test
49
50 { double-2{ -5.0 1.0 } }
51 [ longlong-2{ -5 1 } longlong-2 double-2 test-vconvert ] unit-test
52
53 { longlong-2{ -5 1 } }
54 [ double-2{ -5.0 1.0 } double-2 longlong-2 test-vconvert ] unit-test
55
56 ! TODO we should be able to do double->int pack
57 ! [ int-4{ -5 1 12 34 } ]
58 [ double-2{ -5.0 1.0 } double-2{ 12.0 34.0 } double-2 int-4 test-vconvert ]
59 [ error>> bad-vconvert? ] must-fail-with
60
61 { float-4{ -1.25 2.0 3.0 -4.0 } }
62 [ double-2{ -1.25 2.0 } double-2{ 3.0 -4.0 } double-2 float-4 test-vconvert ] unit-test
63
64 { int-4{ -1 2 3 -4 } }
65 [ longlong-2{ -1 2 } longlong-2{ 3 -4 } longlong-2 int-4 test-vconvert ] unit-test
66
67 { short-8{ -1 2 3 -32768 5 32767 -7 32767 } }
68 [ int-4{ -1 2 3 -40000 } int-4{ 5 60000 -7 80000 } int-4 short-8 test-vconvert ] unit-test
69
70 { short-8{ -1 2 3 -32768 5 32767 -7 32767 } }
71 [
72     int-4{ -1 2 3 -40000 }
73     int-4{ 5 60000 -7 80000 } int-4 short-8 test-vconvert
74 ] unit-test
75
76 { ushort-8{ 0 2 3 0 5 60000 0 65535 } }
77 [ int-4{ -1 2 3 -40000 } int-4{ 5 60000 -7 80000 } int-4 ushort-8 test-vconvert ] unit-test
78
79 { ushort-8{ 65535 2 3 65535 5 60000 65535 65535 } }
80 [ uint-4{ -1 2 3 -40000 } uint-4{ 5 60000 -7 80000 } uint-4 ushort-8 test-vconvert ] unit-test
81
82 [ uint-4{ -1 2 3 -40000 } uint-4{ 5 60000 -7 80000 } uint-4 short-8 test-vconvert ]
83 [ error>> bad-vconvert? ] must-fail-with
84
85 { ushort-8{ 0 1 2 3 128 129 130 131 } ushort-8{ 4 5 6 7 132 133 134 135 } }
86 [
87     uchar-16{ 0 1 2 3 128 129 130 131 4 5 6 7 132 133 134 135 }
88     uchar-16 ushort-8 test-vconvert
89 ] unit-test
90
91 { double-2{ -1.25 2.0 } double-2{ 3.0 -4.0 } }
92 [ float-4{ -1.25 2.0 3.0 -4.0 } float-4 double-2 test-vconvert ] unit-test
93
94 { int-4{ -1 2 3 -4 } }
95 [ int-4{ -1 2 3 -4 } int-4 int-4 test-vconvert ] unit-test
96
97 { longlong-2{ -1 2 } longlong-2{ 3 -4 } }
98 [ int-4{ -1 2 3 -4 } int-4 longlong-2 test-vconvert ] unit-test
99
100 [ int-4{ -1 2 3 -4 } int-4 ulonglong-2 test-vconvert ]
101 [ error>> bad-vconvert? ] must-fail-with
102
103 { ulonglong-2{ 1 2 } ulonglong-2{ 3 4 } }
104 [ uint-4{ 1 2 3 4 } uint-4 ulonglong-2 test-vconvert ] unit-test
105
106 { longlong-2{ 1 2 } longlong-2{ 3 4 } }
107 [ uint-4{ 1 2 3 4 } uint-4 longlong-2 test-vconvert ] unit-test
108
109 { int-4{ 1 2 -3 -4 } int-4{ 5 -6 7 -8 } }
110 [ short-8{ 1 2 -3 -4 5 -6 7 -8 } short-8 int-4 test-vconvert ] unit-test
111
112 { uint-4{ 1 2 3 4 } uint-4{ 5 6 7 8 } }
113 [ ushort-8{ 1 2 3 4 5 6 7 8 } ushort-8 uint-4 test-vconvert ] unit-test
114
115 { longlong-2{ 1 2 } longlong-2{ 3 4 } }
116 [ uint-4{ 1 2 3 4 } uint-4 longlong-2 test-vconvert ] unit-test
117
118 ! TODO we should be able to do multi-tier pack/unpack
119 ! [ longlong-2{ 1 2 } longlong-2{ 3 4 } longlong-2{ 5 6 } longlong-2{ 7 8 } ]
120 [ ushort-8{ 1 2 3 4 5 6 7 8 } ushort-8 longlong-2 test-vconvert ]
121 [ error>> bad-vconvert? ] must-fail-with
122
123 ! [ ushort-8{ 1 2 3 4 5 6 7 8 } ]
124 [
125     longlong-2{ 1 2 }
126     longlong-2{ 3 4 }
127     longlong-2{ 5 6 }
128     longlong-2{ 7 8 }
129     longlong-2 ushort-8 test-vconvert
130 ]
131 [ error>> bad-vconvert? ] must-fail-with