| OLD | NEW |
| 1 /* crosstest.py --test=test_arith.cpp --test=test_arith_frem.ll \ | 1 /* crosstest.py --test=test_arith.cpp --test=test_arith_frem.ll \ |
| 2 --test=test_arith_sqrt.ll --driver=test_arith_main.cpp \ | 2 --test=test_arith_sqrt.ll --driver=test_arith_main.cpp \ |
| 3 --prefix=Subzero_ --output=test_arith */ | 3 --prefix=Subzero_ --output=test_arith */ |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <climits> // CHAR_BIT | 7 #include <climits> // CHAR_BIT |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <cfloat> | 9 #include <cfloat> |
| 10 #include <cmath> // fmodf | 10 #include <cmath> // fmodf |
| 11 #include <cstring> // memcmp | 11 #include <cstring> // memcmp |
| 12 #include <iostream> | 12 #include <iostream> |
| 13 | 13 |
| 14 // Include test_arith.h twice - once normally, and once within the | 14 // Include test_arith.h twice - once normally, and once within the |
| 15 // Subzero_ namespace, corresponding to the llc and Subzero translated | 15 // Subzero_ namespace, corresponding to the llc and Subzero translated |
| 16 // object files, respectively. | 16 // object files, respectively. |
| 17 #include "test_arith.h" | 17 #include "test_arith.h" |
| 18 namespace Subzero_ { | 18 namespace Subzero_ { |
| 19 #include "test_arith.h" | 19 #include "test_arith.h" |
| 20 } | 20 } |
| 21 | 21 |
| 22 volatile unsigned Values[] = INT_VALUE_ARRAY; | |
| 23 const static size_t NumValues = sizeof(Values) / sizeof(*Values); | |
| 24 | |
| 25 template <class T> bool inputsMayTriggerException(T Value1, T Value2) { | 22 template <class T> bool inputsMayTriggerException(T Value1, T Value2) { |
| 26 // Avoid HW divide-by-zero exception. | 23 // Avoid HW divide-by-zero exception. |
| 27 if (Value2 == 0) | 24 if (Value2 == 0) |
| 28 return true; | 25 return true; |
| 29 // Avoid HW overflow exception (on x86-32). TODO: adjust | 26 // Avoid HW overflow exception (on x86-32). TODO: adjust |
| 30 // for other architecture. | 27 // for other architecture. |
| 31 if (Value1 == std::numeric_limits<T>::min() && Value2 == -1) | 28 if (Value1 == std::numeric_limits<T>::min() && Value2 == -1) |
| 32 return true; | 29 return true; |
| 33 return false; | 30 return false; |
| 34 } | 31 } |
| 35 | 32 |
| 36 template <typename TypeUnsigned, typename TypeSigned> | 33 template <typename TypeUnsigned, typename TypeSigned> |
| 37 void testsInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { | 34 void testsInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 38 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); | 35 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); |
| 39 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); | 36 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); |
| 37 volatile unsigned Values[] = INT_VALUE_ARRAY; |
| 38 const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
| 40 static struct { | 39 static struct { |
| 41 const char *Name; | 40 const char *Name; |
| 42 FuncTypeUnsigned FuncLlc; | 41 FuncTypeUnsigned FuncLlc; |
| 43 FuncTypeUnsigned FuncSz; | 42 FuncTypeUnsigned FuncSz; |
| 44 bool ExcludeDivExceptions; // for divide related tests | 43 bool ExcludeDivExceptions; // for divide related tests |
| 45 } Funcs[] = { | 44 } Funcs[] = { |
| 46 #define X(inst, op, isdiv) \ | 45 #define X(inst, op, isdiv) \ |
| 47 { \ | 46 { \ |
| 48 STR(inst), (FuncTypeUnsigned)test##inst, \ | 47 STR(inst), (FuncTypeUnsigned)test##inst, \ |
| 49 (FuncTypeUnsigned)Subzero_::test##inst, isdiv \ | 48 (FuncTypeUnsigned)Subzero_::test##inst, isdiv \ |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 std::cout << ", "; | 152 std::cout << ", "; |
| 154 std::cout << (CastType) Vect[i]; | 153 std::cout << (CastType) Vect[i]; |
| 155 } | 154 } |
| 156 } | 155 } |
| 157 | 156 |
| 158 template <typename TypeUnsigned, typename TypeSigned, | 157 template <typename TypeUnsigned, typename TypeSigned, |
| 159 typename ElementTypeUnsigned, typename ElementTypeSigned> | 158 typename ElementTypeUnsigned, typename ElementTypeSigned> |
| 160 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { | 159 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 161 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); | 160 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); |
| 162 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); | 161 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); |
| 162 volatile unsigned Values[] = INT_VALUE_ARRAY; |
| 163 const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
| 163 static struct { | 164 static struct { |
| 164 const char *Name; | 165 const char *Name; |
| 165 FuncTypeUnsigned FuncLlc; | 166 FuncTypeUnsigned FuncLlc; |
| 166 FuncTypeUnsigned FuncSz; | 167 FuncTypeUnsigned FuncSz; |
| 167 bool ExcludeDivExceptions; // for divide related tests | 168 bool ExcludeDivExceptions; // for divide related tests |
| 168 } Funcs[] = { | 169 } Funcs[] = { |
| 169 #define X(inst, op, isdiv) \ | 170 #define X(inst, op, isdiv) \ |
| 170 { \ | 171 { \ |
| 171 STR(inst), (FuncTypeUnsigned)test##inst, \ | 172 STR(inst), (FuncTypeUnsigned)test##inst, \ |
| 172 (FuncTypeUnsigned)Subzero_::test##inst, isdiv \ | 173 (FuncTypeUnsigned)Subzero_::test##inst, isdiv \ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 185 }; | 186 }; |
| 186 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); | 187 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 187 const static size_t NumElementsInType = | 188 const static size_t NumElementsInType = |
| 188 sizeof(TypeUnsigned) / sizeof(ElementTypeUnsigned); | 189 sizeof(TypeUnsigned) / sizeof(ElementTypeUnsigned); |
| 189 for (size_t f = 0; f < NumFuncs; ++f) { | 190 for (size_t f = 0; f < NumFuncs; ++f) { |
| 190 PRNG Index; | 191 PRNG Index; |
| 191 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { | 192 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
| 192 // Initialize the test vectors. | 193 // Initialize the test vectors. |
| 193 TypeUnsigned Value1, Value2; | 194 TypeUnsigned Value1, Value2; |
| 194 for (size_t j = 0; j < NumElementsInType;) { | 195 for (size_t j = 0; j < NumElementsInType;) { |
| 195 ElementTypeUnsigned Element1 = Values[Index() % NumElementsInType]; | 196 ElementTypeUnsigned Element1 = Values[Index() % NumValues]; |
| 196 ElementTypeUnsigned Element2 = Values[Index() % NumElementsInType]; | 197 ElementTypeUnsigned Element2 = Values[Index() % NumValues]; |
| 197 if (Funcs[f].ExcludeDivExceptions && | 198 if (Funcs[f].ExcludeDivExceptions && |
| 198 inputsMayTriggerException<ElementTypeSigned>(Element1, Element2)) | 199 inputsMayTriggerException<ElementTypeSigned>(Element1, Element2)) |
| 199 continue; | 200 continue; |
| 200 Value1[j] = Element1; | 201 Value1[j] = Element1; |
| 201 Value2[j] = Element2; | 202 Value2[j] = Element2; |
| 202 ++j; | 203 ++j; |
| 203 } | 204 } |
| 204 // Perform the test. | 205 // Perform the test. |
| 205 TypeUnsigned ResultSz = Funcs[f].FuncSz(Value1, Value2); | 206 TypeUnsigned ResultSz = Funcs[f].FuncSz(Value1, Value2); |
| 206 TypeUnsigned ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | 207 TypeUnsigned ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 #undef X | 304 #undef X |
| 304 }; | 305 }; |
| 305 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); | 306 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 306 const static size_t NumElementsInType = 4; | 307 const static size_t NumElementsInType = 4; |
| 307 for (size_t f = 0; f < NumFuncs; ++f) { | 308 for (size_t f = 0; f < NumFuncs; ++f) { |
| 308 PRNG Index; | 309 PRNG Index; |
| 309 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { | 310 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
| 310 // Initialize the test vectors. | 311 // Initialize the test vectors. |
| 311 v4f32 Value1, Value2; | 312 v4f32 Value1, Value2; |
| 312 for (size_t j = 0; j < NumElementsInType; ++j) { | 313 for (size_t j = 0; j < NumElementsInType; ++j) { |
| 313 Value1[j] = Values[Index() % NumElementsInType]; | 314 Value1[j] = Values[Index() % NumValues]; |
| 314 Value2[j] = Values[Index() % NumElementsInType]; | 315 Value2[j] = Values[Index() % NumValues]; |
| 315 } | 316 } |
| 316 // Perform the test. | 317 // Perform the test. |
| 317 v4f32 ResultSz = Funcs[f].FuncSz(Value1, Value2); | 318 v4f32 ResultSz = Funcs[f].FuncSz(Value1, Value2); |
| 318 v4f32 ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | 319 v4f32 ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
| 319 ++TotalTests; | 320 ++TotalTests; |
| 320 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { | 321 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { |
| 321 ++Passes; | 322 ++Passes; |
| 322 } else { | 323 } else { |
| 323 ++Failures; | 324 ++Failures; |
| 324 std::cout << std::fixed << "test" << Funcs[f].Name << "v4f32" | 325 std::cout << std::fixed << "test" << Funcs[f].Name << "v4f32" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 v16si8 Sz_srem_v16i8(v16si8 a, v16si8 b) { return a % b; } | 385 v16si8 Sz_srem_v16i8(v16si8 a, v16si8 b) { return a % b; } |
| 385 v16ui8 Sz_urem_v16i8(v16ui8 a, v16ui8 b) { return a % b; } | 386 v16ui8 Sz_urem_v16i8(v16ui8 a, v16ui8 b) { return a % b; } |
| 386 | 387 |
| 387 v4f32 Sz_frem_v4f32(v4f32 a, v4f32 b) { | 388 v4f32 Sz_frem_v4f32(v4f32 a, v4f32 b) { |
| 388 v4f32 Result; | 389 v4f32 Result; |
| 389 for (int i = 0; i < 4; ++i) | 390 for (int i = 0; i < 4; ++i) |
| 390 Result[i] = fmodf(a[i], b[i]); | 391 Result[i] = fmodf(a[i], b[i]); |
| 391 return Result; | 392 return Result; |
| 392 } | 393 } |
| 393 } | 394 } |
| OLD | NEW |