OLD | NEW |
---|---|
1 /* crosstest.py --test=test_icmp.cpp --driver=test_icmp_main.cpp \ | 1 //===- subzero/crosstest/test_icmp_main.cpp - Driver for tests. -----------===// |
2 --prefix=Subzero_ --output=test_icmp */ | 2 // |
3 // The Subzero Code Generator | |
4 // | |
5 // This file is distributed under the University of Illinois Open Source | |
6 // License. See LICENSE.TXT for details. | |
7 // | |
8 //===----------------------------------------------------------------------===// | |
9 // | |
10 // Driver for cross testing the icmp bitcode instruction | |
11 // | |
12 //===----------------------------------------------------------------------===// | |
3 | 13 |
14 /* crosstest.py --test=test_icmp.cpp --test=test_icmp_i1vec.ll \ | |
15 --driver=test_icmp_main.cpp --prefix=Subzero_ --output=test_icmp */ | |
16 | |
17 #include <climits> // CHAR_BIT | |
18 #include <cstring> // memcmp, memset | |
4 #include <stdint.h> | 19 #include <stdint.h> |
5 #include <iostream> | 20 #include <iostream> |
6 | 21 |
7 // Include test_icmp.h twice - once normally, and once within the | 22 // Include test_icmp.h twice - once normally, and once within the |
8 // Subzero_ namespace, corresponding to the llc and Subzero translated | 23 // Subzero_ namespace, corresponding to the llc and Subzero translated |
9 // object files, respectively. | 24 // object files, respectively. |
10 #include "test_icmp.h" | 25 #include "test_icmp.h" |
11 namespace Subzero_ { | 26 namespace Subzero_ { |
12 #include "test_icmp.h" | 27 #include "test_icmp.h" |
13 } | 28 } |
(...skipping 14 matching lines...) Expand all Loading... | |
28 const char *Name; | 43 const char *Name; |
29 FuncTypeUnsigned FuncLlc; | 44 FuncTypeUnsigned FuncLlc; |
30 FuncTypeUnsigned FuncSz; | 45 FuncTypeUnsigned FuncSz; |
31 } Funcs[] = { | 46 } Funcs[] = { |
32 #define X(cmp, op) \ | 47 #define X(cmp, op) \ |
33 { \ | 48 { \ |
34 STR(inst), (FuncTypeUnsigned)icmp##cmp, \ | 49 STR(inst), (FuncTypeUnsigned)icmp##cmp, \ |
35 (FuncTypeUnsigned)Subzero_::icmp##cmp \ | 50 (FuncTypeUnsigned)Subzero_::icmp##cmp \ |
36 } \ | 51 } \ |
37 , | 52 , |
38 ICMP_U_TABLE | 53 ICMP_U_TABLE |
39 #undef X | 54 #undef X |
40 #define X(cmp, op) \ | 55 #define X(cmp, op) \ |
41 { \ | 56 { \ |
42 STR(inst), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \ | 57 STR(inst), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \ |
43 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp \ | 58 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp \ |
44 } \ | 59 } \ |
45 , | 60 , |
46 ICMP_S_TABLE | 61 ICMP_S_TABLE |
47 #undef X | 62 #undef X |
48 }; | 63 }; |
49 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); | 64 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
50 | 65 |
51 if (sizeof(TypeUnsigned) <= sizeof(uint32_t)) { | 66 if (sizeof(TypeUnsigned) <= sizeof(uint32_t)) { |
52 // This is the "normal" version of the loop nest, for 32-bit or | 67 // This is the "normal" version of the loop nest, for 32-bit or |
53 // narrower types. | 68 // narrower types. |
54 for (size_t f = 0; f < NumFuncs; ++f) { | 69 for (size_t f = 0; f < NumFuncs; ++f) { |
55 for (size_t i = 0; i < NumValues; ++i) { | 70 for (size_t i = 0; i < NumValues; ++i) { |
56 for (size_t j = 0; j < NumValues; ++j) { | 71 for (size_t j = 0; j < NumValues; ++j) { |
57 TypeUnsigned Value1 = Values[i]; | 72 TypeUnsigned Value1 = Values[i]; |
58 TypeUnsigned Value2 = Values[j]; | 73 TypeUnsigned Value2 = Values[j]; |
59 ++TotalTests; | 74 ++TotalTests; |
60 bool ResultSz = Funcs[f].FuncSz(Value1, Value2); | 75 bool ResultSz = Funcs[f].FuncSz(Value1, Value2); |
61 bool ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | 76 bool ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
62 if (ResultSz == ResultLlc) { | 77 if (ResultSz == ResultLlc) { |
63 ++Passes; | 78 ++Passes; |
64 } else { | 79 } else { |
65 ++Failures; | 80 ++Failures; |
66 std::cout << "icmp" << Funcs[f].Name << (8 * sizeof(TypeUnsigned)) | 81 std::cout << "icmp" << Funcs[f].Name |
67 << "(" << Value1 << ", " << Value2 << "): sz=" << ResultSz | 82 << (CHAR_BIT * sizeof(TypeUnsigned)) << "(" << Value1 |
83 << ", " << Value2 << "): sz=" << ResultSz | |
68 << " llc=" << ResultLlc << std::endl; | 84 << " llc=" << ResultLlc << std::endl; |
69 } | 85 } |
70 } | 86 } |
71 } | 87 } |
72 } | 88 } |
73 } else { | 89 } else { |
74 // This is the 64-bit version. Test values are synthesized from | 90 // This is the 64-bit version. Test values are synthesized from |
75 // the 32-bit values in Values[]. | 91 // the 32-bit values in Values[]. |
76 for (size_t f = 0; f < NumFuncs; ++f) { | 92 for (size_t f = 0; f < NumFuncs; ++f) { |
77 for (size_t iLo = 0; iLo < NumValues; ++iLo) { | 93 for (size_t iLo = 0; iLo < NumValues; ++iLo) { |
78 for (size_t iHi = 0; iHi < NumValues; ++iHi) { | 94 for (size_t iHi = 0; iHi < NumValues; ++iHi) { |
79 for (size_t jLo = 0; jLo < NumValues; ++jLo) { | 95 for (size_t jLo = 0; jLo < NumValues; ++jLo) { |
80 for (size_t jHi = 0; jHi < NumValues; ++jHi) { | 96 for (size_t jHi = 0; jHi < NumValues; ++jHi) { |
81 TypeUnsigned Value1 = | 97 TypeUnsigned Value1 = |
82 (((TypeUnsigned)Values[iHi]) << 32) + Values[iLo]; | 98 (((TypeUnsigned)Values[iHi]) << 32) + Values[iLo]; |
83 TypeUnsigned Value2 = | 99 TypeUnsigned Value2 = |
84 (((TypeUnsigned)Values[jHi]) << 32) + Values[jLo]; | 100 (((TypeUnsigned)Values[jHi]) << 32) + Values[jLo]; |
85 ++TotalTests; | 101 ++TotalTests; |
86 bool ResultSz = Funcs[f].FuncSz(Value1, Value2); | 102 bool ResultSz = Funcs[f].FuncSz(Value1, Value2); |
87 bool ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | 103 bool ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
88 if (ResultSz == ResultLlc) { | 104 if (ResultSz == ResultLlc) { |
89 ++Passes; | 105 ++Passes; |
90 } else { | 106 } else { |
91 ++Failures; | 107 ++Failures; |
92 std::cout << "icmp" << Funcs[f].Name | 108 std::cout << "icmp" << Funcs[f].Name |
93 << (8 * sizeof(TypeUnsigned)) << "(" << Value1 << ", " | 109 << (CHAR_BIT * sizeof(TypeUnsigned)) << "(" << Value1 |
94 << Value2 << "): sz=" << ResultSz | 110 << ", " << Value2 << "): sz=" << ResultSz |
95 << " llc=" << ResultLlc << std::endl; | 111 << " llc=" << ResultLlc << std::endl; |
96 } | 112 } |
97 } | 113 } |
98 } | 114 } |
99 } | 115 } |
100 } | 116 } |
101 } | 117 } |
102 } | 118 } |
103 } | 119 } |
104 | 120 |
121 const static size_t MaxTestsPerFunc = 100000; | |
122 | |
123 template <typename TypeUnsignedLabel, typename TypeSignedLabel> | |
124 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { | |
125 typedef typename Vectors<TypeUnsignedLabel>::Ty TypeUnsigned; | |
126 typedef typename Vectors<TypeSignedLabel>::Ty TypeSigned; | |
127 typedef typename Vectors<TypeUnsignedLabel>::ElementTy ElementTypeUnsigned; | |
128 typedef typename Vectors<TypeSignedLabel>::ElementTy ElementTypeSigned; | |
129 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); | |
130 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); | |
131 static struct { | |
132 const char *Name; | |
133 FuncTypeUnsigned FuncLlc; | |
134 FuncTypeUnsigned FuncSz; | |
135 } Funcs[] = { | |
136 #define X(cmp, op) \ | |
137 { \ | |
138 STR(inst), (FuncTypeUnsigned)icmp##cmp, \ | |
139 (FuncTypeUnsigned)Subzero_::icmp##cmp \ | |
140 } \ | |
141 , | |
142 ICMP_U_TABLE | |
143 #undef X | |
144 #define X(cmp, op) \ | |
145 { \ | |
146 STR(inst), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \ | |
147 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp \ | |
148 } \ | |
149 , | |
150 ICMP_S_TABLE | |
151 #undef X | |
152 }; | |
153 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); | |
154 const static size_t NumElementsInType = Vectors<TypeUnsigned>::NumElements; | |
155 for (size_t f = 0; f < NumFuncs; ++f) { | |
156 PRNG Index; | |
157 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { | |
158 // Initialize the test vectors. | |
159 TypeUnsigned Value1, Value2; | |
160 for (size_t j = 0; j < NumElementsInType;) { | |
161 Value1[j] = Values[Index() % NumValues]; | |
162 Value2[j] = Values[Index() % NumValues]; | |
163 ++j; | |
164 } | |
165 // Perform the test. | |
166 TypeUnsigned ResultSz = Funcs[f].FuncSz(Value1, Value2); | |
167 TypeUnsigned ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | |
168 ++TotalTests; | |
169 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { | |
170 ++Passes; | |
171 } else { | |
172 ++Failures; | |
173 std::cout << "test" << Funcs[f].Name | |
174 << Vectors<TypeUnsignedLabel>::TypeName << "(" | |
175 << vectAsString<TypeUnsignedLabel>(Value1) << "," | |
176 << vectAsString<TypeUnsignedLabel>(Value2) | |
177 << "): sz=" << vectAsString<TypeUnsignedLabel>(ResultSz) | |
178 << " llc=" << vectAsString<TypeUnsignedLabel>(ResultLlc) | |
179 << std::endl; | |
180 } | |
181 } | |
182 } | |
183 } | |
184 | |
185 // True on wraparound | |
jvoung (off chromium)
2014/07/23 18:54:55
nit: "Return true"
wala
2014/07/23 20:40:36
Done.
| |
186 template <typename T> bool incrementI1Vector(typename Vectors<T>::Ty &Vect) { | |
187 size_t Pos = 0; | |
188 const static size_t NumElements = Vectors<T>::NumElements; | |
189 for (Pos = 0; Pos < NumElements; ++Pos) { | |
190 if (Vect[Pos] == 0) { | |
191 Vect[Pos] = 1; | |
192 break; | |
193 } | |
194 Vect[Pos] = 0; | |
195 } | |
196 return (Pos == NumElements); | |
197 } | |
198 | |
199 template <typename T> | |
200 void testsVecI1(size_t &TotalTests, size_t &Passes, size_t &Failures) { | |
201 typedef typename Vectors<T>::Ty Ty; | |
202 typedef Ty (*FuncType)(Ty, Ty); | |
203 static struct { | |
204 const char *Name; | |
205 FuncType FuncLlc; | |
206 FuncType FuncSz; | |
207 } Funcs[] = { | |
208 #define X(cmp, op) \ | |
209 { STR(inst), (FuncType)icmpi1##cmp, (FuncType)Subzero_::icmpi1##cmp } \ | |
210 , | |
211 ICMP_U_TABLE | |
212 ICMP_S_TABLE | |
213 }; | |
214 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); | |
215 const static size_t NumElements = Vectors<T>::NumElements; | |
216 const static size_t MAX_NUMBER_OF_ELEMENTS_FOR_EXHAUSTIVE_TESTING = 8; | |
217 | |
218 // Check if the type is small enough to try all possible input pairs. | |
219 if (NumElements <= MAX_NUMBER_OF_ELEMENTS_FOR_EXHAUSTIVE_TESTING) { | |
220 for (size_t f = 0; f < NumFuncs; ++f) { | |
221 Ty Value1, Value2; | |
222 memset(&Value1, 0, sizeof(Value1)); | |
223 for (bool IsValue1Done = false; !IsValue1Done; | |
224 IsValue1Done = incrementI1Vector<T>(Value1)) { | |
225 memset(&Value2, 0, sizeof(Value2)); | |
226 for (bool IsValue2Done = false; !IsValue2Done; | |
227 IsValue2Done = incrementI1Vector<T>(Value2)) { | |
228 Ty ResultSz = Funcs[f].FuncSz(Value1, Value2); | |
229 Ty ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | |
230 ++TotalTests; | |
231 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { | |
232 ++Passes; | |
233 } else { | |
234 ++Failures; | |
235 std::cout << "test" << Funcs[f].Name << Vectors<T>::TypeName << "(" | |
236 << vectAsString<T>(Value1) << "," | |
237 << vectAsString<T>(Value2) | |
238 << "): sz=" << vectAsString<T>(ResultSz) | |
239 << " llc=" << vectAsString<T>(ResultLlc) << std::endl; | |
240 } | |
241 } | |
242 } | |
243 } | |
244 } else { | |
245 for (size_t f = 0; f < NumFuncs; ++f) { | |
246 PRNG Index; | |
247 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { | |
248 Ty Value1, Value2; | |
249 // Initialize the test vectors. | |
250 for (size_t j = 0; j < NumElements; ++j) { | |
251 Value1[j] = Index() % 2; | |
252 Value2[j] = Index() % 2; | |
253 } | |
254 // Perform the test. | |
255 Ty ResultSz = Funcs[f].FuncSz(Value1, Value2); | |
256 Ty ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | |
257 ++TotalTests; | |
258 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { | |
259 ++Passes; | |
260 } else { | |
261 ++Failures; | |
262 std::cout << "test" << Funcs[f].Name << Vectors<T>::TypeName << "(" | |
263 << vectAsString<T>(Value1) << "," << vectAsString<T>(Value2) | |
264 << "): sz=" << vectAsString<T>(ResultSz) | |
265 << " llc=" << vectAsString<T>(ResultLlc) << std::endl; | |
266 } | |
267 } | |
268 } | |
269 } | |
270 } | |
271 | |
105 int main(int argc, char **argv) { | 272 int main(int argc, char **argv) { |
106 size_t TotalTests = 0; | 273 size_t TotalTests = 0; |
107 size_t Passes = 0; | 274 size_t Passes = 0; |
108 size_t Failures = 0; | 275 size_t Failures = 0; |
109 | 276 |
110 testsInt<uint8_t, int8_t>(TotalTests, Passes, Failures); | 277 testsInt<uint8_t, int8_t>(TotalTests, Passes, Failures); |
111 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); | 278 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); |
112 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); | 279 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); |
113 testsInt<uint64_t, int64_t>(TotalTests, Passes, Failures); | 280 testsInt<uint64_t, int64_t>(TotalTests, Passes, Failures); |
281 testsVecInt<v4ui32, v4si32>(TotalTests, Passes, Failures); | |
282 testsVecInt<v8ui16, v8si16>(TotalTests, Passes, Failures); | |
283 testsVecInt<v16ui8, v16si8>(TotalTests, Passes, Failures); | |
284 testsVecI1<v4i1>(TotalTests, Passes, Failures); | |
285 testsVecI1<v8i1>(TotalTests, Passes, Failures); | |
286 testsVecI1<v16i1>(TotalTests, Passes, Failures); | |
114 | 287 |
115 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes | 288 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
116 << " Failures=" << Failures << "\n"; | 289 << " Failures=" << Failures << "\n"; |
117 return Failures; | 290 return Failures; |
118 } | 291 } |
OLD | NEW |