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

Side by Side Diff: crosstest/test_icmp_main.cpp

Issue 1406593003: Optimize 64-bit compares with zero (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Simplify header file Created 5 years, 2 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
OLDNEW
1 //===- subzero/crosstest/test_icmp_main.cpp - Driver for tests. -----------===// 1 //===- subzero/crosstest/test_icmp_main.cpp - Driver for tests. -----------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // Driver for cross testing the icmp bitcode instruction 10 // Driver for cross testing the icmp bitcode instruction
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 << " llc=" << ResultLlc << "\n"; 114 << " llc=" << ResultLlc << "\n";
115 } 115 }
116 } 116 }
117 } 117 }
118 } 118 }
119 } 119 }
120 } 120 }
121 } 121 }
122 } 122 }
123 123
124 template <typename TypeUnsigned, typename TypeSigned>
125 void testsIntWithZero(size_t &TotalTests, size_t &Passes, size_t &Failures) {
126 typedef bool (*FuncTypeUnsigned)(TypeUnsigned);
127 typedef bool (*FuncTypeSigned)(TypeSigned);
128 static struct {
129 const char *Name;
130 FuncTypeUnsigned FuncLlc;
131 FuncTypeUnsigned FuncSz;
132 } Funcs[] = {
133 #define X(cmp, op) \
134 { \
135 STR(cmp), (FuncTypeUnsigned)icmp_zero##cmp, \
136 (FuncTypeUnsigned)Subzero_::icmp_zero##cmp \
137 } \
138 ,
139 ICMP_U_TABLE
140 #undef X
141 #define X(cmp, op) \
142 { \
143 STR(cmp), (FuncTypeUnsigned)(FuncTypeSigned)icmp_zero##cmp, \
144 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp_zero##cmp \
145 } \
146 ,
147 ICMP_S_TABLE
148 #undef X
149 };
150 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
151
152 if (sizeof(TypeUnsigned) <= sizeof(uint32_t)) {
153 // This is the "normal" version of the loop nest, for 32-bit or
154 // narrower types.
155 for (size_t f = 0; f < NumFuncs; ++f) {
156 for (size_t i = 0; i < NumValues; ++i) {
157 TypeUnsigned Value = Values[i];
158 ++TotalTests;
159 bool ResultSz = Funcs[f].FuncSz(Value);
160 bool ResultLlc = Funcs[f].FuncLlc(Value);
161 if (ResultSz == ResultLlc) {
162 ++Passes;
163 } else {
164 ++Failures;
165 std::cout << "icmp" << Funcs[f].Name
166 << (CHAR_BIT * sizeof(TypeUnsigned)) << "(" << Value
167 << "): sz=" << ResultSz << " llc=" << ResultLlc << "\n";
168 }
169 }
170 }
171 } else {
172 // This is the 64-bit version. Test values are synthesized from
173 // the 32-bit values in Values[].
174 for (size_t f = 0; f < NumFuncs; ++f) {
175 for (size_t iLo = 0; iLo < NumValues; ++iLo) {
176 for (size_t iHi = 0; iHi < NumValues; ++iHi) {
177 TypeUnsigned Value =
178 (((TypeUnsigned)Values[iHi]) << 32) + Values[iLo];
179 ++TotalTests;
180 bool ResultSz = Funcs[f].FuncSz(Value);
181 bool ResultLlc = Funcs[f].FuncLlc(Value);
182 if (ResultSz == ResultLlc) {
183 ++Passes;
184 } else {
185 ++Failures;
186 std::cout << "icmp" << Funcs[f].Name
187 << (CHAR_BIT * sizeof(TypeUnsigned)) << "(" << Value
188 << "): sz=" << ResultSz << " llc=" << ResultLlc << "\n";
189 }
190 }
191 }
192 }
193 }
194 }
195
124 const static size_t MaxTestsPerFunc = 100000; 196 const static size_t MaxTestsPerFunc = 100000;
125 197
126 template <typename TypeUnsignedLabel, typename TypeSignedLabel> 198 template <typename TypeUnsignedLabel, typename TypeSignedLabel>
127 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { 199 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) {
128 #ifndef ARM32 200 #ifndef ARM32
129 // TODO(jpp): remove this once vector support is implemented. 201 // TODO(jpp): remove this once vector support is implemented.
130 typedef typename Vectors<TypeUnsignedLabel>::Ty TypeUnsigned; 202 typedef typename Vectors<TypeUnsignedLabel>::Ty TypeUnsigned;
131 typedef typename Vectors<TypeSignedLabel>::Ty TypeSigned; 203 typedef typename Vectors<TypeSignedLabel>::Ty TypeSigned;
132 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); 204 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned);
133 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); 205 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 int main(int argc, char *argv[]) { 352 int main(int argc, char *argv[]) {
281 #endif // X8664_STACK_HACK 353 #endif // X8664_STACK_HACK
282 size_t TotalTests = 0; 354 size_t TotalTests = 0;
283 size_t Passes = 0; 355 size_t Passes = 0;
284 size_t Failures = 0; 356 size_t Failures = 0;
285 357
286 testsInt<uint8_t, myint8_t>(TotalTests, Passes, Failures); 358 testsInt<uint8_t, myint8_t>(TotalTests, Passes, Failures);
287 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); 359 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures);
288 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); 360 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures);
289 testsInt<uint64, int64>(TotalTests, Passes, Failures); 361 testsInt<uint64, int64>(TotalTests, Passes, Failures);
362 testsIntWithZero<uint8_t, myint8_t>(TotalTests, Passes, Failures);
363 testsIntWithZero<uint16_t, int16_t>(TotalTests, Passes, Failures);
364 testsIntWithZero<uint32_t, int32_t>(TotalTests, Passes, Failures);
365 testsIntWithZero<uint64, int64>(TotalTests, Passes, Failures);
290 testsVecInt<v4ui32, v4si32>(TotalTests, Passes, Failures); 366 testsVecInt<v4ui32, v4si32>(TotalTests, Passes, Failures);
291 testsVecInt<v8ui16, v8si16>(TotalTests, Passes, Failures); 367 testsVecInt<v8ui16, v8si16>(TotalTests, Passes, Failures);
292 testsVecInt<v16ui8, v16si8>(TotalTests, Passes, Failures); 368 testsVecInt<v16ui8, v16si8>(TotalTests, Passes, Failures);
293 testsVecI1<v4i1>(TotalTests, Passes, Failures); 369 testsVecI1<v4i1>(TotalTests, Passes, Failures);
294 testsVecI1<v8i1>(TotalTests, Passes, Failures); 370 testsVecI1<v8i1>(TotalTests, Passes, Failures);
295 testsVecI1<v16i1>(TotalTests, Passes, Failures); 371 testsVecI1<v16i1>(TotalTests, Passes, Failures);
296 372
297 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes 373 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
298 << " Failures=" << Failures << "\n"; 374 << " Failures=" << Failures << "\n";
299 return Failures; 375 return Failures;
300 } 376 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698