Chromium Code Reviews| 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; | 22 volatile unsigned Values[] = INT_VALUE_ARRAY; |
|
Jim Stichnoth
2014/07/18 22:50:35
Could you push Values[] and NumValues down into te
| |
| 23 const static size_t NumValues = sizeof(Values) / sizeof(*Values); | 23 const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
| 24 | 24 |
| 25 template <class T> bool inputsMayTriggerException(T Value1, T Value2) { | 25 template <class T> bool inputsMayTriggerException(T Value1, T Value2) { |
| 26 // Avoid HW divide-by-zero exception. | 26 // Avoid HW divide-by-zero exception. |
| 27 if (Value2 == 0) | 27 if (Value2 == 0) |
| 28 return true; | 28 return true; |
| 29 // Avoid HW overflow exception (on x86-32). TODO: adjust | 29 // Avoid HW overflow exception (on x86-32). TODO: adjust |
| 30 // for other architecture. | 30 // for other architecture. |
| 31 if (Value1 == std::numeric_limits<T>::min() && Value2 == -1) | 31 if (Value1 == std::numeric_limits<T>::min() && Value2 == -1) |
| 32 return true; | 32 return true; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 }; | 185 }; |
| 186 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); | 186 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 187 const static size_t NumElementsInType = | 187 const static size_t NumElementsInType = |
| 188 sizeof(TypeUnsigned) / sizeof(ElementTypeUnsigned); | 188 sizeof(TypeUnsigned) / sizeof(ElementTypeUnsigned); |
| 189 for (size_t f = 0; f < NumFuncs; ++f) { | 189 for (size_t f = 0; f < NumFuncs; ++f) { |
| 190 PRNG Index; | 190 PRNG Index; |
| 191 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { | 191 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
| 192 // Initialize the test vectors. | 192 // Initialize the test vectors. |
| 193 TypeUnsigned Value1, Value2; | 193 TypeUnsigned Value1, Value2; |
| 194 for (size_t j = 0; j < NumElementsInType;) { | 194 for (size_t j = 0; j < NumElementsInType;) { |
| 195 ElementTypeUnsigned Element1 = Values[Index() % NumElementsInType]; | 195 ElementTypeUnsigned Element1 = Values[Index() % NumValues]; |
| 196 ElementTypeUnsigned Element2 = Values[Index() % NumElementsInType]; | 196 ElementTypeUnsigned Element2 = Values[Index() % NumValues]; |
| 197 if (Funcs[f].ExcludeDivExceptions && | 197 if (Funcs[f].ExcludeDivExceptions && |
| 198 inputsMayTriggerException<ElementTypeSigned>(Element1, Element2)) | 198 inputsMayTriggerException<ElementTypeSigned>(Element1, Element2)) |
| 199 continue; | 199 continue; |
| 200 Value1[j] = Element1; | 200 Value1[j] = Element1; |
| 201 Value2[j] = Element2; | 201 Value2[j] = Element2; |
| 202 ++j; | 202 ++j; |
| 203 } | 203 } |
| 204 // Perform the test. | 204 // Perform the test. |
| 205 TypeUnsigned ResultSz = Funcs[f].FuncSz(Value1, Value2); | 205 TypeUnsigned ResultSz = Funcs[f].FuncSz(Value1, Value2); |
| 206 TypeUnsigned ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | 206 TypeUnsigned ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 #undef X | 303 #undef X |
| 304 }; | 304 }; |
| 305 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); | 305 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 306 const static size_t NumElementsInType = 4; | 306 const static size_t NumElementsInType = 4; |
| 307 for (size_t f = 0; f < NumFuncs; ++f) { | 307 for (size_t f = 0; f < NumFuncs; ++f) { |
| 308 PRNG Index; | 308 PRNG Index; |
| 309 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { | 309 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
| 310 // Initialize the test vectors. | 310 // Initialize the test vectors. |
| 311 v4f32 Value1, Value2; | 311 v4f32 Value1, Value2; |
| 312 for (size_t j = 0; j < NumElementsInType; ++j) { | 312 for (size_t j = 0; j < NumElementsInType; ++j) { |
| 313 Value1[j] = Values[Index() % NumElementsInType]; | 313 Value1[j] = Values[Index() % NumValues]; |
| 314 Value2[j] = Values[Index() % NumElementsInType]; | 314 Value2[j] = Values[Index() % NumValues]; |
| 315 } | 315 } |
| 316 // Perform the test. | 316 // Perform the test. |
| 317 v4f32 ResultSz = Funcs[f].FuncSz(Value1, Value2); | 317 v4f32 ResultSz = Funcs[f].FuncSz(Value1, Value2); |
| 318 v4f32 ResultLlc = Funcs[f].FuncLlc(Value1, Value2); | 318 v4f32 ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
| 319 ++TotalTests; | 319 ++TotalTests; |
| 320 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { | 320 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { |
| 321 ++Passes; | 321 ++Passes; |
| 322 } else { | 322 } else { |
| 323 ++Failures; | 323 ++Failures; |
| 324 std::cout << std::fixed << "test" << Funcs[f].Name << "v4f32" | 324 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; } | 384 v16si8 Sz_srem_v16i8(v16si8 a, v16si8 b) { return a % b; } |
| 385 v16ui8 Sz_urem_v16i8(v16ui8 a, v16ui8 b) { return a % b; } | 385 v16ui8 Sz_urem_v16i8(v16ui8 a, v16ui8 b) { return a % b; } |
| 386 | 386 |
| 387 v4f32 Sz_frem_v4f32(v4f32 a, v4f32 b) { | 387 v4f32 Sz_frem_v4f32(v4f32 a, v4f32 b) { |
| 388 v4f32 Result; | 388 v4f32 Result; |
| 389 for (int i = 0; i < 4; ++i) | 389 for (int i = 0; i < 4; ++i) |
| 390 Result[i] = fmodf(a[i], b[i]); | 390 Result[i] = fmodf(a[i], b[i]); |
| 391 return Result; | 391 return Result; |
| 392 } | 392 } |
| 393 } | 393 } |
| OLD | NEW |