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