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

Side by Side Diff: crosstest/test_arith_main.cpp

Issue 1506653002: Subzero: Add Non-SFI support for x86-32. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes Created 4 years, 11 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/crosstest.cfg ('k') | crosstest/test_global_main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/crosstest/test_arith_main.cpp - Driver for tests -----------===// 1 //===- subzero/crosstest/test_arith_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 crosstesting arithmetic operations 10 // Driver for crosstesting arithmetic operations
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 155 }
156 } 156 }
157 } 157 }
158 } 158 }
159 } 159 }
160 160
161 const static size_t MaxTestsPerFunc = 100000; 161 const static size_t MaxTestsPerFunc = 100000;
162 162
163 template <typename TypeUnsignedLabel, typename TypeSignedLabel> 163 template <typename TypeUnsignedLabel, typename TypeSignedLabel>
164 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { 164 void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) {
165 #ifndef ARM32 165 #if !defined(ARM32) && !defined(NONSFI)
166 // TODO(jpp): remove this once vector support is implemented. 166 // TODO(jpp): remove this once vector support is implemented.
167 typedef typename Vectors<TypeUnsignedLabel>::Ty TypeUnsigned; 167 typedef typename Vectors<TypeUnsignedLabel>::Ty TypeUnsigned;
168 typedef typename Vectors<TypeSignedLabel>::Ty TypeSigned; 168 typedef typename Vectors<TypeSignedLabel>::Ty TypeSigned;
169 typedef typename Vectors<TypeUnsignedLabel>::ElementTy ElementTypeUnsigned; 169 typedef typename Vectors<TypeUnsignedLabel>::ElementTy ElementTypeUnsigned;
170 typedef typename Vectors<TypeSignedLabel>::ElementTy ElementTypeSigned; 170 typedef typename Vectors<TypeSignedLabel>::ElementTy ElementTypeSigned;
171 171
172 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); 172 typedef TypeUnsigned (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned);
173 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned); 173 typedef TypeSigned (*FuncTypeSigned)(TypeSigned, TypeSigned);
174 volatile unsigned Values[] = INT_VALUE_ARRAY; 174 volatile unsigned Values[] = INT_VALUE_ARRAY;
175 const static size_t NumValues = sizeof(Values) / sizeof(*Values); 175 const static size_t NumValues = sizeof(Values) / sizeof(*Values);
(...skipping 21 matching lines...) Expand all
197 SINTOP_TABLE 197 SINTOP_TABLE
198 #undef X 198 #undef X
199 }; 199 };
200 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); 200 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
201 const static size_t NumElementsInType = Vectors<TypeUnsigned>::NumElements; 201 const static size_t NumElementsInType = Vectors<TypeUnsigned>::NumElements;
202 for (size_t f = 0; f < NumFuncs; ++f) { 202 for (size_t f = 0; f < NumFuncs; ++f) {
203 PRNG Index; 203 PRNG Index;
204 for (size_t i = 0; i < MaxTestsPerFunc; ++i) { 204 for (size_t i = 0; i < MaxTestsPerFunc; ++i) {
205 // Initialize the test vectors. 205 // Initialize the test vectors.
206 TypeUnsigned Value1, Value2; 206 TypeUnsigned Value1, Value2;
207 for (size_t j = 0; j < NumElementsInType;) { 207 for (size_t j = 0; j < NumElementsInType; ++j) {
208 ElementTypeUnsigned Element1 = Values[Index() % NumValues]; 208 ElementTypeUnsigned Element1 = Values[Index() % NumValues];
209 ElementTypeUnsigned Element2 = Values[Index() % NumValues]; 209 ElementTypeUnsigned Element2 = Values[Index() % NumValues];
210 if (Funcs[f].ExcludeDivExceptions && 210 if (Funcs[f].ExcludeDivExceptions &&
211 inputsMayTriggerException<ElementTypeSigned>(Element1, Element2)) 211 inputsMayTriggerException<ElementTypeSigned>(Element1, Element2))
212 continue; 212 continue;
213 if (Funcs[f].MaskShiftOperations) 213 if (Funcs[f].MaskShiftOperations)
214 Element2 &= CHAR_BIT * sizeof(ElementTypeUnsigned) - 1; 214 Element2 &= CHAR_BIT * sizeof(ElementTypeUnsigned) - 1;
215 Value1[j] = Element1; 215 Value1[j] = Element1;
216 Value2[j] = Element2; 216 Value2[j] = Element2;
217 ++j;
218 } 217 }
219 // Perform the test. 218 // Perform the test.
220 TypeUnsigned ResultSz, ResultLlc; 219 TypeUnsigned ResultSz, ResultLlc;
221 ++TotalTests; 220 ++TotalTests;
222 if (Funcs[f].FuncSzUnsigned) { 221 if (Funcs[f].FuncSzUnsigned) {
223 ResultSz = Funcs[f].FuncSzUnsigned(Value1, Value2); 222 ResultSz = Funcs[f].FuncSzUnsigned(Value1, Value2);
224 ResultLlc = Funcs[f].FuncLlcUnsigned(Value1, Value2); 223 ResultLlc = Funcs[f].FuncLlcUnsigned(Value1, Value2);
225 } else { 224 } else {
226 ResultSz = Funcs[f].FuncSzSigned(Value1, Value2); 225 ResultSz = Funcs[f].FuncSzSigned(Value1, Value2);
227 ResultLlc = Funcs[f].FuncLlcSigned(Value1, Value2); 226 ResultLlc = Funcs[f].FuncLlcSigned(Value1, Value2);
228 } 227 }
229 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) { 228 if (!memcmp(&ResultSz, &ResultLlc, sizeof(ResultSz))) {
230 ++Passes; 229 ++Passes;
231 } else { 230 } else {
232 ++Failures; 231 ++Failures;
233 std::cout << "test" << Funcs[f].Name << "v" << NumElementsInType << "i" 232 std::cout << "test" << Funcs[f].Name << "v" << NumElementsInType << "i"
234 << (CHAR_BIT * sizeof(ElementTypeUnsigned)) << "(" 233 << (CHAR_BIT * sizeof(ElementTypeUnsigned)) << "("
235 << vectAsString<TypeUnsignedLabel>(Value1) << "," 234 << vectAsString<TypeUnsignedLabel>(Value1) << ","
236 << vectAsString<TypeUnsignedLabel>(Value2) 235 << vectAsString<TypeUnsignedLabel>(Value2)
237 << "): sz=" << vectAsString<TypeUnsignedLabel>(ResultSz) 236 << "): sz=" << vectAsString<TypeUnsignedLabel>(ResultSz)
238 << " llc=" << vectAsString<TypeUnsignedLabel>(ResultLlc) 237 << " llc=" << vectAsString<TypeUnsignedLabel>(ResultLlc)
239 << "\n"; 238 << "\n";
240 } 239 }
241 } 240 }
242 } 241 }
243 #endif // ARM32 242 #endif // !ARM32 && !NONSFI
244 } 243 }
245 244
246 template <typename Type> 245 template <typename Type>
247 void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { 246 void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) {
248 static const Type NegInf = -1.0 / 0.0; 247 static const Type NegInf = -1.0 / 0.0;
249 static const Type PosInf = 1.0 / 0.0; 248 static const Type PosInf = 1.0 / 0.0;
250 static const Type Nan = 0.0 / 0.0; 249 static const Type Nan = 0.0 / 0.0;
251 static const Type NegNan = -0.0 / 0.0; 250 static const Type NegNan = -0.0 / 0.0;
252 volatile Type Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); 251 volatile Type Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
253 const static size_t NumValues = sizeof(Values) / sizeof(*Values); 252 const static size_t NumValues = sizeof(Values) / sizeof(*Values);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } else { 308 } else {
310 ++Failures; 309 ++Failures;
311 std::cout << std::fixed << "test_fabs" << (CHAR_BIT * sizeof(Type)) << "(" 310 std::cout << std::fixed << "test_fabs" << (CHAR_BIT * sizeof(Type)) << "("
312 << Value << "): sz=" << ResultSz << " llc=" << ResultLlc 311 << Value << "): sz=" << ResultSz << " llc=" << ResultLlc
313 << "\n"; 312 << "\n";
314 } 313 }
315 } 314 }
316 } 315 }
317 316
318 void testsVecFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { 317 void testsVecFp(size_t &TotalTests, size_t &Passes, size_t &Failures) {
319 #ifndef ARM32 318 #if !defined(ARM32) && !defined(NONSFI)
320 // TODO(jpp): remove this once vector support is implemented. 319 // TODO(jpp): remove this once vector support is implemented.
321 static const float NegInf = -1.0 / 0.0; 320 static const float NegInf = -1.0 / 0.0;
322 static const float PosInf = 1.0 / 0.0; 321 static const float PosInf = 1.0 / 0.0;
323 static const float Nan = 0.0 / 0.0; 322 static const float Nan = 0.0 / 0.0;
324 static const float NegNan = -0.0 / 0.0; 323 static const float NegNan = -0.0 / 0.0;
325 volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); 324 volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
326 const static size_t NumValues = sizeof(Values) / sizeof(*Values); 325 const static size_t NumValues = sizeof(Values) / sizeof(*Values);
327 typedef v4f32 (*FuncType)(v4f32, v4f32); 326 typedef v4f32 (*FuncType)(v4f32, v4f32);
328 static struct { 327 static struct {
329 const char *Name; 328 const char *Name;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 ++Passes; 368 ++Passes;
370 } else { 369 } else {
371 ++Failures; 370 ++Failures;
372 std::cout << "test_fabs_v4f32" 371 std::cout << "test_fabs_v4f32"
373 << "(" << vectAsString<v4f32>(Value1) 372 << "(" << vectAsString<v4f32>(Value1)
374 << "): sz=" << vectAsString<v4f32>(ResultSz) << " llc" 373 << "): sz=" << vectAsString<v4f32>(ResultSz) << " llc"
375 << vectAsString<v4f32>(ResultLlc) << "\n"; 374 << vectAsString<v4f32>(ResultLlc) << "\n";
376 } 375 }
377 } 376 }
378 } 377 }
379 #endif // ARM32 378 #endif // !ARM32 && !NONSFI
380 } 379 }
381 380
382 #ifdef X8664_STACK_HACK 381 #ifdef X8664_STACK_HACK
383 extern "C" int wrapped_main(int argc, char *argv[]) { 382 extern "C" int wrapped_main(int argc, char *argv[]) {
384 #else // !defined(X8664_STACK_HACK) 383 #else // !defined(X8664_STACK_HACK)
385 int main(int argc, char *argv[]) { 384 int main(int argc, char *argv[]) {
386 #endif // X8664_STACK_HACK 385 #endif // X8664_STACK_HACK
387 size_t TotalTests = 0; 386 size_t TotalTests = 0;
388 size_t Passes = 0; 387 size_t Passes = 0;
389 size_t Failures = 0; 388 size_t Failures = 0;
390 389
391 testsInt<bool, bool>(TotalTests, Passes, Failures); 390 testsInt<bool, bool>(TotalTests, Passes, Failures);
392 testsInt<uint8_t, myint8_t>(TotalTests, Passes, Failures); 391 testsInt<uint8_t, myint8_t>(TotalTests, Passes, Failures);
393 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); 392 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures);
394 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); 393 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures);
395 testsInt<uint64, int64>(TotalTests, Passes, Failures); 394 testsInt<uint64, int64>(TotalTests, Passes, Failures);
396 testsVecInt<v4ui32, v4si32>(TotalTests, Passes, Failures); 395 testsVecInt<v4ui32, v4si32>(TotalTests, Passes, Failures);
397 testsVecInt<v8ui16, v8si16>(TotalTests, Passes, Failures); 396 testsVecInt<v8ui16, v8si16>(TotalTests, Passes, Failures);
398 testsVecInt<v16ui8, v16si8>(TotalTests, Passes, Failures); 397 testsVecInt<v16ui8, v16si8>(TotalTests, Passes, Failures);
399 testsFp<float>(TotalTests, Passes, Failures); 398 testsFp<float>(TotalTests, Passes, Failures);
400 testsFp<double>(TotalTests, Passes, Failures); 399 testsFp<double>(TotalTests, Passes, Failures);
401 testsVecFp(TotalTests, Passes, Failures); 400 testsVecFp(TotalTests, Passes, Failures);
402 401
403 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes 402 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
404 << " Failures=" << Failures << "\n"; 403 << " Failures=" << Failures << "\n";
405 return Failures; 404 return Failures;
406 } 405 }
OLDNEW
« no previous file with comments | « crosstest/crosstest.cfg ('k') | crosstest/test_global_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698