OLD | NEW |
---|---|
1 //===- subzero/crosstest/test_arith_main.cpp - Driver for tests -----------===// | 1 //===- subzero/crosstest/test_arith_main.cpp - Driver for tests -----------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // Driver for crosstesting arithmetic operations | 10 // Driver for crosstesting arithmetic operations |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include <limits> | 21 #include <limits> |
22 #include <cfloat> | 22 #include <cfloat> |
23 #include <cmath> // fmodf | 23 #include <cmath> // fmodf |
24 #include <cstring> // memcmp | 24 #include <cstring> // memcmp |
25 #include <iostream> | 25 #include <iostream> |
26 | 26 |
27 // Include test_arith.h twice - once normally, and once within the | 27 // Include test_arith.h twice - once normally, and once within the |
28 // Subzero_ namespace, corresponding to the llc and Subzero translated | 28 // Subzero_ namespace, corresponding to the llc and Subzero translated |
29 // object files, respectively. | 29 // object files, respectively. |
30 #include "test_arith.h" | 30 #include "test_arith.h" |
31 #include "xdefs.h" | |
32 | 31 |
33 namespace Subzero_ { | 32 namespace Subzero_ { |
34 #include "test_arith.h" | 33 #include "test_arith.h" |
35 } | 34 } |
36 | 35 |
36 #include "insertelement.h" | |
37 #include "xdefs.h" | |
38 | |
37 template <class T> bool inputsMayTriggerException(T Value1, T Value2) { | 39 template <class T> bool inputsMayTriggerException(T Value1, T Value2) { |
38 // Avoid HW divide-by-zero exception. | 40 // Avoid HW divide-by-zero exception. |
39 if (Value2 == 0) | 41 if (Value2 == 0) |
40 return true; | 42 return true; |
41 // Avoid HW overflow exception (on x86-32). TODO: adjust | 43 // Avoid HW overflow exception (on x86-32). TODO: adjust |
42 // for other architecture. | 44 // for other architecture. |
43 if (Value1 == std::numeric_limits<T>::min() && Value2 == -1) | 45 if (Value1 == std::numeric_limits<T>::min() && Value2 == -1) |
44 return true; | 46 return true; |
45 return false; | 47 return false; |
46 } | 48 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 } | 157 } |
156 } | 158 } |
157 } | 159 } |
158 } | 160 } |
159 } | 161 } |
160 | 162 |
161 const static size_t MaxTestsPerFunc = 100000; | 163 const static size_t MaxTestsPerFunc = 100000; |
162 | 164 |
163 template <typename TypeUnsignedLabel, typename TypeSignedLabel> | 165 template <typename TypeUnsignedLabel, typename TypeSignedLabel> |
164 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { | 166 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
165 #if !defined(ARM32) && !defined(NONSFI) | 167 #if !defined(ARM32) |
166 // TODO(jpp): remove this once vector support is implemented. | 168 // TODO(jpp): remove this once vector support is implemented. |
167 typedef typename Vectors<TypeUnsignedLabel>::Ty TypeUnsigned; | 169 typedef typename Vectors<TypeUnsignedLabel>::Ty TypeUnsigned; |
168 typedef typename Vectors<TypeSignedLabel>::Ty TypeSigned; | 170 typedef typename Vectors<TypeSignedLabel>::Ty TypeSigned; |
169 typedef typename Vectors<TypeUnsignedLabel>::ElementTy ElementTypeUnsigned; | 171 typedef typename Vectors<TypeUnsignedLabel>::ElementTy ElementTypeUnsigned; |
170 typedef typename Vectors<TypeSignedLabel>::ElementTy ElementTypeSigned; | 172 typedef typename Vectors<TypeSignedLabel>::ElementTy ElementTypeSigned; |
171 | 173 |
172 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); | 174 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); |
173 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); | 175 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); |
174 volatile unsigned Values[] = INT_VALUE_ARRAY; | 176 volatile unsigned Values[] = INT_VALUE_ARRAY; |
175 const static size_t NumValues = sizeof(Values) / sizeof(*Values); | 177 const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
(...skipping 29 matching lines...) Expand all Loading... | |
205 // Initialize the test vectors. | 207 // Initialize the test vectors. |
206 TypeUnsigned Value1, Value2; | 208 TypeUnsigned Value1, Value2; |
207 for (size_t j = 0; j < NumElementsInType; ++j) { | 209 for (size_t j = 0; j < NumElementsInType; ++j) { |
208 ElementTypeUnsigned Element1 = Values[Index() % NumValues]; | 210 ElementTypeUnsigned Element1 = Values[Index() % NumValues]; |
209 ElementTypeUnsigned Element2 = Values[Index() % NumValues]; | 211 ElementTypeUnsigned Element2 = Values[Index() % NumValues]; |
210 if (Funcs[f].ExcludeDivExceptions && | 212 if (Funcs[f].ExcludeDivExceptions && |
211 inputsMayTriggerException<ElementTypeSigned>(Element1, Element2)) | 213 inputsMayTriggerException<ElementTypeSigned>(Element1, Element2)) |
212 continue; | 214 continue; |
213 if (Funcs[f].MaskShiftOperations) | 215 if (Funcs[f].MaskShiftOperations) |
214 Element2 &= CHAR_BIT * sizeof(ElementTypeUnsigned) - 1; | 216 Element2 &= CHAR_BIT * sizeof(ElementTypeUnsigned) - 1; |
215 Value1[j] = Element1; | 217 setElement<TypeUnsigned, ElementTypeUnsigned>(Value1, j, Element1); |
John
2016/01/06 15:24:26
Do you need the template parameters? I would guess
Jim Stichnoth
2016/01/06 17:34:30
Done.
| |
216 Value2[j] = Element2; | 218 setElement<TypeUnsigned, ElementTypeUnsigned>(Value2, j, Element2); |
217 } | 219 } |
218 // Perform the test. | 220 // Perform the test. |
219 TypeUnsigned ResultSz, ResultLlc; | 221 TypeUnsigned ResultSz, ResultLlc; |
220 ++TotalTests; | 222 ++TotalTests; |
221 if (Funcs[f].FuncSzUnsigned) { | 223 if (Funcs[f].FuncSzUnsigned) { |
222 ResultSz = Funcs[f].FuncSzUnsigned(Value1, Value2); | 224 ResultSz = Funcs[f].FuncSzUnsigned(Value1, Value2); |
223 ResultLlc = Funcs[f].FuncLlcUnsigned(Value1, Value2); | 225 ResultLlc = Funcs[f].FuncLlcUnsigned(Value1, Value2); |
224 } else { | 226 } else { |
225 ResultSz = Funcs[f].FuncSzSigned(Value1, Value2); | 227 ResultSz = Funcs[f].FuncSzSigned(Value1, Value2); |
226 ResultLlc = Funcs[f].FuncLlcSigned(Value1, Value2); | 228 ResultLlc = Funcs[f].FuncLlcSigned(Value1, Value2); |
227 } | 229 } |
228 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { | 230 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { |
229 ++Passes; | 231 ++Passes; |
230 } else { | 232 } else { |
231 ++Failures; | 233 ++Failures; |
232 std::cout << "test" << Funcs[f].Name << "v" << NumElementsInType << "i" | 234 std::cout << "test" << Funcs[f].Name << "v" << NumElementsInType << "i" |
233 << (CHAR_BIT * sizeof(ElementTypeUnsigned)) << "(" | 235 << (CHAR_BIT * sizeof(ElementTypeUnsigned)) << "(" |
234 << vectAsString<TypeUnsignedLabel>(Value1) << "," | 236 << vectAsString<TypeUnsignedLabel>(Value1) << "," |
235 << vectAsString<TypeUnsignedLabel>(Value2) | 237 << vectAsString<TypeUnsignedLabel>(Value2) |
236 << "): sz=" << vectAsString<TypeUnsignedLabel>(ResultSz) | 238 << "): sz=" << vectAsString<TypeUnsignedLabel>(ResultSz) |
237 << " llc=" << vectAsString<TypeUnsignedLabel>(ResultLlc) | 239 << " llc=" << vectAsString<TypeUnsignedLabel>(ResultLlc) |
238 << "\n"; | 240 << "\n"; |
239 } | 241 } |
240 } | 242 } |
241 } | 243 } |
242 #endif // !ARM32 && !NONSFI | 244 #endif // !ARM32 |
243 } | 245 } |
244 | 246 |
245 template <typename Type> | 247 template <typename Type> |
246 void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { | 248 void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
247 static const Type NegInf = -1.0 / 0.0; | 249 static const Type NegInf = -1.0 / 0.0; |
248 static const Type PosInf = 1.0 / 0.0; | 250 static const Type PosInf = 1.0 / 0.0; |
249 static const Type Nan = 0.0 / 0.0; | 251 static const Type Nan = 0.0 / 0.0; |
250 static const Type NegNan = -0.0 / 0.0; | 252 static const Type NegNan = -0.0 / 0.0; |
251 volatile Type Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); | 253 volatile Type Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); |
252 const static size_t NumValues = sizeof(Values) / sizeof(*Values); | 254 const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 } else { | 310 } else { |
309 ++Failures; | 311 ++Failures; |
310 std::cout << std::fixed << "test_fabs" << (CHAR_BIT * sizeof(Type)) << "(" | 312 std::cout << std::fixed << "test_fabs" << (CHAR_BIT * sizeof(Type)) << "(" |
311 << Value << "): sz=" << ResultSz << " llc=" << ResultLlc | 313 << Value << "): sz=" << ResultSz << " llc=" << ResultLlc |
312 << "\n"; | 314 << "\n"; |
313 } | 315 } |
314 } | 316 } |
315 } | 317 } |
316 | 318 |
317 void testsVecFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { | 319 void testsVecFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
318 #if !defined(ARM32) && !defined(NONSFI) | 320 #if !defined(ARM32) |
319 // TODO(jpp): remove this once vector support is implemented. | 321 // TODO(jpp): remove this once vector support is implemented. |
320 static const float NegInf = -1.0 / 0.0; | 322 static const float NegInf = -1.0 / 0.0; |
321 static const float PosInf = 1.0 / 0.0; | 323 static const float PosInf = 1.0 / 0.0; |
322 static const float Nan = 0.0 / 0.0; | 324 static const float Nan = 0.0 / 0.0; |
323 static const float NegNan = -0.0 / 0.0; | 325 static const float NegNan = -0.0 / 0.0; |
324 volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); | 326 volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); |
325 const static size_t NumValues = sizeof(Values) / sizeof(*Values); | 327 const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
326 typedef v4f32 (*FuncType)(v4f32, v4f32); | 328 typedef v4f32 (*FuncType)(v4f32, v4f32); |
327 static struct { | 329 static struct { |
328 const char *Name; | 330 const char *Name; |
329 FuncType FuncLlc; | 331 FuncType FuncLlc; |
330 FuncType FuncSz; | 332 FuncType FuncSz; |
331 } Funcs[] = { | 333 } Funcs[] = { |
332 #define X(inst, op, func) \ | 334 #define X(inst, op, func) \ |
333 { STR(inst), (FuncType)test##inst, (FuncType)Subzero_::test##inst } \ | 335 { STR(inst), (FuncType)test##inst, (FuncType)Subzero_::test##inst } \ |
334 , | 336 , |
335 FPOP_TABLE | 337 FPOP_TABLE |
336 #undef X | 338 #undef X |
337 }; | 339 }; |
338 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); | 340 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
339 const static size_t NumElementsInType = 4; | 341 const static size_t NumElementsInType = 4; |
340 for (size_t f = 0; f < NumFuncs; ++f) { | 342 for (size_t f = 0; f < NumFuncs; ++f) { |
341 PRNG Index; | 343 PRNG Index; |
342 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { | 344 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
343 // Initialize the test vectors. | 345 // Initialize the test vectors. |
344 v4f32 Value1, Value2; | 346 v4f32 Value1, Value2; |
345 for (size_t j = 0; j < NumElementsInType; ++j) { | 347 for (size_t j = 0; j < NumElementsInType; ++j) { |
346 Value1[j] = Values[Index() % NumValues]; | 348 setElement<v4f32, float>(Value1, j, Values[Index() % NumValues]); |
347 Value2[j] = Values[Index() % NumValues]; | 349 setElement<v4f32, float>(Value2, j, Values[Index() % NumValues]); |
348 } | 350 } |
349 // Perform the test. | 351 // Perform the test. |
350 v4f32 ResultSz = Funcs[f].FuncSz(Value1, Value2); | 352 v4f32 ResultSz = Funcs[f].FuncSz(Value1, Value2); |
351 v4f32 ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | 353 v4f32 ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
352 ++TotalTests; | 354 ++TotalTests; |
353 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { | 355 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { |
354 ++Passes; | 356 ++Passes; |
355 } else { | 357 } else { |
356 ++Failures; | 358 ++Failures; |
357 std::cout << "test" << Funcs[f].Name << "v4f32" | 359 std::cout << "test" << Funcs[f].Name << "v4f32" |
(...skipping 10 matching lines...) Expand all Loading... | |
368 ++Passes; | 370 ++Passes; |
369 } else { | 371 } else { |
370 ++Failures; | 372 ++Failures; |
371 std::cout << "test_fabs_v4f32" | 373 std::cout << "test_fabs_v4f32" |
372 << "(" << vectAsString<v4f32>(Value1) | 374 << "(" << vectAsString<v4f32>(Value1) |
373 << "): sz=" << vectAsString<v4f32>(ResultSz) << " llc" | 375 << "): sz=" << vectAsString<v4f32>(ResultSz) << " llc" |
374 << vectAsString<v4f32>(ResultLlc) << "\n"; | 376 << vectAsString<v4f32>(ResultLlc) << "\n"; |
375 } | 377 } |
376 } | 378 } |
377 } | 379 } |
378 #endif // !ARM32 && !NONSFI | 380 #endif // !ARM32 |
379 } | 381 } |
380 | 382 |
381 #ifdef X8664_STACK_HACK | 383 #ifdef X8664_STACK_HACK |
382 extern "C" int wrapped_main(int argc, char *argv[]) { | 384 extern "C" int wrapped_main(int argc, char *argv[]) { |
383 #else // !defined(X8664_STACK_HACK) | 385 #else // !defined(X8664_STACK_HACK) |
384 int main(int argc, char *argv[]) { | 386 int main(int argc, char *argv[]) { |
385 #endif // X8664_STACK_HACK | 387 #endif // X8664_STACK_HACK |
386 size_t TotalTests = 0; | 388 size_t TotalTests = 0; |
387 size_t Passes = 0; | 389 size_t Passes = 0; |
388 size_t Failures = 0; | 390 size_t Failures = 0; |
389 | 391 |
390 testsInt<bool, bool>(TotalTests, Passes, Failures); | 392 testsInt<bool, bool>(TotalTests, Passes, Failures); |
391 testsInt<uint8_t, myint8_t>(TotalTests, Passes, Failures); | 393 testsInt<uint8_t, myint8_t>(TotalTests, Passes, Failures); |
392 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); | 394 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); |
393 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); | 395 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); |
394 testsInt<uint64, int64>(TotalTests, Passes, Failures); | 396 testsInt<uint64, int64>(TotalTests, Passes, Failures); |
395 testsVecInt<v4ui32, v4si32>(TotalTests, Passes, Failures); | 397 testsVecInt<v4ui32, v4si32>(TotalTests, Passes, Failures); |
396 testsVecInt<v8ui16, v8si16>(TotalTests, Passes, Failures); | 398 testsVecInt<v8ui16, v8si16>(TotalTests, Passes, Failures); |
397 testsVecInt<v16ui8, v16si8>(TotalTests, Passes, Failures); | 399 testsVecInt<v16ui8, v16si8>(TotalTests, Passes, Failures); |
398 testsFp<float>(TotalTests, Passes, Failures); | 400 testsFp<float>(TotalTests, Passes, Failures); |
399 testsFp<double>(TotalTests, Passes, Failures); | 401 testsFp<double>(TotalTests, Passes, Failures); |
400 testsVecFp(TotalTests, Passes, Failures); | 402 testsVecFp(TotalTests, Passes, Failures); |
401 | 403 |
402 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes | 404 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
403 << " Failures=" << Failures << "\n"; | 405 << " Failures=" << Failures << "\n"; |
404 return Failures; | 406 return Failures; |
405 } | 407 } |
OLD | NEW |