Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: crosstest/test_icmp_main.cpp

Issue 412593002: Lower icmp operations between vector values. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Remove unused typedefs. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « crosstest/test_icmp_i1vec.ll ('k') | src/IceTargetLoweringX8632.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* crosstest.py --test=test_icmp.cpp --driver=test_icmp_main.cpp \ 1 //===- subzero/crosstest/test_icmp_main.cpp - Driver for tests. -----------===//
2 --prefix=Subzero_ --output=test_icmp */ 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 cross testing the icmp bitcode instruction
11 //
12 //===----------------------------------------------------------------------===//
3 13
14 /* crosstest.py --test=test_icmp.cpp --test=test_icmp_i1vec.ll \
15 --driver=test_icmp_main.cpp --prefix=Subzero_ --output=test_icmp */
16
17 #include <climits> // CHAR_BIT
18 #include <cstring> // memcmp, memset
4 #include <stdint.h> 19 #include <stdint.h>
5 #include <iostream> 20 #include <iostream>
6 21
7 // Include test_icmp.h twice - once normally, and once within the 22 // Include test_icmp.h twice - once normally, and once within the
8 // Subzero_ namespace, corresponding to the llc and Subzero translated 23 // Subzero_ namespace, corresponding to the llc and Subzero translated
9 // object files, respectively. 24 // object files, respectively.
10 #include "test_icmp.h" 25 #include "test_icmp.h"
11 namespace Subzero_ { 26 namespace Subzero_ {
12 #include "test_icmp.h" 27 #include "test_icmp.h"
13 } 28 }
(...skipping 14 matching lines...) Expand all
28 const char *Name; 43 const char *Name;
29 FuncTypeUnsigned FuncLlc; 44 FuncTypeUnsigned FuncLlc;
30 FuncTypeUnsigned FuncSz; 45 FuncTypeUnsigned FuncSz;
31 } Funcs[] = { 46 } Funcs[] = {
32 #define X(cmp, op) \ 47 #define X(cmp, op) \
33 { \ 48 { \
34 STR(inst), (FuncTypeUnsigned)icmp##cmp, \ 49 STR(inst), (FuncTypeUnsigned)icmp##cmp, \
35 (FuncTypeUnsigned)Subzero_::icmp##cmp \ 50 (FuncTypeUnsigned)Subzero_::icmp##cmp \
36 } \ 51 } \
37 , 52 ,
38 ICMP_U_TABLE 53 ICMP_U_TABLE
39 #undef X 54 #undef X
40 #define X(cmp, op) \ 55 #define X(cmp, op) \
41 { \ 56 { \
42 STR(inst), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \ 57 STR(inst), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \
43 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp \ 58 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp \
44 } \ 59 } \
45 , 60 ,
46 ICMP_S_TABLE 61 ICMP_S_TABLE
47 #undef X 62 #undef X
48 }; 63 };
49 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); 64 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
50 65
51 if (sizeof(TypeUnsigned) <= sizeof(uint32_t)) { 66 if (sizeof(TypeUnsigned) <= sizeof(uint32_t)) {
52 // This is the "normal" version of the loop nest, for 32-bit or 67 // This is the "normal" version of the loop nest, for 32-bit or
53 // narrower types. 68 // narrower types.
54 for (size_t f = 0; f < NumFuncs; ++f) { 69 for (size_t f = 0; f < NumFuncs; ++f) {
55 for (size_t i = 0; i < NumValues; ++i) { 70 for (size_t i = 0; i < NumValues; ++i) {
56 for (size_t j = 0; j < NumValues; ++j) { 71 for (size_t j = 0; j < NumValues; ++j) {
57 TypeUnsigned Value1 = Values[i]; 72 TypeUnsigned Value1 = Values[i];
58 TypeUnsigned Value2 = Values[j]; 73 TypeUnsigned Value2 = Values[j];
59 ++TotalTests; 74 ++TotalTests;
60 bool ResultSz = Funcs[f].FuncSz(Value1, Value2); 75 bool ResultSz = Funcs[f].FuncSz(Value1, Value2);
61 bool ResultLlc = Funcs[f].FuncLlc(Value1, Value2); 76 bool ResultLlc = Funcs[f].FuncLlc(Value1, Value2);
62 if (ResultSz == ResultLlc) { 77 if (ResultSz == ResultLlc) {
63 ++Passes; 78 ++Passes;
64 } else { 79 } else {
65 ++Failures; 80 ++Failures;
66 std::cout << "icmp" << Funcs[f].Name << (8 * sizeof(TypeUnsigned)) 81 std::cout << "icmp" << Funcs[f].Name
67 << "(" << Value1 << ", " << Value2 << "): sz=" << ResultSz 82 << (CHAR_BIT * sizeof(TypeUnsigned)) << "(" << Value1
83 << ", " << Value2 << "): sz=" << ResultSz
68 << " llc=" << ResultLlc << std::endl; 84 << " llc=" << ResultLlc << std::endl;
69 } 85 }
70 } 86 }
71 } 87 }
72 } 88 }
73 } else { 89 } else {
74 // This is the 64-bit version. Test values are synthesized from 90 // This is the 64-bit version. Test values are synthesized from
75 // the 32-bit values in Values[]. 91 // the 32-bit values in Values[].
76 for (size_t f = 0; f < NumFuncs; ++f) { 92 for (size_t f = 0; f < NumFuncs; ++f) {
77 for (size_t iLo = 0; iLo < NumValues; ++iLo) { 93 for (size_t iLo = 0; iLo < NumValues; ++iLo) {
78 for (size_t iHi = 0; iHi < NumValues; ++iHi) { 94 for (size_t iHi = 0; iHi < NumValues; ++iHi) {
79 for (size_t jLo = 0; jLo < NumValues; ++jLo) { 95 for (size_t jLo = 0; jLo < NumValues; ++jLo) {
80 for (size_t jHi = 0; jHi < NumValues; ++jHi) { 96 for (size_t jHi = 0; jHi < NumValues; ++jHi) {
81 TypeUnsigned Value1 = 97 TypeUnsigned Value1 =
82 (((TypeUnsigned)Values[iHi]) << 32) + Values[iLo]; 98 (((TypeUnsigned)Values[iHi]) << 32) + Values[iLo];
83 TypeUnsigned Value2 = 99 TypeUnsigned Value2 =
84 (((TypeUnsigned)Values[jHi]) << 32) + Values[jLo]; 100 (((TypeUnsigned)Values[jHi]) << 32) + Values[jLo];
85 ++TotalTests; 101 ++TotalTests;
86 bool ResultSz = Funcs[f].FuncSz(Value1, Value2); 102 bool ResultSz = Funcs[f].FuncSz(Value1, Value2);
87 bool ResultLlc = Funcs[f].FuncLlc(Value1, Value2); 103 bool ResultLlc = Funcs[f].FuncLlc(Value1, Value2);
88 if (ResultSz == ResultLlc) { 104 if (ResultSz == ResultLlc) {
89 ++Passes; 105 ++Passes;
90 } else { 106 } else {
91 ++Failures; 107 ++Failures;
92 std::cout << "icmp" << Funcs[f].Name 108 std::cout << "icmp" << Funcs[f].Name
93 << (8 * sizeof(TypeUnsigned)) << "(" << Value1 << ", " 109 << (CHAR_BIT * sizeof(TypeUnsigned)) << "(" << Value1
94 << Value2 << "): sz=" << ResultSz 110 << ", " << Value2 << "): sz=" << ResultSz
95 << " llc=" << ResultLlc << std::endl; 111 << " llc=" << ResultLlc << std::endl;
96 } 112 }
97 } 113 }
98 } 114 }
99 } 115 }
100 } 116 }
101 } 117 }
102 } 118 }
103 } 119 }
104 120
121 const static size_t MaxTestsPerFunc = 100000;
122
123 template <typename TypeUnsignedLabel, typename TypeSignedLabel>
124 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) {
125 typedef typename Vectors<TypeUnsignedLabel>::Ty TypeUnsigned;
126 typedef typename Vectors<TypeSignedLabel>::Ty TypeSigned;
127 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned);
128 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned);
129 static struct {
130 const char *Name;
131 FuncTypeUnsigned FuncLlc;
132 FuncTypeUnsigned FuncSz;
133 } Funcs[] = {
134 #define X(cmp, op) \
135 { \
136 STR(inst), (FuncTypeUnsigned)icmp##cmp, \
137 (FuncTypeUnsigned)Subzero_::icmp##cmp \
138 } \
139 ,
140 ICMP_U_TABLE
141 #undef X
142 #define X(cmp, op) \
143 { \
144 STR(inst), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \
145 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp \
146 } \
147 ,
148 ICMP_S_TABLE
149 #undef X
150 };
151 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
152 const static size_t NumElementsInType = Vectors<TypeUnsigned>::NumElements;
153 for (size_t f = 0; f < NumFuncs; ++f) {
154 PRNG Index;
155 for (size_t i = 0; i < MaxTestsPerFunc; ++i) {
156 // Initialize the test vectors.
157 TypeUnsigned Value1, Value2;
158 for (size_t j = 0; j < NumElementsInType;) {
159 Value1[j] = Values[Index() % NumValues];
160 Value2[j] = Values[Index() % NumValues];
161 ++j;
162 }
163 // Perform the test.
164 TypeUnsigned ResultSz = Funcs[f].FuncSz(Value1, Value2);
165 TypeUnsigned ResultLlc = Funcs[f].FuncLlc(Value1, Value2);
166 ++TotalTests;
167 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) {
168 ++Passes;
169 } else {
170 ++Failures;
171 std::cout << "test" << Funcs[f].Name
172 << Vectors<TypeUnsignedLabel>::TypeName << "("
173 << vectAsString<TypeUnsignedLabel>(Value1) << ","
174 << vectAsString<TypeUnsignedLabel>(Value2)
175 << "): sz=" << vectAsString<TypeUnsignedLabel>(ResultSz)
176 << " llc=" << vectAsString<TypeUnsignedLabel>(ResultLlc)
177 << std::endl;
178 }
179 }
180 }
181 }
182
183 // Return true on wraparound
184 template <typename T> bool incrementI1Vector(typename Vectors<T>::Ty &Vect) {
185 size_t Pos = 0;
186 const static size_t NumElements = Vectors<T>::NumElements;
187 for (Pos = 0; Pos < NumElements; ++Pos) {
188 if (Vect[Pos] == 0) {
189 Vect[Pos] = 1;
190 break;
191 }
192 Vect[Pos] = 0;
193 }
194 return (Pos == NumElements);
195 }
196
197 template <typename T>
198 void testsVecI1(size_t &TotalTests, size_t &Passes, size_t &Failures) {
199 typedef typename Vectors<T>::Ty Ty;
200 typedef Ty (*FuncType)(Ty, Ty);
201 static struct {
202 const char *Name;
203 FuncType FuncLlc;
204 FuncType FuncSz;
205 } Funcs[] = {
206 #define X(cmp, op) \
207 { STR(inst), (FuncType)icmpi1##cmp, (FuncType)Subzero_::icmpi1##cmp } \
208 ,
209 ICMP_U_TABLE
210 ICMP_S_TABLE
211 };
212 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
213 const static size_t NumElements = Vectors<T>::NumElements;
214 const static size_t MAX_NUMBER_OF_ELEMENTS_FOR_EXHAUSTIVE_TESTING = 8;
215
216 // Check if the type is small enough to try all possible input pairs.
217 if (NumElements <= MAX_NUMBER_OF_ELEMENTS_FOR_EXHAUSTIVE_TESTING) {
218 for (size_t f = 0; f < NumFuncs; ++f) {
219 Ty Value1, Value2;
220 memset(&Value1, 0, sizeof(Value1));
221 for (bool IsValue1Done = false; !IsValue1Done;
222 IsValue1Done = incrementI1Vector<T>(Value1)) {
223 memset(&Value2, 0, sizeof(Value2));
224 for (bool IsValue2Done = false; !IsValue2Done;
225 IsValue2Done = incrementI1Vector<T>(Value2)) {
226 Ty ResultSz = Funcs[f].FuncSz(Value1, Value2);
227 Ty ResultLlc = Funcs[f].FuncLlc(Value1, Value2);
228 ++TotalTests;
229 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) {
230 ++Passes;
231 } else {
232 ++Failures;
233 std::cout << "test" << Funcs[f].Name << Vectors<T>::TypeName << "("
234 << vectAsString<T>(Value1) << ","
235 << vectAsString<T>(Value2)
236 << "): sz=" << vectAsString<T>(ResultSz)
237 << " llc=" << vectAsString<T>(ResultLlc) << std::endl;
238 }
239 }
240 }
241 }
242 } else {
243 for (size_t f = 0; f < NumFuncs; ++f) {
244 PRNG Index;
245 for (size_t i = 0; i < MaxTestsPerFunc; ++i) {
246 Ty Value1, Value2;
247 // Initialize the test vectors.
248 for (size_t j = 0; j < NumElements; ++j) {
249 Value1[j] = Index() % 2;
250 Value2[j] = Index() % 2;
251 }
252 // Perform the test.
253 Ty ResultSz = Funcs[f].FuncSz(Value1, Value2);
254 Ty ResultLlc = Funcs[f].FuncLlc(Value1, Value2);
255 ++TotalTests;
256 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) {
257 ++Passes;
258 } else {
259 ++Failures;
260 std::cout << "test" << Funcs[f].Name << Vectors<T>::TypeName << "("
261 << vectAsString<T>(Value1) << "," << vectAsString<T>(Value2)
262 << "): sz=" << vectAsString<T>(ResultSz)
263 << " llc=" << vectAsString<T>(ResultLlc) << std::endl;
264 }
265 }
266 }
267 }
268 }
269
105 int main(int argc, char **argv) { 270 int main(int argc, char **argv) {
106 size_t TotalTests = 0; 271 size_t TotalTests = 0;
107 size_t Passes = 0; 272 size_t Passes = 0;
108 size_t Failures = 0; 273 size_t Failures = 0;
109 274
110 testsInt<uint8_t, int8_t>(TotalTests, Passes, Failures); 275 testsInt<uint8_t, int8_t>(TotalTests, Passes, Failures);
111 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); 276 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures);
112 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); 277 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures);
113 testsInt<uint64_t, int64_t>(TotalTests, Passes, Failures); 278 testsInt<uint64_t, int64_t>(TotalTests, Passes, Failures);
279 testsVecInt<v4ui32, v4si32>(TotalTests, Passes, Failures);
280 testsVecInt<v8ui16, v8si16>(TotalTests, Passes, Failures);
281 testsVecInt<v16ui8, v16si8>(TotalTests, Passes, Failures);
282 testsVecI1<v4i1>(TotalTests, Passes, Failures);
283 testsVecI1<v8i1>(TotalTests, Passes, Failures);
284 testsVecI1<v16i1>(TotalTests, Passes, Failures);
114 285
115 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes 286 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
116 << " Failures=" << Failures << "\n"; 287 << " Failures=" << Failures << "\n";
117 return Failures; 288 return Failures;
118 } 289 }
OLDNEW
« no previous file with comments | « crosstest/test_icmp_i1vec.ll ('k') | src/IceTargetLoweringX8632.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698