OLD | NEW |
| 1 //===- subzero/crosstest/test_arith_main.cpp - Driver for tests -----------===// |
| 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 crosstesting arithmetic operations |
| 11 // |
| 12 //===----------------------------------------------------------------------===// |
| 13 |
1 /* crosstest.py --test=test_arith.cpp --test=test_arith_frem.ll \ | 14 /* crosstest.py --test=test_arith.cpp --test=test_arith_frem.ll \ |
2 --test=test_arith_sqrt.ll --driver=test_arith_main.cpp \ | 15 --test=test_arith_sqrt.ll --driver=test_arith_main.cpp \ |
3 --prefix=Subzero_ --output=test_arith */ | 16 --prefix=Subzero_ --output=test_arith */ |
4 | 17 |
5 #include <stdint.h> | 18 #include <stdint.h> |
6 | 19 |
7 #include <climits> // CHAR_BIT | 20 #include <climits> // CHAR_BIT |
8 #include <limits> | 21 #include <limits> |
9 #include <cfloat> | 22 #include <cfloat> |
10 #include <cmath> // fmodf | 23 #include <cmath> // fmodf |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 << " llc=" << (unsigned)ResultLlc << std::endl; | 129 << " llc=" << (unsigned)ResultLlc << std::endl; |
117 } | 130 } |
118 } | 131 } |
119 } | 132 } |
120 } | 133 } |
121 } | 134 } |
122 } | 135 } |
123 } | 136 } |
124 } | 137 } |
125 | 138 |
126 // Vectors are deterministically constructed by selecting elements from | |
127 // a pool of scalar values based on a pseudorandom sequence. Testing | |
128 // all possible combinations of scalar values from the value table is | |
129 // not tractable. | |
130 // TODO: Replace with a portable PRNG from C++11. | |
131 class PRNG { | |
132 public: | |
133 PRNG(uint32_t Seed = 1) : State(Seed) {} | |
134 | |
135 uint32_t operator()() { | |
136 // Lewis, Goodman, and Miller (1969) | |
137 State = (16807 * State) % 2147483647; | |
138 return State; | |
139 } | |
140 | |
141 private: | |
142 uint32_t State; | |
143 }; | |
144 | |
145 const static size_t MaxTestsPerFunc = 100000; | 139 const static size_t MaxTestsPerFunc = 100000; |
146 | 140 |
147 template <typename Type, typename ElementType, typename CastType> | 141 template <typename TypeUnsignedLabel, typename TypeSignedLabel> |
148 void outputVector(const Type Vect) { | 142 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
149 const static size_t NumElementsInType = sizeof(Type) / sizeof(ElementType); | 143 typedef typename Vectors<TypeUnsignedLabel>::Ty TypeUnsigned; |
150 for (size_t i = 0; i < NumElementsInType; ++i) { | 144 typedef typename Vectors<TypeSignedLabel>::Ty TypeSigned; |
151 if (i > 0) | 145 typedef typename Vectors<TypeUnsignedLabel>::ElementTy ElementTypeUnsigned; |
152 std::cout << ", "; | 146 typedef typename Vectors<TypeSignedLabel>::ElementTy ElementTypeSigned; |
153 std::cout << (CastType) Vect[i]; | |
154 } | |
155 } | |
156 | 147 |
157 template <typename TypeUnsigned, typename TypeSigned, | |
158 typename ElementTypeUnsigned, typename ElementTypeSigned> | |
159 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { | |
160 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); | 148 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); |
161 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); | 149 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); |
162 volatile unsigned Values[] = INT_VALUE_ARRAY; | 150 volatile unsigned Values[] = INT_VALUE_ARRAY; |
163 const static size_t NumValues = sizeof(Values) / sizeof(*Values); | 151 const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
164 static struct { | 152 static struct { |
165 const char *Name; | 153 const char *Name; |
166 FuncTypeUnsigned FuncLlc; | 154 FuncTypeUnsigned FuncLlc; |
167 FuncTypeUnsigned FuncSz; | 155 FuncTypeUnsigned FuncSz; |
168 bool ExcludeDivExceptions; // for divide related tests | 156 bool ExcludeDivExceptions; // for divide related tests |
169 } Funcs[] = { | 157 } Funcs[] = { |
170 #define X(inst, op, isdiv) \ | 158 #define X(inst, op, isdiv) \ |
171 { \ | 159 { \ |
172 STR(inst), (FuncTypeUnsigned)test##inst, \ | 160 STR(inst), (FuncTypeUnsigned)test##inst, \ |
173 (FuncTypeUnsigned)Subzero_::test##inst, isdiv \ | 161 (FuncTypeUnsigned)Subzero_::test##inst, isdiv \ |
174 } \ | 162 } \ |
175 , | 163 , |
176 UINTOP_TABLE | 164 UINTOP_TABLE |
177 #undef X | 165 #undef X |
178 #define X(inst, op, isdiv) \ | 166 #define X(inst, op, isdiv) \ |
179 { \ | 167 { \ |
180 STR(inst), (FuncTypeUnsigned)(FuncTypeSigned)test##inst, \ | 168 STR(inst), (FuncTypeUnsigned)(FuncTypeSigned)test##inst, \ |
181 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::test##inst, isdiv \ | 169 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::test##inst, isdiv \ |
182 } \ | 170 } \ |
183 , | 171 , |
184 SINTOP_TABLE | 172 SINTOP_TABLE |
185 #undef X | 173 #undef X |
186 }; | 174 }; |
187 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); | 175 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
188 const static size_t NumElementsInType = | 176 const static size_t NumElementsInType = Vectors<TypeUnsigned>::NumElements; |
189 sizeof(TypeUnsigned) / sizeof(ElementTypeUnsigned); | |
190 for (size_t f = 0; f < NumFuncs; ++f) { | 177 for (size_t f = 0; f < NumFuncs; ++f) { |
191 PRNG Index; | 178 PRNG Index; |
192 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { | 179 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
193 // Initialize the test vectors. | 180 // Initialize the test vectors. |
194 TypeUnsigned Value1, Value2; | 181 TypeUnsigned Value1, Value2; |
195 for (size_t j = 0; j < NumElementsInType;) { | 182 for (size_t j = 0; j < NumElementsInType;) { |
196 ElementTypeUnsigned Element1 = Values[Index() % NumValues]; | 183 ElementTypeUnsigned Element1 = Values[Index() % NumValues]; |
197 ElementTypeUnsigned Element2 = Values[Index() % NumValues]; | 184 ElementTypeUnsigned Element2 = Values[Index() % NumValues]; |
198 if (Funcs[f].ExcludeDivExceptions && | 185 if (Funcs[f].ExcludeDivExceptions && |
199 inputsMayTriggerException<ElementTypeSigned>(Element1, Element2)) | 186 inputsMayTriggerException<ElementTypeSigned>(Element1, Element2)) |
200 continue; | 187 continue; |
201 Value1[j] = Element1; | 188 Value1[j] = Element1; |
202 Value2[j] = Element2; | 189 Value2[j] = Element2; |
203 ++j; | 190 ++j; |
204 } | 191 } |
205 // Perform the test. | 192 // Perform the test. |
206 TypeUnsigned ResultSz = Funcs[f].FuncSz(Value1, Value2); | 193 TypeUnsigned ResultSz = Funcs[f].FuncSz(Value1, Value2); |
207 TypeUnsigned ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | 194 TypeUnsigned ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
208 ++TotalTests; | 195 ++TotalTests; |
209 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { | 196 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { |
210 ++Passes; | 197 ++Passes; |
211 } else { | 198 } else { |
| 199 ++Failures; |
212 std::cout << "test" << Funcs[f].Name << "v" << NumElementsInType << "i" | 200 std::cout << "test" << Funcs[f].Name << "v" << NumElementsInType << "i" |
213 << (CHAR_BIT * sizeof(ElementTypeUnsigned)) << "("; | 201 << (CHAR_BIT * sizeof(ElementTypeUnsigned)) << "(" |
214 outputVector<TypeUnsigned, ElementTypeUnsigned, unsigned>(Value1); | 202 << vectAsString<TypeUnsignedLabel>(Value1) << "," |
215 std::cout << ", "; | 203 << vectAsString<TypeUnsignedLabel>(Value2) |
216 outputVector<TypeUnsigned, ElementTypeUnsigned, unsigned>(Value2); | 204 << "): sz=" << vectAsString<TypeUnsignedLabel>(ResultSz) |
217 std::cout << "): sz="; | 205 << " llc=" << vectAsString<TypeUnsignedLabel>(ResultLlc) |
218 outputVector<TypeUnsigned, ElementTypeUnsigned, unsigned>(ResultSz); | 206 << std::endl; |
219 std::cout << " llc="; | |
220 outputVector<TypeUnsigned, ElementTypeUnsigned, unsigned>(ResultLlc); | |
221 std::cout << std::endl; | |
222 } | 207 } |
223 } | 208 } |
224 } | 209 } |
225 } | 210 } |
226 | 211 |
227 template <typename Type> | 212 template <typename Type> |
228 void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { | 213 void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
229 static const Type NegInf = -1.0 / 0.0; | 214 static const Type NegInf = -1.0 / 0.0; |
230 static const Type PosInf = 1.0 / 0.0; | 215 static const Type PosInf = 1.0 / 0.0; |
231 static const Type Nan = 0.0 / 0.0; | 216 static const Type Nan = 0.0 / 0.0; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 Value2[j] = Values[Index() % NumValues]; | 300 Value2[j] = Values[Index() % NumValues]; |
316 } | 301 } |
317 // Perform the test. | 302 // Perform the test. |
318 v4f32 ResultSz = Funcs[f].FuncSz(Value1, Value2); | 303 v4f32 ResultSz = Funcs[f].FuncSz(Value1, Value2); |
319 v4f32 ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | 304 v4f32 ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
320 ++TotalTests; | 305 ++TotalTests; |
321 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { | 306 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { |
322 ++Passes; | 307 ++Passes; |
323 } else { | 308 } else { |
324 ++Failures; | 309 ++Failures; |
325 std::cout << std::fixed << "test" << Funcs[f].Name << "v4f32" | 310 std::cout << "test" << Funcs[f].Name << "v4f32" |
326 << "("; | 311 << "(" << vectAsString<v4f32>(Value1) << "," |
327 outputVector<v4f32, float, float>(Value1); | 312 << vectAsString<v4f32>(Value2) |
328 std::cout << ", "; | 313 << "): sz=" << vectAsString<v4f32>(ResultSz) << " llc" |
329 outputVector<v4f32, float, float>(Value2); | 314 << vectAsString<v4f32>(ResultLlc) << std::endl; |
330 std::cout << "): sz="; | |
331 outputVector<v4f32, float, float>(ResultSz); | |
332 std::cout << " llc="; | |
333 outputVector<v4f32, float, float>(ResultLlc); | |
334 std::cout << std::endl; | |
335 } | 315 } |
336 } | 316 } |
337 } | 317 } |
338 } | 318 } |
339 | 319 |
340 int main(int argc, char **argv) { | 320 int main(int argc, char **argv) { |
341 size_t TotalTests = 0; | 321 size_t TotalTests = 0; |
342 size_t Passes = 0; | 322 size_t Passes = 0; |
343 size_t Failures = 0; | 323 size_t Failures = 0; |
344 | 324 |
345 testsInt<uint8_t, int8_t>(TotalTests, Passes, Failures); | 325 testsInt<uint8_t, int8_t>(TotalTests, Passes, Failures); |
346 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); | 326 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); |
347 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); | 327 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); |
348 testsInt<uint64_t, int64_t>(TotalTests, Passes, Failures); | 328 testsInt<uint64_t, int64_t>(TotalTests, Passes, Failures); |
349 testsVecInt<v4ui32, v4si32, uint32_t, int32_t>(TotalTests, Passes, Failures); | 329 testsVecInt<v4ui32, v4si32>(TotalTests, Passes, Failures); |
350 testsVecInt<v8ui16, v8si16, uint16_t, int16_t>(TotalTests, Passes, Failures); | 330 testsVecInt<v8ui16, v8si16>(TotalTests, Passes, Failures); |
351 testsVecInt<v16ui8, v16si8, uint8_t, int8_t>(TotalTests, Passes, Failures); | 331 testsVecInt<v16ui8, v16si8>(TotalTests, Passes, Failures); |
352 testsFp<float>(TotalTests, Passes, Failures); | 332 testsFp<float>(TotalTests, Passes, Failures); |
353 testsFp<double>(TotalTests, Passes, Failures); | 333 testsFp<double>(TotalTests, Passes, Failures); |
354 testsVecFp(TotalTests, Passes, Failures); | 334 testsVecFp(TotalTests, Passes, Failures); |
355 | 335 |
356 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes | 336 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
357 << " Failures=" << Failures << "\n"; | 337 << " Failures=" << Failures << "\n"; |
358 return Failures; | 338 return Failures; |
359 } | 339 } |
360 | 340 |
361 extern "C" { | 341 extern "C" { |
(...skipping 23 matching lines...) Expand all Loading... |
385 v16si8 Sz_srem_v16i8(v16si8 a, v16si8 b) { return a % b; } | 365 v16si8 Sz_srem_v16i8(v16si8 a, v16si8 b) { return a % b; } |
386 v16ui8 Sz_urem_v16i8(v16ui8 a, v16ui8 b) { return a % b; } | 366 v16ui8 Sz_urem_v16i8(v16ui8 a, v16ui8 b) { return a % b; } |
387 | 367 |
388 v4f32 Sz_frem_v4f32(v4f32 a, v4f32 b) { | 368 v4f32 Sz_frem_v4f32(v4f32 a, v4f32 b) { |
389 v4f32 Result; | 369 v4f32 Result; |
390 for (int i = 0; i < 4; ++i) | 370 for (int i = 0; i < 4; ++i) |
391 Result[i] = fmodf(a[i], b[i]); | 371 Result[i] = fmodf(a[i], b[i]); |
392 return Result; | 372 return Result; |
393 } | 373 } |
394 } | 374 } |
OLD | NEW |