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

Side by Side Diff: bench/MathBench.cpp

Issue 1232463006: Fix up -Winconsistent-missing-override (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: llvm_coverage_build Created 5 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 | « bench/InterpBench.cpp ('k') | bench/Matrix44Bench.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 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
1 #include "Benchmark.h" 8 #include "Benchmark.h"
2 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
3 #include "SkMatrix.h" 10 #include "SkMatrix.h"
4 #include "SkPaint.h" 11 #include "SkPaint.h"
5 #include "SkRandom.h" 12 #include "SkRandom.h"
6 #include "SkString.h" 13 #include "SkString.h"
7 14
8 static float sk_fsel(float pred, float result_ge, float result_lt) { 15 static float sk_fsel(float pred, float result_ge, float result_lt) {
9 return pred >= 0 ? result_ge : result_lt; 16 return pred >= 0 ? result_ge : result_lt;
10 } 17 }
(...skipping 24 matching lines...) Expand all
35 return backend == kNonRendering_Backend; 42 return backend == kNonRendering_Backend;
36 } 43 }
37 44
38 virtual void performTest(float* SK_RESTRICT dst, 45 virtual void performTest(float* SK_RESTRICT dst,
39 const float* SK_RESTRICT src, 46 const float* SK_RESTRICT src,
40 int count) = 0; 47 int count) = 0;
41 48
42 protected: 49 protected:
43 virtual int mulLoopCount() const { return 1; } 50 virtual int mulLoopCount() const { return 1; }
44 51
45 virtual const char* onGetName() { 52 const char* onGetName() override {
46 return fName.c_str(); 53 return fName.c_str();
47 } 54 }
48 55
49 virtual void onDraw(const int loops, SkCanvas*) { 56 void onDraw(const int loops, SkCanvas*) override {
50 int n = loops * this->mulLoopCount(); 57 int n = loops * this->mulLoopCount();
51 for (int i = 0; i < n; i++) { 58 for (int i = 0; i < n; i++) {
52 this->performTest(fDst, fSrc, kBuffer); 59 this->performTest(fDst, fSrc, kBuffer);
53 } 60 }
54 } 61 }
55 62
56 private: 63 private:
57 typedef Benchmark INHERITED; 64 typedef Benchmark INHERITED;
58 }; 65 };
59 66
60 class MathBenchU32 : public MathBench { 67 class MathBenchU32 : public MathBench {
61 public: 68 public:
62 MathBenchU32(const char name[]) : INHERITED(name) {} 69 MathBenchU32(const char name[]) : INHERITED(name) {}
63 70
64 protected: 71 protected:
65 virtual void performITest(uint32_t* SK_RESTRICT dst, 72 virtual void performITest(uint32_t* SK_RESTRICT dst,
66 const uint32_t* SK_RESTRICT src, 73 const uint32_t* SK_RESTRICT src,
67 int count) = 0; 74 int count) = 0;
68 75
69 virtual void performTest(float* SK_RESTRICT dst, 76 void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int c ount) override {
70 const float* SK_RESTRICT src,
71 int count) override {
72 uint32_t* d = SkTCast<uint32_t*>(dst); 77 uint32_t* d = SkTCast<uint32_t*>(dst);
73 const uint32_t* s = SkTCast<const uint32_t*>(src); 78 const uint32_t* s = SkTCast<const uint32_t*>(src);
74 this->performITest(d, s, count); 79 this->performITest(d, s, count);
75 } 80 }
76 private: 81 private:
77 typedef MathBench INHERITED; 82 typedef MathBench INHERITED;
78 }; 83 };
79 84
80 /////////////////////////////////////////////////////////////////////////////// 85 ///////////////////////////////////////////////////////////////////////////////
81 86
82 class NoOpMathBench : public MathBench { 87 class NoOpMathBench : public MathBench {
83 public: 88 public:
84 NoOpMathBench() : INHERITED("noOp") {} 89 NoOpMathBench() : INHERITED("noOp") {}
85 protected: 90 protected:
86 virtual void performTest(float* SK_RESTRICT dst, 91 void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int c ount) override {
87 const float* SK_RESTRICT src,
88 int count) {
89 for (int i = 0; i < count; ++i) { 92 for (int i = 0; i < count; ++i) {
90 dst[i] = src[i] + 1; 93 dst[i] = src[i] + 1;
91 } 94 }
92 } 95 }
93 private: 96 private:
94 typedef MathBench INHERITED; 97 typedef MathBench INHERITED;
95 }; 98 };
96 99
97 class SkRSqrtMathBench : public MathBench { 100 class SkRSqrtMathBench : public MathBench {
98 public: 101 public:
99 SkRSqrtMathBench() : INHERITED("sk_float_rsqrt") {} 102 SkRSqrtMathBench() : INHERITED("sk_float_rsqrt") {}
100 protected: 103 protected:
101 virtual void performTest(float* SK_RESTRICT dst, 104 void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int c ount) override {
102 const float* SK_RESTRICT src,
103 int count) {
104 for (int i = 0; i < count; ++i) { 105 for (int i = 0; i < count; ++i) {
105 dst[i] = sk_float_rsqrt(src[i]); 106 dst[i] = sk_float_rsqrt(src[i]);
106 } 107 }
107 } 108 }
108 private: 109 private:
109 typedef MathBench INHERITED; 110 typedef MathBench INHERITED;
110 }; 111 };
111 112
112 113
113 class SlowISqrtMathBench : public MathBench { 114 class SlowISqrtMathBench : public MathBench {
114 public: 115 public:
115 SlowISqrtMathBench() : INHERITED("slowIsqrt") {} 116 SlowISqrtMathBench() : INHERITED("slowIsqrt") {}
116 protected: 117 protected:
117 virtual void performTest(float* SK_RESTRICT dst, 118 void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int c ount) override {
118 const float* SK_RESTRICT src,
119 int count) {
120 for (int i = 0; i < count; ++i) { 119 for (int i = 0; i < count; ++i) {
121 dst[i] = 1.0f / sk_float_sqrt(src[i]); 120 dst[i] = 1.0f / sk_float_sqrt(src[i]);
122 } 121 }
123 } 122 }
124 private: 123 private:
125 typedef MathBench INHERITED; 124 typedef MathBench INHERITED;
126 }; 125 };
127 126
128 static inline float SkFastInvSqrt(float x) { 127 static inline float SkFastInvSqrt(float x) {
129 float xhalf = 0.5f*x; 128 float xhalf = 0.5f*x;
130 int i = *SkTCast<int*>(&x); 129 int i = *SkTCast<int*>(&x);
131 i = 0x5f3759df - (i>>1); 130 i = 0x5f3759df - (i>>1);
132 x = *SkTCast<float*>(&i); 131 x = *SkTCast<float*>(&i);
133 x = x*(1.5f-xhalf*x*x); 132 x = x*(1.5f-xhalf*x*x);
134 // x = x*(1.5f-xhalf*x*x); // this line takes err from 10^-3 to 10^-6 133 // x = x*(1.5f-xhalf*x*x); // this line takes err from 10^-3 to 10^-6
135 return x; 134 return x;
136 } 135 }
137 136
138 class FastISqrtMathBench : public MathBench { 137 class FastISqrtMathBench : public MathBench {
139 public: 138 public:
140 FastISqrtMathBench() : INHERITED("fastIsqrt") {} 139 FastISqrtMathBench() : INHERITED("fastIsqrt") {}
141 protected: 140 protected:
142 virtual void performTest(float* SK_RESTRICT dst, 141 void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int c ount) override {
143 const float* SK_RESTRICT src,
144 int count) {
145 for (int i = 0; i < count; ++i) { 142 for (int i = 0; i < count; ++i) {
146 dst[i] = SkFastInvSqrt(src[i]); 143 dst[i] = SkFastInvSqrt(src[i]);
147 } 144 }
148 } 145 }
149 private: 146 private:
150 typedef MathBench INHERITED; 147 typedef MathBench INHERITED;
151 }; 148 };
152 149
153 static inline uint32_t QMul64(uint32_t value, U8CPU alpha) { 150 static inline uint32_t QMul64(uint32_t value, U8CPU alpha) {
154 SkASSERT((uint8_t)alpha == alpha); 151 SkASSERT((uint8_t)alpha == alpha);
155 const uint32_t mask = 0xFF00FF; 152 const uint32_t mask = 0xFF00FF;
156 153
157 uint64_t tmp = value; 154 uint64_t tmp = value;
158 tmp = (tmp & mask) | ((tmp & ~mask) << 24); 155 tmp = (tmp & mask) | ((tmp & ~mask) << 24);
159 tmp *= alpha; 156 tmp *= alpha;
160 return (uint32_t) (((tmp >> 8) & mask) | ((tmp >> 32) & ~mask)); 157 return (uint32_t) (((tmp >> 8) & mask) | ((tmp >> 32) & ~mask));
161 } 158 }
162 159
163 class QMul64Bench : public MathBenchU32 { 160 class QMul64Bench : public MathBenchU32 {
164 public: 161 public:
165 QMul64Bench() : INHERITED("qmul64") {} 162 QMul64Bench() : INHERITED("qmul64") {}
166 protected: 163 protected:
167 virtual void performITest(uint32_t* SK_RESTRICT dst, 164 void performITest(uint32_t* SK_RESTRICT dst,
168 const uint32_t* SK_RESTRICT src, 165 const uint32_t* SK_RESTRICT src,
169 int count) override { 166 int count) override {
170 for (int i = 0; i < count; ++i) { 167 for (int i = 0; i < count; ++i) {
171 dst[i] = QMul64(src[i], (uint8_t)i); 168 dst[i] = QMul64(src[i], (uint8_t)i);
172 } 169 }
173 } 170 }
174 private: 171 private:
175 typedef MathBenchU32 INHERITED; 172 typedef MathBenchU32 INHERITED;
176 }; 173 };
177 174
178 class QMul32Bench : public MathBenchU32 { 175 class QMul32Bench : public MathBenchU32 {
179 public: 176 public:
180 QMul32Bench() : INHERITED("qmul32") {} 177 QMul32Bench() : INHERITED("qmul32") {}
181 protected: 178 protected:
182 virtual void performITest(uint32_t* SK_RESTRICT dst, 179 void performITest(uint32_t* SK_RESTRICT dst,
183 const uint32_t* SK_RESTRICT src, 180 const uint32_t* SK_RESTRICT src,
184 int count) override { 181 int count) override {
185 for (int i = 0; i < count; ++i) { 182 for (int i = 0; i < count; ++i) {
186 dst[i] = SkAlphaMulQ(src[i], (uint8_t)i); 183 dst[i] = SkAlphaMulQ(src[i], (uint8_t)i);
187 } 184 }
188 } 185 }
189 private: 186 private:
190 typedef MathBenchU32 INHERITED; 187 typedef MathBenchU32 INHERITED;
191 }; 188 };
192 189
193 /////////////////////////////////////////////////////////////////////////////// 190 ///////////////////////////////////////////////////////////////////////////////
194 191
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 fProc = gRec[index].fProc; 280 fProc = gRec[index].fProc;
284 fName = gRec[index].fName; 281 fName = gRec[index].fName;
285 } 282 }
286 } 283 }
287 284
288 bool isSuitableFor(Backend backend) override { 285 bool isSuitableFor(Backend backend) override {
289 return backend == kNonRendering_Backend; 286 return backend == kNonRendering_Backend;
290 } 287 }
291 288
292 protected: 289 protected:
293 virtual void onDraw(const int loops, SkCanvas*) { 290 void onDraw(const int loops, SkCanvas*) override {
294 IsFiniteProc proc = fProc; 291 IsFiniteProc proc = fProc;
295 const float* data = fData; 292 const float* data = fData;
296 // do this so the compiler won't throw away the function call 293 // do this so the compiler won't throw away the function call
297 int counter = 0; 294 int counter = 0;
298 295
299 if (proc) { 296 if (proc) {
300 for (int j = 0; j < loops; ++j) { 297 for (int j = 0; j < loops; ++j) {
301 for (int i = 0; i < N - 4; ++i) { 298 for (int i = 0; i < N - 4; ++i) {
302 counter += proc(&data[i]); 299 counter += proc(&data[i]);
303 } 300 }
304 } 301 }
305 } else { 302 } else {
306 for (int j = 0; j < loops; ++j) { 303 for (int j = 0; j < loops; ++j) {
307 for (int i = 0; i < N - 4; ++i) { 304 for (int i = 0; i < N - 4; ++i) {
308 const SkRect* r = reinterpret_cast<const SkRect*>(&data[i]); 305 const SkRect* r = reinterpret_cast<const SkRect*>(&data[i]);
309 if (false) { // avoid bit rot, suppress warning 306 if (false) { // avoid bit rot, suppress warning
310 isFinite(*r); 307 isFinite(*r);
311 } 308 }
312 counter += r->isFinite(); 309 counter += r->isFinite();
313 } 310 }
314 } 311 }
315 } 312 }
316 313
317 SkPaint paint; 314 SkPaint paint;
318 if (paint.getAlpha() == 0) { 315 if (paint.getAlpha() == 0) {
319 SkDebugf("%d\n", counter); 316 SkDebugf("%d\n", counter);
320 } 317 }
321 } 318 }
322 319
323 virtual const char* onGetName() { 320 const char* onGetName() override {
324 return fName; 321 return fName;
325 } 322 }
326 323
327 private: 324 private:
328 IsFiniteProc fProc; 325 IsFiniteProc fProc;
329 const char* fName; 326 const char* fName;
330 327
331 typedef Benchmark INHERITED; 328 typedef Benchmark INHERITED;
332 }; 329 };
333 330
(...skipping 19 matching lines...) Expand all
353 } 350 }
354 } 351 }
355 352
356 bool isSuitableFor(Backend backend) override { 353 bool isSuitableFor(Backend backend) override {
357 return backend == kNonRendering_Backend; 354 return backend == kNonRendering_Backend;
358 } 355 }
359 356
360 virtual void process(float) {} 357 virtual void process(float) {}
361 358
362 protected: 359 protected:
363 virtual void onDraw(const int loops, SkCanvas*) { 360 void onDraw(const int loops, SkCanvas*) override {
364 SkRandom rand; 361 SkRandom rand;
365 float accum = 0; 362 float accum = 0;
366 const float* data = fData; 363 const float* data = fData;
367 364
368 if (fFast) { 365 if (fFast) {
369 for (int j = 0; j < loops; ++j) { 366 for (int j = 0; j < loops; ++j) {
370 for (int i = 0; i < ARRAY; ++i) { 367 for (int i = 0; i < ARRAY; ++i) {
371 accum += fast_floor(data[i]); 368 accum += fast_floor(data[i]);
372 } 369 }
373 this->process(accum); 370 this->process(accum);
374 } 371 }
375 } else { 372 } else {
376 for (int j = 0; j < loops; ++j) { 373 for (int j = 0; j < loops; ++j) {
377 for (int i = 0; i < ARRAY; ++i) { 374 for (int i = 0; i < ARRAY; ++i) {
378 accum += sk_float_floor(data[i]); 375 accum += sk_float_floor(data[i]);
379 } 376 }
380 this->process(accum); 377 this->process(accum);
381 } 378 }
382 } 379 }
383 } 380 }
384 381
385 virtual const char* onGetName() { 382 const char* onGetName() override {
386 return fName; 383 return fName;
387 } 384 }
388 385
389 private: 386 private:
390 const char* fName; 387 const char* fName;
391 388
392 typedef Benchmark INHERITED; 389 typedef Benchmark INHERITED;
393 }; 390 };
394 391
395 class CLZBench : public Benchmark { 392 class CLZBench : public Benchmark {
(...skipping 19 matching lines...) Expand all
415 } 412 }
416 413
417 bool isSuitableFor(Backend backend) override { 414 bool isSuitableFor(Backend backend) override {
418 return backend == kNonRendering_Backend; 415 return backend == kNonRendering_Backend;
419 } 416 }
420 417
421 // just so the compiler doesn't remove our loops 418 // just so the compiler doesn't remove our loops
422 virtual void process(int) {} 419 virtual void process(int) {}
423 420
424 protected: 421 protected:
425 virtual void onDraw(const int loops, SkCanvas*) { 422 void onDraw(const int loops, SkCanvas*) override {
426 int accum = 0; 423 int accum = 0;
427 424
428 if (fUsePortable) { 425 if (fUsePortable) {
429 for (int j = 0; j < loops; ++j) { 426 for (int j = 0; j < loops; ++j) {
430 for (int i = 0; i < ARRAY; ++i) { 427 for (int i = 0; i < ARRAY; ++i) {
431 accum += SkCLZ_portable(fData[i]); 428 accum += SkCLZ_portable(fData[i]);
432 } 429 }
433 this->process(accum); 430 this->process(accum);
434 } 431 }
435 } else { 432 } else {
436 for (int j = 0; j < loops; ++j) { 433 for (int j = 0; j < loops; ++j) {
437 for (int i = 0; i < ARRAY; ++i) { 434 for (int i = 0; i < ARRAY; ++i) {
438 accum += SkCLZ(fData[i]); 435 accum += SkCLZ(fData[i]);
439 } 436 }
440 this->process(accum); 437 this->process(accum);
441 } 438 }
442 } 439 }
443 } 440 }
444 441
445 virtual const char* onGetName() { 442 const char* onGetName() override {
446 return fName; 443 return fName;
447 } 444 }
448 445
449 private: 446 private:
450 const char* fName; 447 const char* fName;
451 448
452 typedef Benchmark INHERITED; 449 typedef Benchmark INHERITED;
453 }; 450 };
454 451
455 /////////////////////////////////////////////////////////////////////////////// 452 ///////////////////////////////////////////////////////////////////////////////
(...skipping 15 matching lines...) Expand all
471 } 468 }
472 469
473 bool isSuitableFor(Backend backend) override { 470 bool isSuitableFor(Backend backend) override {
474 return backend == kNonRendering_Backend; 471 return backend == kNonRendering_Backend;
475 } 472 }
476 473
477 // just so the compiler doesn't remove our loops 474 // just so the compiler doesn't remove our loops
478 virtual void process(int) {} 475 virtual void process(int) {}
479 476
480 protected: 477 protected:
481 virtual void onDraw(const int loops, SkCanvas*) { 478 void onDraw(const int loops, SkCanvas*) override {
482 int accum = 0; 479 int accum = 0;
483 480
484 for (int j = 0; j < loops; ++j) { 481 for (int j = 0; j < loops; ++j) {
485 for (int i = 0; i < ARRAY; ++i) { 482 for (int i = 0; i < ARRAY; ++i) {
486 accum += fVec[i].normalize(); 483 accum += fVec[i].normalize();
487 } 484 }
488 this->process(accum); 485 this->process(accum);
489 } 486 }
490 } 487 }
491 488
492 virtual const char* onGetName() { 489 const char* onGetName() override {
493 return fName; 490 return fName;
494 } 491 }
495 492
496 private: 493 private:
497 const char* fName; 494 const char* fName;
498 495
499 typedef Benchmark INHERITED; 496 typedef Benchmark INHERITED;
500 }; 497 };
501 498
502 /////////////////////////////////////////////////////////////////////////////// 499 ///////////////////////////////////////////////////////////////////////////////
(...skipping 12 matching lines...) Expand all
515 fData[i] = rand.nextSScalar1(); 512 fData[i] = rand.nextSScalar1();
516 } 513 }
517 514
518 } 515 }
519 516
520 bool isSuitableFor(Backend backend) override { 517 bool isSuitableFor(Backend backend) override {
521 return backend == kNonRendering_Backend; 518 return backend == kNonRendering_Backend;
522 } 519 }
523 520
524 protected: 521 protected:
525 virtual void onDraw(const int loops, SkCanvas*) { 522 void onDraw(const int loops, SkCanvas*) override {
526 for (int j = 0; j < loops; ++j) { 523 for (int j = 0; j < loops; ++j) {
527 for (int i = 0; i < N - 4; ++i) { 524 for (int i = 0; i < N - 4; ++i) {
528 fResult[i] = SkFloatToFixed(fData[i]); 525 fResult[i] = SkFloatToFixed(fData[i]);
529 } 526 }
530 } 527 }
531 528
532 SkPaint paint; 529 SkPaint paint;
533 if (paint.getAlpha() == 0) { 530 if (paint.getAlpha() == 0) {
534 SkDebugf("%d\n", fResult[0]); 531 SkDebugf("%d\n", fResult[0]);
535 } 532 }
536 } 533 }
537 534
538 virtual const char* onGetName() { 535 const char* onGetName() override {
539 return "float_to_fixed"; 536 return "float_to_fixed";
540 } 537 }
541 538
542 private: 539 private:
543 typedef Benchmark INHERITED; 540 typedef Benchmark INHERITED;
544 }; 541 };
545 542
546 /////////////////////////////////////////////////////////////////////////////// 543 ///////////////////////////////////////////////////////////////////////////////
547 544
548 template <typename T> 545 template <typename T>
549 class DivModBench : public Benchmark { 546 class DivModBench : public Benchmark {
550 SkString fName; 547 SkString fName;
551 public: 548 public:
552 explicit DivModBench(const char* name) { 549 explicit DivModBench(const char* name) {
553 fName.printf("divmod_%s", name); 550 fName.printf("divmod_%s", name);
554 } 551 }
555 552
556 bool isSuitableFor(Backend backend) override { 553 bool isSuitableFor(Backend backend) override {
557 return backend == kNonRendering_Backend; 554 return backend == kNonRendering_Backend;
558 } 555 }
559 556
560 protected: 557 protected:
561 virtual const char* onGetName() { 558 const char* onGetName() override {
562 return fName.c_str(); 559 return fName.c_str();
563 } 560 }
564 561
565 virtual void onDraw(const int loops, SkCanvas*) { 562 void onDraw(const int loops, SkCanvas*) override {
566 volatile T a = 0, b = 0; 563 volatile T a = 0, b = 0;
567 T div = 0, mod = 0; 564 T div = 0, mod = 0;
568 for (int i = 0; i < loops; i++) { 565 for (int i = 0; i < loops; i++) {
569 if ((T)i == 0) continue; // Small T will wrap around. 566 if ((T)i == 0) continue; // Small T will wrap around.
570 SkTDivMod((T)(i+1), (T)i, &div, &mod); 567 SkTDivMod((T)(i+1), (T)i, &div, &mod);
571 a ^= div; 568 a ^= div;
572 b ^= mod; 569 b ^= mod;
573 } 570 }
574 } 571 }
575 }; 572 };
(...skipping 26 matching lines...) Expand all
602 599
603 DEF_BENCH( return new FloorBench(false); ) 600 DEF_BENCH( return new FloorBench(false); )
604 DEF_BENCH( return new FloorBench(true); ) 601 DEF_BENCH( return new FloorBench(true); )
605 602
606 DEF_BENCH( return new CLZBench(false); ) 603 DEF_BENCH( return new CLZBench(false); )
607 DEF_BENCH( return new CLZBench(true); ) 604 DEF_BENCH( return new CLZBench(true); )
608 605
609 DEF_BENCH( return new NormalizeBench(); ) 606 DEF_BENCH( return new NormalizeBench(); )
610 607
611 DEF_BENCH( return new FixedMathBench(); ) 608 DEF_BENCH( return new FixedMathBench(); )
OLDNEW
« no previous file with comments | « bench/InterpBench.cpp ('k') | bench/Matrix44Bench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698