OLD | NEW |
(Empty) | |
| 1 //===- subzero/crosstest/test_select_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 the select bitcode instruction |
| 11 // |
| 12 //===----------------------------------------------------------------------===// |
| 13 |
| 14 /* crosstest.py --test=test_select.ll --driver=test_select_main.cpp \ |
| 15 --prefix=Subzero_ --output=test_select */ |
| 16 |
| 17 #include <cfloat> |
| 18 #include <cstring> |
| 19 #include <iostream> |
| 20 |
| 21 #include "test_select.h" |
| 22 |
| 23 namespace Subzero_ { |
| 24 #include "test_select.h" |
| 25 } |
| 26 |
| 27 static const size_t MaxTestsPerFunc = 100000; |
| 28 |
| 29 template <typename T, typename TI1> |
| 30 void testSelect(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 31 typedef typename Vectors<T>::Ty Ty; |
| 32 typedef typename Vectors<TI1>::Ty TyI1; |
| 33 volatile unsigned Values[] = { |
| 34 0x0, 0x1, 0x7ffffffe, 0x7fffffff, |
| 35 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, |
| 36 0x7e, 0x7f, 0x80, 0x81, |
| 37 0xfe, 0xff, 0x100, 0x101, |
| 38 0x7ffe, 0x7fff, 0x8000, 0x8001, |
| 39 0xfffe, 0xffff, 0x10000, 0x10001 |
| 40 }; |
| 41 static const size_t NumValues = sizeof(Values) / sizeof(*Values); |
| 42 static const size_t NumElements = Vectors<T>::NumElements; |
| 43 PRNG Index; |
| 44 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
| 45 TyI1 Cond; |
| 46 Ty Value1, Value2; |
| 47 for (size_t j = 0; j < NumElements; ++j) { |
| 48 Cond[j] = Index() % 2; |
| 49 Value1[j] = Values[Index() % NumValues]; |
| 50 Value2[j] = Values[Index() % NumValues]; |
| 51 } |
| 52 Ty ResultLlc = select(Cond, Value1, Value2); |
| 53 Ty ResultSz = Subzero_::select(Cond, Value1, Value2); |
| 54 ++TotalTests; |
| 55 if (!memcmp(&ResultLlc, &ResultSz, sizeof(ResultLlc))) { |
| 56 ++Passes; |
| 57 } else { |
| 58 ++Failures; |
| 59 std::cout << "select<" << Vectors<T>::TypeName << ">(Cond="; |
| 60 std::cout << vectAsString<TI1>(Cond) |
| 61 << ", Value1=" << vectAsString<T>(Value1) |
| 62 << ", Value2=" << vectAsString<T>(Value2) << ")\n"; |
| 63 std::cout << "llc=" << vectAsString<T>(ResultLlc) << "\n"; |
| 64 std::cout << "sz =" << vectAsString<T>(ResultSz) << "\n"; |
| 65 } |
| 66 } |
| 67 } |
| 68 |
| 69 template<> void |
| 70 testSelect<v4f32, v4i1>(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 71 static const float NegInf = -1.0 / 0.0; |
| 72 static const float PosInf = 1.0 / 0.0; |
| 73 static const float Nan = 0.0 / 0.0; |
| 74 static const float NegNan = -0.0 / 0.0; |
| 75 volatile float Values[] = { |
| 76 0, 1, 0x7e, |
| 77 0x7f, 0x80, 0x81, |
| 78 0xfe, 0xff, 0x7ffe, |
| 79 0x7fff, 0x8000, 0x8001, |
| 80 0xfffe, 0xffff, 0x7ffffffe, |
| 81 0x7fffffff, 0x80000000, 0x80000001, |
| 82 0xfffffffe, 0xffffffff, 0x100000000ll, |
| 83 0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll, |
| 84 0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell, |
| 85 0xffffffffffffffffll, NegInf, PosInf, |
| 86 Nan, NegNan, -0.0, |
| 87 FLT_MIN, FLT_MAX, DBL_MIN, |
| 88 DBL_MAX |
| 89 }; |
| 90 static const size_t NumValues = sizeof(Values) / sizeof(*Values); |
| 91 static const size_t NumElements = 4; |
| 92 PRNG Index; |
| 93 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
| 94 v4si32 Cond; |
| 95 v4f32 Value1, Value2; |
| 96 for (size_t j = 0; j < NumElements; ++j) { |
| 97 Cond[j] = Index() % 2; |
| 98 Value1[j] = Values[Index() % NumValues]; |
| 99 Value2[j] = Values[Index() % NumValues]; |
| 100 } |
| 101 v4f32 ResultLlc = select(Cond, Value1, Value2); |
| 102 v4f32 ResultSz = Subzero_::select(Cond, Value1, Value2); |
| 103 ++TotalTests; |
| 104 if (!memcmp(&ResultLlc, &ResultSz, sizeof(ResultLlc))) { |
| 105 ++Passes; |
| 106 } else { |
| 107 ++Failures; |
| 108 std::cout << "select<v4f32>(Cond="; |
| 109 std::cout << vectAsString<v4i1>(Cond) |
| 110 << ", Value1=" << vectAsString<v4f32>(Value1) |
| 111 << ", Value2=" << vectAsString<v4f32>(Value2) << ")\n"; |
| 112 std::cout << "llc=" << vectAsString<v4f32>(ResultLlc) << "\n"; |
| 113 std::cout << "sz =" << vectAsString<v4f32>(ResultSz) << "\n"; |
| 114 } |
| 115 } |
| 116 } |
| 117 |
| 118 template<typename T> |
| 119 void testSelectI1(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 120 typedef typename Vectors<T>::Ty Ty; |
| 121 static const size_t NumElements = Vectors<T>::NumElements; |
| 122 PRNG Index; |
| 123 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { |
| 124 Ty Cond; |
| 125 Ty Value1, Value2; |
| 126 for (size_t j = 0; j < NumElements; ++j) { |
| 127 Cond[j] = Index() % 2; |
| 128 Value1[j] = Index() % 2; |
| 129 Value2[j] = Index() % 2; |
| 130 } |
| 131 Ty ResultLlc = select_i1(Cond, Value1, Value2); |
| 132 Ty ResultSz = Subzero_::select_i1(Cond, Value1, Value2); |
| 133 ++TotalTests; |
| 134 if (!memcmp(&ResultLlc, &ResultSz, sizeof(ResultLlc))) { |
| 135 ++Passes; |
| 136 } else { |
| 137 ++Failures; |
| 138 std::cout << "select<" << Vectors<T>::TypeName << ">(Cond="; |
| 139 std::cout << vectAsString<T>(Cond) |
| 140 << ", Value1=" << vectAsString<T>(Value1) |
| 141 << ", Value2=" << vectAsString<T>(Value2) << ")\n"; |
| 142 std::cout << "llc=" << vectAsString<T>(ResultLlc) << "\n"; |
| 143 std::cout << "sz =" << vectAsString<T>(ResultSz) << "\n"; |
| 144 } |
| 145 } |
| 146 } |
| 147 |
| 148 int main(int argc, char *argv[]) { |
| 149 size_t TotalTests = 0; |
| 150 size_t Passes = 0; |
| 151 size_t Failures = 0; |
| 152 |
| 153 testSelect<v4f32, v4i1>(TotalTests, Passes, Failures); |
| 154 testSelect<v4si32, v4i1>(TotalTests, Passes, Failures); |
| 155 testSelect<v4ui32, v4i1>(TotalTests, Passes, Failures); |
| 156 testSelect<v8si16, v8i1>(TotalTests, Passes, Failures); |
| 157 testSelect<v8ui16, v8i1>(TotalTests, Passes, Failures); |
| 158 testSelect<v16si8, v16i1>(TotalTests, Passes, Failures); |
| 159 testSelect<v16ui8, v16i1>(TotalTests, Passes, Failures); |
| 160 testSelectI1<v4i1>(TotalTests, Passes, Failures); |
| 161 testSelectI1<v8i1>(TotalTests, Passes, Failures); |
| 162 testSelectI1<v16i1>(TotalTests, Passes, Failures); |
| 163 |
| 164 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
| 165 << " Failures=" << Failures << "\n"; |
| 166 |
| 167 return Failures; |
| 168 } |
OLD | NEW |