blob: c34be44303c3fe0609eb11bd4c7565ccaa95b801 [file] [log] [blame]
reed@google.comddc518b2011-08-29 17:49:23 +00001#include "SkBenchmark.h"
reed@google.come05cc8e2011-10-10 14:19:40 +00002#include "SkColorPriv.h"
reed@google.comddc518b2011-08-29 17:49:23 +00003#include "SkMatrix.h"
4#include "SkRandom.h"
5#include "SkString.h"
reed@google.com16078632011-12-06 18:56:37 +00006#include "SkPaint.h"
reed@google.comddc518b2011-08-29 17:49:23 +00007
reed@google.com7f192412012-05-30 12:26:52 +00008static float sk_fsel(float pred, float result_ge, float result_lt) {
9 return pred >= 0 ? result_ge : result_lt;
10}
11
12static float fast_floor(float x) {
reed@google.comf3a8d8e2012-05-30 14:08:57 +000013// float big = sk_fsel(x, 0x1.0p+23, -0x1.0p+23);
14 float big = sk_fsel(x, (float)(1 << 23), -(float)(1 << 23));
reed@google.com7f192412012-05-30 12:26:52 +000015 return (x + big) - big;
16}
17
reed@google.comddc518b2011-08-29 17:49:23 +000018class MathBench : public SkBenchmark {
19 enum {
20 kBuffer = 100,
reed@google.comddc518b2011-08-29 17:49:23 +000021 };
22 SkString fName;
23 float fSrc[kBuffer], fDst[kBuffer];
24public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000025 MathBench(const char name[]) {
reed@google.comddc518b2011-08-29 17:49:23 +000026 fName.printf("math_%s", name);
27
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000028 SkRandom rand;
reed@google.comddc518b2011-08-29 17:49:23 +000029 for (int i = 0; i < kBuffer; ++i) {
30 fSrc[i] = rand.nextSScalar1();
31 }
tomhudson@google.com9dc27132012-09-13 15:50:24 +000032
33 fIsRendering = false;
reed@google.comddc518b2011-08-29 17:49:23 +000034 }
35
rmistry@google.comfbfcd562012-08-23 18:09:54 +000036 virtual void performTest(float* SK_RESTRICT dst,
37 const float* SK_RESTRICT src,
robertphillips@google.com6853e802012-04-16 15:50:18 +000038 int count) = 0;
reed@google.comddc518b2011-08-29 17:49:23 +000039
40protected:
41 virtual int mulLoopCount() const { return 1; }
42
43 virtual const char* onGetName() {
44 return fName.c_str();
45 }
46
sugoi@google.com77472f02013-03-05 18:50:01 +000047 virtual void onDraw(SkCanvas*) {
mtklein@google.comc2897432013-09-10 19:23:38 +000048 int n = this->getLoops() * this->mulLoopCount();
reed@google.comddc518b2011-08-29 17:49:23 +000049 for (int i = 0; i < n; i++) {
50 this->performTest(fDst, fSrc, kBuffer);
51 }
52 }
53
54private:
55 typedef SkBenchmark INHERITED;
56};
57
reed@google.come05cc8e2011-10-10 14:19:40 +000058class MathBenchU32 : public MathBench {
59public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000060 MathBenchU32(const char name[]) : INHERITED(name) {}
skia.committer@gmail.com81521132013-04-30 07:01:03 +000061
reed@google.come05cc8e2011-10-10 14:19:40 +000062protected:
rmistry@google.comfbfcd562012-08-23 18:09:54 +000063 virtual void performITest(uint32_t* SK_RESTRICT dst,
64 const uint32_t* SK_RESTRICT src,
robertphillips@google.com6853e802012-04-16 15:50:18 +000065 int count) = 0;
skia.committer@gmail.com81521132013-04-30 07:01:03 +000066
rmistry@google.comfbfcd562012-08-23 18:09:54 +000067 virtual void performTest(float* SK_RESTRICT dst,
reed@google.com0d7aac92013-04-29 13:55:11 +000068 const float* SK_RESTRICT src,
69 int count) SK_OVERRIDE {
reed@google.come05cc8e2011-10-10 14:19:40 +000070 uint32_t* d = SkTCast<uint32_t*>(dst);
71 const uint32_t* s = SkTCast<const uint32_t*>(src);
72 this->performITest(d, s, count);
73 }
74private:
75 typedef MathBench INHERITED;
76};
77
78///////////////////////////////////////////////////////////////////////////////
reed@google.comddc518b2011-08-29 17:49:23 +000079
80class NoOpMathBench : public MathBench {
81public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000082 NoOpMathBench() : INHERITED("noOp") {}
reed@google.comddc518b2011-08-29 17:49:23 +000083protected:
rmistry@google.comfbfcd562012-08-23 18:09:54 +000084 virtual void performTest(float* SK_RESTRICT dst,
85 const float* SK_RESTRICT src,
robertphillips@google.com6853e802012-04-16 15:50:18 +000086 int count) {
reed@google.comddc518b2011-08-29 17:49:23 +000087 for (int i = 0; i < count; ++i) {
88 dst[i] = src[i] + 1;
89 }
90 }
91private:
92 typedef MathBench INHERITED;
93};
94
robertphillips@google.com36bb2702013-08-12 12:02:28 +000095class SlowISqrtMathBench : public MathBench {
reed@google.comddc518b2011-08-29 17:49:23 +000096public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000097 SlowISqrtMathBench() : INHERITED("slowIsqrt") {}
commit-bot@chromium.orgb3ecdc42013-08-12 08:37:51 +000098protected:
robertphillips@google.com36bb2702013-08-12 12:02:28 +000099 virtual void performTest(float* SK_RESTRICT dst,
100 const float* SK_RESTRICT src,
101 int count) {
102 for (int i = 0; i < count; ++i) {
103 dst[i] = 1.0f / sk_float_sqrt(src[i]);
commit-bot@chromium.orgb3ecdc42013-08-12 08:37:51 +0000104 }
commit-bot@chromium.orgb3ecdc42013-08-12 08:37:51 +0000105 }
reed@google.comddc518b2011-08-29 17:49:23 +0000106private:
robertphillips@google.com36bb2702013-08-12 12:02:28 +0000107 typedef MathBench INHERITED;
108};
109
110static inline float SkFastInvSqrt(float x) {
111 float xhalf = 0.5f*x;
112 int i = *SkTCast<int*>(&x);
113 i = 0x5f3759df - (i>>1);
114 x = *SkTCast<float*>(&i);
115 x = x*(1.5f-xhalf*x*x);
116// x = x*(1.5f-xhalf*x*x); // this line takes err from 10^-3 to 10^-6
117 return x;
118}
119
120class FastISqrtMathBench : public MathBench {
121public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000122 FastISqrtMathBench() : INHERITED("fastIsqrt") {}
robertphillips@google.com36bb2702013-08-12 12:02:28 +0000123protected:
124 virtual void performTest(float* SK_RESTRICT dst,
125 const float* SK_RESTRICT src,
126 int count) {
127 for (int i = 0; i < count; ++i) {
128 dst[i] = SkFastInvSqrt(src[i]);
129 }
130 }
131private:
132 typedef MathBench INHERITED;
reed@google.comddc518b2011-08-29 17:49:23 +0000133};
134
reed@google.come05cc8e2011-10-10 14:19:40 +0000135static inline uint32_t QMul64(uint32_t value, U8CPU alpha) {
136 SkASSERT((uint8_t)alpha == alpha);
137 const uint32_t mask = 0xFF00FF;
138
139 uint64_t tmp = value;
140 tmp = (tmp & mask) | ((tmp & ~mask) << 24);
141 tmp *= alpha;
caryclark@google.com19069a22012-06-06 12:11:45 +0000142 return (uint32_t) (((tmp >> 8) & mask) | ((tmp >> 32) & ~mask));
reed@google.come05cc8e2011-10-10 14:19:40 +0000143}
144
145class QMul64Bench : public MathBenchU32 {
146public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000147 QMul64Bench() : INHERITED("qmul64") {}
reed@google.come05cc8e2011-10-10 14:19:40 +0000148protected:
149 virtual void performITest(uint32_t* SK_RESTRICT dst,
150 const uint32_t* SK_RESTRICT src,
151 int count) SK_OVERRIDE {
152 for (int i = 0; i < count; ++i) {
153 dst[i] = QMul64(src[i], (uint8_t)i);
154 }
155 }
156private:
157 typedef MathBenchU32 INHERITED;
158};
159
160class QMul32Bench : public MathBenchU32 {
161public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000162 QMul32Bench() : INHERITED("qmul32") {}
reed@google.come05cc8e2011-10-10 14:19:40 +0000163protected:
164 virtual void performITest(uint32_t* SK_RESTRICT dst,
165 const uint32_t* SK_RESTRICT src,
166 int count) SK_OVERRIDE {
167 for (int i = 0; i < count; ++i) {
168 dst[i] = SkAlphaMulQ(src[i], (uint8_t)i);
169 }
170 }
171private:
172 typedef MathBenchU32 INHERITED;
173};
174
reed@google.comddc518b2011-08-29 17:49:23 +0000175///////////////////////////////////////////////////////////////////////////////
176
reed@google.com0be5eb72011-12-05 21:53:22 +0000177static bool isFinite_int(float x) {
178 uint32_t bits = SkFloat2Bits(x); // need unsigned for our shifts
179 int exponent = bits << 1 >> 24;
180 return exponent != 0xFF;
181}
182
183static bool isFinite_float(float x) {
robertphillips@google.com6853e802012-04-16 15:50:18 +0000184 return SkToBool(sk_float_isfinite(x));
reed@google.com0be5eb72011-12-05 21:53:22 +0000185}
186
187static bool isFinite_mulzero(float x) {
188 float y = x * 0;
189 return y == y;
190}
191
192static bool isfinite_and_int(const float data[4]) {
193 return isFinite_int(data[0]) && isFinite_int(data[1]) && isFinite_int(data[2]) && isFinite_int(data[3]);
194}
195
196static bool isfinite_and_float(const float data[4]) {
197 return isFinite_float(data[0]) && isFinite_float(data[1]) && isFinite_float(data[2]) && isFinite_float(data[3]);
198}
199
200static bool isfinite_and_mulzero(const float data[4]) {
201 return isFinite_mulzero(data[0]) && isFinite_mulzero(data[1]) && isFinite_mulzero(data[2]) && isFinite_mulzero(data[3]);
202}
203
204#define mulzeroadd(data) (data[0]*0 + data[1]*0 + data[2]*0 + data[3]*0)
205
206static bool isfinite_plus_int(const float data[4]) {
207 return isFinite_int(mulzeroadd(data));
208}
209
210static bool isfinite_plus_float(const float data[4]) {
reed@google.com5ae777d2011-12-06 20:18:05 +0000211 return !sk_float_isnan(mulzeroadd(data));
reed@google.com0be5eb72011-12-05 21:53:22 +0000212}
213
214static bool isfinite_plus_mulzero(const float data[4]) {
215 float x = mulzeroadd(data);
216 return x == x;
217}
218
219typedef bool (*IsFiniteProc)(const float[]);
220
221#define MAKEREC(name) { name, #name }
222
223static const struct {
224 IsFiniteProc fProc;
225 const char* fName;
226} gRec[] = {
227 MAKEREC(isfinite_and_int),
228 MAKEREC(isfinite_and_float),
229 MAKEREC(isfinite_and_mulzero),
230 MAKEREC(isfinite_plus_int),
231 MAKEREC(isfinite_plus_float),
232 MAKEREC(isfinite_plus_mulzero),
233};
234
235#undef MAKEREC
236
reed@google.com16078632011-12-06 18:56:37 +0000237static bool isFinite(const SkRect& r) {
238 // x * 0 will be NaN iff x is infinity or NaN.
239 // a + b will be NaN iff either a or b is NaN.
240 float value = r.fLeft * 0 + r.fTop * 0 + r.fRight * 0 + r.fBottom * 0;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000241
reed@google.com16078632011-12-06 18:56:37 +0000242 // value is either NaN or it is finite (zero).
243 // value==value will be true iff value is not NaN
244 return value == value;
245}
246
reed@google.com0be5eb72011-12-05 21:53:22 +0000247class IsFiniteBench : public SkBenchmark {
248 enum {
mtklein@google.comc2897432013-09-10 19:23:38 +0000249 N = 1000,
reed@google.com0be5eb72011-12-05 21:53:22 +0000250 };
251 float fData[N];
252public:
253
mtklein@google.com410e6e82013-09-13 19:52:27 +0000254 IsFiniteBench(int index) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000255 SkRandom rand;
reed@google.com0be5eb72011-12-05 21:53:22 +0000256
257 for (int i = 0; i < N; ++i) {
258 fData[i] = rand.nextSScalar1();
259 }
reed@google.com16078632011-12-06 18:56:37 +0000260
261 if (index < 0) {
262 fProc = NULL;
263 fName = "isfinite_rect";
264 } else {
265 fProc = gRec[index].fProc;
266 fName = gRec[index].fName;
267 }
tomhudson@google.com9dc27132012-09-13 15:50:24 +0000268 fIsRendering = false;
reed@google.com0be5eb72011-12-05 21:53:22 +0000269 }
270
271protected:
sugoi@google.com77472f02013-03-05 18:50:01 +0000272 virtual void onDraw(SkCanvas*) {
reed@google.com0be5eb72011-12-05 21:53:22 +0000273 IsFiniteProc proc = fProc;
274 const float* data = fData;
reed@google.com16078632011-12-06 18:56:37 +0000275 // do this so the compiler won't throw away the function call
276 int counter = 0;
reed@google.com0be5eb72011-12-05 21:53:22 +0000277
reed@google.com16078632011-12-06 18:56:37 +0000278 if (proc) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000279 for (int j = 0; j < this->getLoops(); ++j) {
reed@google.com16078632011-12-06 18:56:37 +0000280 for (int i = 0; i < N - 4; ++i) {
281 counter += proc(&data[i]);
282 }
reed@google.com0be5eb72011-12-05 21:53:22 +0000283 }
reed@google.com16078632011-12-06 18:56:37 +0000284 } else {
mtklein@google.comc2897432013-09-10 19:23:38 +0000285 for (int j = 0; j < this->getLoops(); ++j) {
reed@google.com16078632011-12-06 18:56:37 +0000286 for (int i = 0; i < N - 4; ++i) {
287 const SkRect* r = reinterpret_cast<const SkRect*>(&data[i]);
caryclark@google.com19069a22012-06-06 12:11:45 +0000288 if (false) { // avoid bit rot, suppress warning
289 isFinite(*r);
290 }
reed@google.com16078632011-12-06 18:56:37 +0000291 counter += r->isFinite();
292 }
293 }
294 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000295
reed@google.com16078632011-12-06 18:56:37 +0000296 SkPaint paint;
297 if (paint.getAlpha() == 0) {
298 SkDebugf("%d\n", counter);
reed@google.com0be5eb72011-12-05 21:53:22 +0000299 }
300 }
301
302 virtual const char* onGetName() {
303 return fName;
304 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000305
reed@google.com0be5eb72011-12-05 21:53:22 +0000306private:
307 IsFiniteProc fProc;
308 const char* fName;
309
310 typedef SkBenchmark INHERITED;
311};
312
reed@google.com7f192412012-05-30 12:26:52 +0000313class FloorBench : public SkBenchmark {
314 enum {
mtklein@google.comc2897432013-09-10 19:23:38 +0000315 ARRAY = 1000,
reed@google.com7f192412012-05-30 12:26:52 +0000316 };
317 float fData[ARRAY];
318 bool fFast;
319public:
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000320
mtklein@google.com410e6e82013-09-13 19:52:27 +0000321 FloorBench(bool fast) : fFast(fast) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000322 SkRandom rand;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000323
reed@google.com7f192412012-05-30 12:26:52 +0000324 for (int i = 0; i < ARRAY; ++i) {
325 fData[i] = rand.nextSScalar1();
326 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000327
reed@google.com7f192412012-05-30 12:26:52 +0000328 if (fast) {
329 fName = "floor_fast";
330 } else {
331 fName = "floor_std";
332 }
tomhudson@google.com9dc27132012-09-13 15:50:24 +0000333 fIsRendering = false;
reed@google.com7f192412012-05-30 12:26:52 +0000334 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000335
reed@google.com7f192412012-05-30 12:26:52 +0000336 virtual void process(float) {}
337
338protected:
sugoi@google.com77472f02013-03-05 18:50:01 +0000339 virtual void onDraw(SkCanvas*) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000340 SkRandom rand;
reed@google.com7f192412012-05-30 12:26:52 +0000341 float accum = 0;
342 const float* data = fData;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000343
reed@google.com7f192412012-05-30 12:26:52 +0000344 if (fFast) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000345 for (int j = 0; j < this->getLoops(); ++j) {
reed@google.com7f192412012-05-30 12:26:52 +0000346 for (int i = 0; i < ARRAY; ++i) {
347 accum += fast_floor(data[i]);
348 }
349 this->process(accum);
350 }
351 } else {
mtklein@google.comc2897432013-09-10 19:23:38 +0000352 for (int j = 0; j < this->getLoops(); ++j) {
reed@google.com7f192412012-05-30 12:26:52 +0000353 for (int i = 0; i < ARRAY; ++i) {
354 accum += sk_float_floor(data[i]);
355 }
356 this->process(accum);
357 }
358 }
359 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000360
reed@google.com7f192412012-05-30 12:26:52 +0000361 virtual const char* onGetName() {
362 return fName;
363 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000364
reed@google.com7f192412012-05-30 12:26:52 +0000365private:
366 const char* fName;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000367
reed@google.com7f192412012-05-30 12:26:52 +0000368 typedef SkBenchmark INHERITED;
369};
370
reed@google.com0d7aac92013-04-29 13:55:11 +0000371class CLZBench : public SkBenchmark {
372 enum {
mtklein@google.comc2897432013-09-10 19:23:38 +0000373 ARRAY = 1000,
reed@google.com0d7aac92013-04-29 13:55:11 +0000374 };
375 uint32_t fData[ARRAY];
376 bool fUsePortable;
377
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000378public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000379 CLZBench(bool usePortable) : fUsePortable(usePortable) {
reed@google.com0d7aac92013-04-29 13:55:11 +0000380
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000381 SkRandom rand;
reed@google.com0d7aac92013-04-29 13:55:11 +0000382 for (int i = 0; i < ARRAY; ++i) {
383 fData[i] = rand.nextU();
384 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000385
reed@google.com0d7aac92013-04-29 13:55:11 +0000386 if (fUsePortable) {
387 fName = "clz_portable";
388 } else {
389 fName = "clz_intrinsic";
390 }
391 fIsRendering = false;
392 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000393
reed@google.com0d7aac92013-04-29 13:55:11 +0000394 // just so the compiler doesn't remove our loops
395 virtual void process(int) {}
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000396
reed@google.com0d7aac92013-04-29 13:55:11 +0000397protected:
398 virtual void onDraw(SkCanvas*) {
399 int accum = 0;
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000400
reed@google.com0d7aac92013-04-29 13:55:11 +0000401 if (fUsePortable) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000402 for (int j = 0; j < this->getLoops(); ++j) {
reed@google.com0d7aac92013-04-29 13:55:11 +0000403 for (int i = 0; i < ARRAY; ++i) {
404 accum += SkCLZ_portable(fData[i]);
405 }
406 this->process(accum);
407 }
408 } else {
mtklein@google.comc2897432013-09-10 19:23:38 +0000409 for (int j = 0; j < this->getLoops(); ++j) {
reed@google.com0d7aac92013-04-29 13:55:11 +0000410 for (int i = 0; i < ARRAY; ++i) {
411 accum += SkCLZ(fData[i]);
412 }
413 this->process(accum);
414 }
415 }
416 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000417
reed@google.com0d7aac92013-04-29 13:55:11 +0000418 virtual const char* onGetName() {
419 return fName;
420 }
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000421
reed@google.com0d7aac92013-04-29 13:55:11 +0000422private:
423 const char* fName;
skia.committer@gmail.com81521132013-04-30 07:01:03 +0000424
reed@google.com0d7aac92013-04-29 13:55:11 +0000425 typedef SkBenchmark INHERITED;
426};
427
reed@google.com0be5eb72011-12-05 21:53:22 +0000428///////////////////////////////////////////////////////////////////////////////
429
reed@google.com0889f682013-05-03 12:56:39 +0000430class NormalizeBench : public SkBenchmark {
431 enum {
mtklein@google.comc2897432013-09-10 19:23:38 +0000432 ARRAY =1000,
reed@google.com0889f682013-05-03 12:56:39 +0000433 };
434 SkVector fVec[ARRAY];
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +0000435
reed@google.com0889f682013-05-03 12:56:39 +0000436public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000437 NormalizeBench() {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000438 SkRandom rand;
reed@google.com0889f682013-05-03 12:56:39 +0000439 for (int i = 0; i < ARRAY; ++i) {
440 fVec[i].set(rand.nextSScalar1(), rand.nextSScalar1());
441 }
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +0000442
reed@google.com0889f682013-05-03 12:56:39 +0000443 fName = "point_normalize";
444 fIsRendering = false;
445 }
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +0000446
reed@google.com0889f682013-05-03 12:56:39 +0000447 // just so the compiler doesn't remove our loops
448 virtual void process(int) {}
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +0000449
reed@google.com0889f682013-05-03 12:56:39 +0000450protected:
451 virtual void onDraw(SkCanvas*) {
452 int accum = 0;
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +0000453
mtklein@google.comc2897432013-09-10 19:23:38 +0000454 for (int j = 0; j < this->getLoops(); ++j) {
reed@google.com0889f682013-05-03 12:56:39 +0000455 for (int i = 0; i < ARRAY; ++i) {
456 accum += fVec[i].normalize();
457 }
458 this->process(accum);
459 }
460 }
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +0000461
reed@google.com0889f682013-05-03 12:56:39 +0000462 virtual const char* onGetName() {
463 return fName;
464 }
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +0000465
reed@google.com0889f682013-05-03 12:56:39 +0000466private:
467 const char* fName;
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +0000468
reed@google.com0889f682013-05-03 12:56:39 +0000469 typedef SkBenchmark INHERITED;
470};
471
472///////////////////////////////////////////////////////////////////////////////
473
djsollen@google.com25a11e42013-07-18 19:11:30 +0000474class FixedMathBench : public SkBenchmark {
475 enum {
mtklein@google.comc2897432013-09-10 19:23:38 +0000476 N = 1000,
djsollen@google.com25a11e42013-07-18 19:11:30 +0000477 };
478 float fData[N];
479 SkFixed fResult[N];
480public:
481
mtklein@google.com410e6e82013-09-13 19:52:27 +0000482 FixedMathBench() {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000483 SkRandom rand;
mtklein@google.comc2897432013-09-10 19:23:38 +0000484 for (int i = 0; i < this->getLoops(); ++i) {
485 fData[i%N] = rand.nextSScalar1();
djsollen@google.com25a11e42013-07-18 19:11:30 +0000486 }
487
488 fIsRendering = false;
489 }
490
491protected:
492 virtual void onDraw(SkCanvas*) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000493 for (int j = 0; j < this->getLoops(); ++j) {
djsollen@google.com25a11e42013-07-18 19:11:30 +0000494 for (int i = 0; i < N - 4; ++i) {
495 fResult[i] = SkFloatToFixed(fData[i]);
496 }
497 }
498
499 SkPaint paint;
500 if (paint.getAlpha() == 0) {
501 SkDebugf("%d\n", fResult[0]);
502 }
503 }
504
505 virtual const char* onGetName() {
506 return "float_to_fixed";
507 }
508
509private:
510 typedef SkBenchmark INHERITED;
511};
512
513///////////////////////////////////////////////////////////////////////////////
514
mtklein@google.com410e6e82013-09-13 19:52:27 +0000515DEF_BENCH( return new NoOpMathBench(); )
516DEF_BENCH( return new SlowISqrtMathBench(); )
517DEF_BENCH( return new FastISqrtMathBench(); )
518DEF_BENCH( return new QMul64Bench(); )
519DEF_BENCH( return new QMul32Bench(); )
reed@google.comddc518b2011-08-29 17:49:23 +0000520
mtklein@google.com410e6e82013-09-13 19:52:27 +0000521DEF_BENCH( return new IsFiniteBench(-1); )
522DEF_BENCH( return new IsFiniteBench(0); )
523DEF_BENCH( return new IsFiniteBench(1); )
524DEF_BENCH( return new IsFiniteBench(2); )
525DEF_BENCH( return new IsFiniteBench(3); )
526DEF_BENCH( return new IsFiniteBench(4); )
527DEF_BENCH( return new IsFiniteBench(5); )
reed@google.com0be5eb72011-12-05 21:53:22 +0000528
mtklein@google.com410e6e82013-09-13 19:52:27 +0000529DEF_BENCH( return new FloorBench(false); )
530DEF_BENCH( return new FloorBench(true); )
reed@google.com7f192412012-05-30 12:26:52 +0000531
mtklein@google.com410e6e82013-09-13 19:52:27 +0000532DEF_BENCH( return new CLZBench(false); )
533DEF_BENCH( return new CLZBench(true); )
reed@google.com0889f682013-05-03 12:56:39 +0000534
mtklein@google.com410e6e82013-09-13 19:52:27 +0000535DEF_BENCH( return new NormalizeBench(); )
djsollen@google.com25a11e42013-07-18 19:11:30 +0000536
mtklein@google.com410e6e82013-09-13 19:52:27 +0000537DEF_BENCH( return new FixedMathBench(); )