Matt Wala | 89a7c2b | 2014-07-22 10:55:30 -0700 | [diff] [blame] | 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 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 14 | /* crosstest.py --test=test_arith.cpp --test=test_arith_frem.ll \ |
Jan Voung | f37fbbe | 2014-07-09 16:13:13 -0700 | [diff] [blame] | 15 | --test=test_arith_sqrt.ll --driver=test_arith_main.cpp \ |
| 16 | --prefix=Subzero_ --output=test_arith */ |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 17 | |
| 18 | #include <stdint.h> |
| 19 | |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 20 | #include <climits> // CHAR_BIT |
| 21 | #include <limits> |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 22 | #include <cfloat> |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 23 | #include <cmath> // fmodf |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 24 | #include <cstring> // memcmp |
| 25 | #include <iostream> |
| 26 | |
| 27 | // Include test_arith.h twice - once normally, and once within the |
| 28 | // Subzero_ namespace, corresponding to the llc and Subzero translated |
| 29 | // object files, respectively. |
| 30 | #include "test_arith.h" |
John Porto | 1d23542 | 2015-08-12 12:37:53 -0700 | [diff] [blame] | 31 | #include "xdefs.h" |
| 32 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 33 | namespace Subzero_ { |
| 34 | #include "test_arith.h" |
| 35 | } |
| 36 | |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 37 | template <class T> bool inputsMayTriggerException(T Value1, T Value2) { |
| 38 | // Avoid HW divide-by-zero exception. |
| 39 | if (Value2 == 0) |
| 40 | return true; |
| 41 | // Avoid HW overflow exception (on x86-32). TODO: adjust |
| 42 | // for other architecture. |
| 43 | if (Value1 == std::numeric_limits<T>::min() && Value2 == -1) |
| 44 | return true; |
| 45 | return false; |
| 46 | } |
| 47 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 48 | template <typename TypeUnsigned, typename TypeSigned> |
| 49 | void testsInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 50 | typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); |
| 51 | typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); |
Matt Wala | 35ec373 | 2014-07-18 16:32:16 -0700 | [diff] [blame] | 52 | volatile unsigned Values[] = INT_VALUE_ARRAY; |
| 53 | const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 54 | static struct { |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 55 | // For functions that operate on unsigned values, the |
| 56 | // FuncLlcSigned and FuncSzSigned fields are NULL. For functions |
| 57 | // that operate on signed values, the FuncLlcUnsigned and |
| 58 | // FuncSzUnsigned fields are NULL. |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 59 | const char *Name; |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 60 | FuncTypeUnsigned FuncLlcUnsigned; |
| 61 | FuncTypeUnsigned FuncSzUnsigned; |
| 62 | FuncTypeSigned FuncLlcSigned; |
| 63 | FuncTypeSigned FuncSzSigned; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 64 | bool ExcludeDivExceptions; // for divide related tests |
| 65 | } Funcs[] = { |
Matt Wala | afeaee4 | 2014-08-07 13:47:30 -0700 | [diff] [blame] | 66 | #define X(inst, op, isdiv, isshift) \ |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 67 | { STR(inst), test##inst, Subzero_::test##inst, NULL, NULL, isdiv } \ |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 68 | , |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 69 | UINTOP_TABLE |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 70 | #undef X |
Matt Wala | afeaee4 | 2014-08-07 13:47:30 -0700 | [diff] [blame] | 71 | #define X(inst, op, isdiv, isshift) \ |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 72 | { STR(inst), NULL, NULL, test##inst, Subzero_::test##inst, isdiv } \ |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 73 | , |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 74 | SINTOP_TABLE |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 75 | #undef X |
John Porto | 98cc08c | 2015-11-24 12:30:01 -0800 | [diff] [blame] | 76 | #define X(mult_by) \ |
| 77 | { \ |
| 78 | "Mult-By-" STR(mult_by), testMultiplyBy##mult_by, \ |
| 79 | Subzero_::testMultiplyBy##mult_by, NULL, NULL, false \ |
| 80 | } \ |
| 81 | , {"Mult-By-Neg-" STR(mult_by), testMultiplyByNeg##mult_by, \ |
| 82 | Subzero_::testMultiplyByNeg##mult_by, NULL, NULL, false}, |
| 83 | MULIMM_TABLE}; |
| 84 | #undef X |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 85 | const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 86 | |
| 87 | if (sizeof(TypeUnsigned) <= sizeof(uint32_t)) { |
| 88 | // This is the "normal" version of the loop nest, for 32-bit or |
| 89 | // narrower types. |
| 90 | for (size_t f = 0; f < NumFuncs; ++f) { |
| 91 | for (size_t i = 0; i < NumValues; ++i) { |
| 92 | for (size_t j = 0; j < NumValues; ++j) { |
| 93 | TypeUnsigned Value1 = Values[i]; |
| 94 | TypeUnsigned Value2 = Values[j]; |
| 95 | // Avoid HW divide-by-zero exception. |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 96 | if (Funcs[f].ExcludeDivExceptions && |
| 97 | inputsMayTriggerException<TypeSigned>(Value1, Value2)) |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 98 | continue; |
| 99 | ++TotalTests; |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 100 | TypeUnsigned ResultSz, ResultLlc; |
| 101 | if (Funcs[f].FuncSzUnsigned) { |
| 102 | ResultSz = Funcs[f].FuncSzUnsigned(Value1, Value2); |
| 103 | ResultLlc = Funcs[f].FuncLlcUnsigned(Value1, Value2); |
| 104 | } else { |
| 105 | ResultSz = Funcs[f].FuncSzSigned(Value1, Value2); |
| 106 | ResultLlc = Funcs[f].FuncLlcSigned(Value1, Value2); |
| 107 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 108 | if (ResultSz == ResultLlc) { |
| 109 | ++Passes; |
| 110 | } else { |
| 111 | ++Failures; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 112 | std::cout << "test" << Funcs[f].Name |
| 113 | << (CHAR_BIT * sizeof(TypeUnsigned)) << "(" << Value1 |
| 114 | << ", " << Value2 << "): sz=" << (unsigned)ResultSz |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 115 | << " llc=" << (unsigned)ResultLlc << "\n"; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } else { |
| 121 | // This is the 64-bit version. Test values are synthesized from |
| 122 | // the 32-bit values in Values[]. |
| 123 | for (size_t f = 0; f < NumFuncs; ++f) { |
| 124 | for (size_t iLo = 0; iLo < NumValues; ++iLo) { |
| 125 | for (size_t iHi = 0; iHi < NumValues; ++iHi) { |
| 126 | for (size_t jLo = 0; jLo < NumValues; ++jLo) { |
| 127 | for (size_t jHi = 0; jHi < NumValues; ++jHi) { |
| 128 | TypeUnsigned Value1 = |
| 129 | (((TypeUnsigned)Values[iHi]) << 32) + Values[iLo]; |
| 130 | TypeUnsigned Value2 = |
| 131 | (((TypeUnsigned)Values[jHi]) << 32) + Values[jLo]; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 132 | if (Funcs[f].ExcludeDivExceptions && |
| 133 | inputsMayTriggerException<TypeSigned>(Value1, Value2)) |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 134 | continue; |
| 135 | ++TotalTests; |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 136 | TypeUnsigned ResultSz, ResultLlc; |
| 137 | if (Funcs[f].FuncSzUnsigned) { |
| 138 | ResultSz = Funcs[f].FuncSzUnsigned(Value1, Value2); |
| 139 | ResultLlc = Funcs[f].FuncLlcUnsigned(Value1, Value2); |
| 140 | } else { |
| 141 | ResultSz = Funcs[f].FuncSzSigned(Value1, Value2); |
| 142 | ResultLlc = Funcs[f].FuncLlcSigned(Value1, Value2); |
| 143 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 144 | if (ResultSz == ResultLlc) { |
| 145 | ++Passes; |
| 146 | } else { |
| 147 | ++Failures; |
| 148 | std::cout << "test" << Funcs[f].Name |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 149 | << (CHAR_BIT * sizeof(TypeUnsigned)) << "(" << Value1 |
John Porto | ba6a67c | 2015-09-25 15:19:45 -0700 | [diff] [blame] | 150 | << ", " << Value2 << "): sz=" << (uint64)ResultSz |
| 151 | << " llc=" << (uint64)ResultLlc << "\n"; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 161 | const static size_t MaxTestsPerFunc = 100000; |
| 162 | |
Matt Wala | 89a7c2b | 2014-07-22 10:55:30 -0700 | [diff] [blame] | 163 | template <typename TypeUnsignedLabel, typename TypeSignedLabel> |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 164 | void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame^] | 165 | #if !defined(ARM32) && !defined(NONSFI) |
John Porto | ba6a67c | 2015-09-25 15:19:45 -0700 | [diff] [blame] | 166 | // TODO(jpp): remove this once vector support is implemented. |
Matt Wala | 89a7c2b | 2014-07-22 10:55:30 -0700 | [diff] [blame] | 167 | typedef typename Vectors<TypeUnsignedLabel>::Ty TypeUnsigned; |
| 168 | typedef typename Vectors<TypeSignedLabel>::Ty TypeSigned; |
| 169 | typedef typename Vectors<TypeUnsignedLabel>::ElementTy ElementTypeUnsigned; |
| 170 | typedef typename Vectors<TypeSignedLabel>::ElementTy ElementTypeSigned; |
| 171 | |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 172 | typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); |
| 173 | typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); |
Matt Wala | 35ec373 | 2014-07-18 16:32:16 -0700 | [diff] [blame] | 174 | volatile unsigned Values[] = INT_VALUE_ARRAY; |
| 175 | const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 176 | static struct { |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 177 | // For functions that operate on unsigned values, the |
| 178 | // FuncLlcSigned and FuncSzSigned fields are NULL. For functions |
| 179 | // that operate on signed values, the FuncLlcUnsigned and |
| 180 | // FuncSzUnsigned fields are NULL. |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 181 | const char *Name; |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 182 | FuncTypeUnsigned FuncLlcUnsigned; |
| 183 | FuncTypeUnsigned FuncSzUnsigned; |
| 184 | FuncTypeSigned FuncLlcSigned; |
| 185 | FuncTypeSigned FuncSzSigned; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 186 | bool ExcludeDivExceptions; // for divide related tests |
Matt Wala | afeaee4 | 2014-08-07 13:47:30 -0700 | [diff] [blame] | 187 | bool MaskShiftOperations; // for shift related tests |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 188 | } Funcs[] = { |
Matt Wala | afeaee4 | 2014-08-07 13:47:30 -0700 | [diff] [blame] | 189 | #define X(inst, op, isdiv, isshift) \ |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 190 | { STR(inst), test##inst, Subzero_::test##inst, NULL, NULL, isdiv, isshift } \ |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 191 | , |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 192 | UINTOP_TABLE |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 193 | #undef X |
Matt Wala | afeaee4 | 2014-08-07 13:47:30 -0700 | [diff] [blame] | 194 | #define X(inst, op, isdiv, isshift) \ |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 195 | { STR(inst), NULL, NULL, test##inst, Subzero_::test##inst, isdiv, isshift } \ |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 196 | , |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 197 | SINTOP_TABLE |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 198 | #undef X |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 199 | }; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 200 | const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
Matt Wala | 89a7c2b | 2014-07-22 10:55:30 -0700 | [diff] [blame] | 201 | const static size_t NumElementsInType = Vectors<TypeUnsigned>::NumElements; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 202 | for (size_t f = 0; f < NumFuncs; ++f) { |
| 203 | PRNG Index; |
| 204 | for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
| 205 | // Initialize the test vectors. |
| 206 | TypeUnsigned Value1, Value2; |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame^] | 207 | for (size_t j = 0; j < NumElementsInType; ++j) { |
Matt Wala | 35ec373 | 2014-07-18 16:32:16 -0700 | [diff] [blame] | 208 | ElementTypeUnsigned Element1 = Values[Index() % NumValues]; |
| 209 | ElementTypeUnsigned Element2 = Values[Index() % NumValues]; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 210 | if (Funcs[f].ExcludeDivExceptions && |
| 211 | inputsMayTriggerException<ElementTypeSigned>(Element1, Element2)) |
| 212 | continue; |
Matt Wala | afeaee4 | 2014-08-07 13:47:30 -0700 | [diff] [blame] | 213 | if (Funcs[f].MaskShiftOperations) |
| 214 | Element2 &= CHAR_BIT * sizeof(ElementTypeUnsigned) - 1; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 215 | Value1[j] = Element1; |
| 216 | Value2[j] = Element2; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 217 | } |
| 218 | // Perform the test. |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 219 | TypeUnsigned ResultSz, ResultLlc; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 220 | ++TotalTests; |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 221 | if (Funcs[f].FuncSzUnsigned) { |
| 222 | ResultSz = Funcs[f].FuncSzUnsigned(Value1, Value2); |
| 223 | ResultLlc = Funcs[f].FuncLlcUnsigned(Value1, Value2); |
| 224 | } else { |
| 225 | ResultSz = Funcs[f].FuncSzSigned(Value1, Value2); |
| 226 | ResultLlc = Funcs[f].FuncLlcSigned(Value1, Value2); |
| 227 | } |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 228 | if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { |
| 229 | ++Passes; |
| 230 | } else { |
Matt Wala | 89a7c2b | 2014-07-22 10:55:30 -0700 | [diff] [blame] | 231 | ++Failures; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 232 | std::cout << "test" << Funcs[f].Name << "v" << NumElementsInType << "i" |
Matt Wala | 89a7c2b | 2014-07-22 10:55:30 -0700 | [diff] [blame] | 233 | << (CHAR_BIT * sizeof(ElementTypeUnsigned)) << "(" |
| 234 | << vectAsString<TypeUnsignedLabel>(Value1) << "," |
| 235 | << vectAsString<TypeUnsignedLabel>(Value2) |
| 236 | << "): sz=" << vectAsString<TypeUnsignedLabel>(ResultSz) |
| 237 | << " llc=" << vectAsString<TypeUnsignedLabel>(ResultLlc) |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 238 | << "\n"; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | } |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame^] | 242 | #endif // !ARM32 && !NONSFI |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 245 | template <typename Type> |
| 246 | void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 247 | static const Type NegInf = -1.0 / 0.0; |
| 248 | static const Type PosInf = 1.0 / 0.0; |
| 249 | static const Type Nan = 0.0 / 0.0; |
Jan Voung | f37fbbe | 2014-07-09 16:13:13 -0700 | [diff] [blame] | 250 | static const Type NegNan = -0.0 / 0.0; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 251 | volatile Type Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 252 | const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
| 253 | typedef Type (*FuncType)(Type, Type); |
| 254 | static struct { |
| 255 | const char *Name; |
| 256 | FuncType FuncLlc; |
| 257 | FuncType FuncSz; |
| 258 | } Funcs[] = { |
| 259 | #define X(inst, op, func) \ |
| 260 | { STR(inst), (FuncType)test##inst, (FuncType)Subzero_::test##inst } \ |
| 261 | , |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 262 | FPOP_TABLE |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 263 | #undef X |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 264 | }; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 265 | const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 266 | |
| 267 | for (size_t f = 0; f < NumFuncs; ++f) { |
| 268 | for (size_t i = 0; i < NumValues; ++i) { |
| 269 | for (size_t j = 0; j < NumValues; ++j) { |
| 270 | Type Value1 = Values[i]; |
| 271 | Type Value2 = Values[j]; |
| 272 | ++TotalTests; |
| 273 | Type ResultSz = Funcs[f].FuncSz(Value1, Value2); |
| 274 | Type ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
| 275 | // Compare results using memcmp() in case they are both NaN. |
| 276 | if (!memcmp(&ResultSz, &ResultLlc, sizeof(Type))) { |
| 277 | ++Passes; |
| 278 | } else { |
| 279 | ++Failures; |
| 280 | std::cout << std::fixed << "test" << Funcs[f].Name |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 281 | << (CHAR_BIT * sizeof(Type)) << "(" << Value1 << ", " |
| 282 | << Value2 << "): sz=" << ResultSz << " llc=" << ResultLlc |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 283 | << "\n"; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | } |
| 287 | } |
Jan Voung | f37fbbe | 2014-07-09 16:13:13 -0700 | [diff] [blame] | 288 | for (size_t i = 0; i < NumValues; ++i) { |
| 289 | Type Value = Values[i]; |
| 290 | ++TotalTests; |
| 291 | Type ResultSz = Subzero_::mySqrt(Value); |
| 292 | Type ResultLlc = mySqrt(Value); |
| 293 | // Compare results using memcmp() in case they are both NaN. |
| 294 | if (!memcmp(&ResultSz, &ResultLlc, sizeof(Type))) { |
| 295 | ++Passes; |
| 296 | } else { |
| 297 | ++Failures; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 298 | std::cout << std::fixed << "test_sqrt" << (CHAR_BIT * sizeof(Type)) << "(" |
| 299 | << Value << "): sz=" << ResultSz << " llc=" << ResultLlc |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 300 | << "\n"; |
Jan Voung | f37fbbe | 2014-07-09 16:13:13 -0700 | [diff] [blame] | 301 | } |
Jim Stichnoth | 8c980d0 | 2015-03-19 13:01:50 -0700 | [diff] [blame] | 302 | ++TotalTests; |
| 303 | ResultSz = Subzero_::myFabs(Value); |
| 304 | ResultLlc = myFabs(Value); |
| 305 | // Compare results using memcmp() in case they are both NaN. |
| 306 | if (!memcmp(&ResultSz, &ResultLlc, sizeof(Type))) { |
| 307 | ++Passes; |
| 308 | } else { |
| 309 | ++Failures; |
| 310 | std::cout << std::fixed << "test_fabs" << (CHAR_BIT * sizeof(Type)) << "(" |
| 311 | << Value << "): sz=" << ResultSz << " llc=" << ResultLlc |
| 312 | << "\n"; |
| 313 | } |
Jan Voung | f37fbbe | 2014-07-09 16:13:13 -0700 | [diff] [blame] | 314 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 317 | void testsVecFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame^] | 318 | #if !defined(ARM32) && !defined(NONSFI) |
John Porto | ba6a67c | 2015-09-25 15:19:45 -0700 | [diff] [blame] | 319 | // TODO(jpp): remove this once vector support is implemented. |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 320 | static const float NegInf = -1.0 / 0.0; |
| 321 | static const float PosInf = 1.0 / 0.0; |
| 322 | static const float Nan = 0.0 / 0.0; |
| 323 | static const float NegNan = -0.0 / 0.0; |
| 324 | volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); |
| 325 | const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
| 326 | typedef v4f32 (*FuncType)(v4f32, v4f32); |
| 327 | static struct { |
| 328 | const char *Name; |
| 329 | FuncType FuncLlc; |
| 330 | FuncType FuncSz; |
| 331 | } Funcs[] = { |
| 332 | #define X(inst, op, func) \ |
| 333 | { STR(inst), (FuncType)test##inst, (FuncType)Subzero_::test##inst } \ |
| 334 | , |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 335 | FPOP_TABLE |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 336 | #undef X |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 337 | }; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 338 | const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 339 | const static size_t NumElementsInType = 4; |
| 340 | for (size_t f = 0; f < NumFuncs; ++f) { |
| 341 | PRNG Index; |
| 342 | for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
| 343 | // Initialize the test vectors. |
| 344 | v4f32 Value1, Value2; |
| 345 | for (size_t j = 0; j < NumElementsInType; ++j) { |
Matt Wala | 35ec373 | 2014-07-18 16:32:16 -0700 | [diff] [blame] | 346 | Value1[j] = Values[Index() % NumValues]; |
| 347 | Value2[j] = Values[Index() % NumValues]; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 348 | } |
| 349 | // Perform the test. |
| 350 | v4f32 ResultSz = Funcs[f].FuncSz(Value1, Value2); |
| 351 | v4f32 ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
| 352 | ++TotalTests; |
| 353 | if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { |
| 354 | ++Passes; |
| 355 | } else { |
| 356 | ++Failures; |
Matt Wala | 89a7c2b | 2014-07-22 10:55:30 -0700 | [diff] [blame] | 357 | std::cout << "test" << Funcs[f].Name << "v4f32" |
| 358 | << "(" << vectAsString<v4f32>(Value1) << "," |
| 359 | << vectAsString<v4f32>(Value2) |
| 360 | << "): sz=" << vectAsString<v4f32>(ResultSz) << " llc" |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 361 | << vectAsString<v4f32>(ResultLlc) << "\n"; |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 362 | } |
Jim Stichnoth | 8c980d0 | 2015-03-19 13:01:50 -0700 | [diff] [blame] | 363 | // Special case for unary fabs operation. Use Value1, ignore Value2. |
| 364 | ResultSz = Subzero_::myFabs(Value1); |
| 365 | ResultLlc = myFabs(Value1); |
| 366 | ++TotalTests; |
| 367 | if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { |
| 368 | ++Passes; |
| 369 | } else { |
| 370 | ++Failures; |
| 371 | std::cout << "test_fabs_v4f32" |
| 372 | << "(" << vectAsString<v4f32>(Value1) |
| 373 | << "): sz=" << vectAsString<v4f32>(ResultSz) << " llc" |
| 374 | << vectAsString<v4f32>(ResultLlc) << "\n"; |
| 375 | } |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 376 | } |
| 377 | } |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame^] | 378 | #endif // !ARM32 && !NONSFI |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 379 | } |
| 380 | |
John Porto | 1d23542 | 2015-08-12 12:37:53 -0700 | [diff] [blame] | 381 | #ifdef X8664_STACK_HACK |
| 382 | extern "C" int wrapped_main(int argc, char *argv[]) { |
| 383 | #else // !defined(X8664_STACK_HACK) |
| 384 | int main(int argc, char *argv[]) { |
| 385 | #endif // X8664_STACK_HACK |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 386 | size_t TotalTests = 0; |
| 387 | size_t Passes = 0; |
| 388 | size_t Failures = 0; |
| 389 | |
Jim Stichnoth | 3ef786f | 2014-09-08 11:19:21 -0700 | [diff] [blame] | 390 | testsInt<bool, bool>(TotalTests, Passes, Failures); |
Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 391 | testsInt<uint8_t, myint8_t>(TotalTests, Passes, Failures); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 392 | testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); |
| 393 | testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); |
John Porto | 1d23542 | 2015-08-12 12:37:53 -0700 | [diff] [blame] | 394 | testsInt<uint64, int64>(TotalTests, Passes, Failures); |
Matt Wala | 89a7c2b | 2014-07-22 10:55:30 -0700 | [diff] [blame] | 395 | testsVecInt<v4ui32, v4si32>(TotalTests, Passes, Failures); |
| 396 | testsVecInt<v8ui16, v8si16>(TotalTests, Passes, Failures); |
| 397 | testsVecInt<v16ui8, v16si8>(TotalTests, Passes, Failures); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 398 | testsFp<float>(TotalTests, Passes, Failures); |
| 399 | testsFp<double>(TotalTests, Passes, Failures); |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 400 | testsVecFp(TotalTests, Passes, Failures); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 401 | |
| 402 | std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
| 403 | << " Failures=" << Failures << "\n"; |
| 404 | return Failures; |
| 405 | } |