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) << ")" << std::endl; | |
Jim Stichnoth
2014/07/23 20:06:37
We can use "\n" instead of std::endl, per LLVM cod
wala
2014/07/23 20:49:54
Done.
| |
63 std::cout << "llc=" << vectAsString<T>(ResultLlc) << std::endl; | |
64 std::cout << "sz =" << vectAsString<T>(ResultSz) << std::endl; | |
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) | |
112 << ")" << std::endl; | |
113 std::cout << "llc=" << vectAsString<v4f32>(ResultLlc) << std::endl; | |
114 std::cout << "sz =" << vectAsString<v4f32>(ResultSz) << std::endl; | |
115 } | |
116 } | |
117 } | |
118 | |
119 template<typename T> | |
120 void testSelectI1(size_t &TotalTests, size_t &Passes, size_t &Failures) { | |
121 typedef typename Vectors<T>::Ty Ty; | |
122 static const size_t NumElements = Vectors<T>::NumElements; | |
123 PRNG Index; | |
124 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { | |
125 Ty Cond; | |
126 Ty Value1, Value2; | |
127 for (size_t j = 0; j < NumElements; ++j) { | |
128 Cond[j] = Index() % 2; | |
129 Value1[j] = Index() % 2; | |
130 Value2[j] = Index() % 2; | |
131 } | |
132 Ty ResultLlc = select_i1(Cond, Value1, Value2); | |
133 Ty ResultSz = Subzero_::select_i1(Cond, Value1, Value2); | |
134 ++TotalTests; | |
135 if (!memcmp(&ResultLlc, &ResultSz, sizeof(ResultLlc))) { | |
136 ++Passes; | |
137 } else { | |
138 ++Failures; | |
139 std::cout << "select<" << Vectors<T>::TypeName << ">(Cond="; | |
140 std::cout << vectAsString<T>(Cond) | |
141 << ", Value1=" << vectAsString<T>(Value1) | |
142 << ", Value2=" << vectAsString<T>(Value2) << ")" << std::endl; | |
143 std::cout << "llc=" << vectAsString<T>(ResultLlc) << std::endl; | |
144 std::cout << "sz =" << vectAsString<T>(ResultSz) << std::endl; | |
145 } | |
146 } | |
147 } | |
148 | |
149 int main(int argc, char *argv[]) { | |
150 size_t TotalTests = 0; | |
151 size_t Passes = 0; | |
152 size_t Failures = 0; | |
153 | |
154 testSelect<v4f32, v4i1>(TotalTests, Passes, Failures); | |
155 testSelect<v4si32, v4i1>(TotalTests, Passes, Failures); | |
156 testSelect<v4ui32, v4i1>(TotalTests, Passes, Failures); | |
157 testSelect<v8si16, v8i1>(TotalTests, Passes, Failures); | |
158 testSelect<v8ui16, v8i1>(TotalTests, Passes, Failures); | |
159 testSelect<v16si8, v16i1>(TotalTests, Passes, Failures); | |
160 testSelect<v16ui8, v16i1>(TotalTests, Passes, Failures); | |
161 testSelectI1<v4i1>(TotalTests, Passes, Failures); | |
162 testSelectI1<v8i1>(TotalTests, Passes, Failures); | |
163 testSelectI1<v16i1>(TotalTests, Passes, Failures); | |
164 | |
165 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes | |
166 << " Failures=" << Failures << "\n"; | |
167 | |
168 return Failures; | |
169 } | |
OLD | NEW |