mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/Benchmark.h" |
| 9 | #include "include/core/SkMatrix.h" |
| 10 | #include "include/core/SkPaint.h" |
| 11 | #include "include/core/SkString.h" |
| 12 | #include "include/private/SkColorData.h" |
| 13 | #include "include/private/SkFixed.h" |
| 14 | #include "include/utils/SkRandom.h" |
| 15 | #include "src/core/SkMathPriv.h" |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 16 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 17 | static float sk_fsel(float pred, float result_ge, float result_lt) { |
| 18 | return pred >= 0 ? result_ge : result_lt; |
| 19 | } |
| 20 | |
| 21 | static float fast_floor(float x) { |
reed@google.com | f3a8d8e | 2012-05-30 14:08:57 +0000 | [diff] [blame] | 22 | // float big = sk_fsel(x, 0x1.0p+23, -0x1.0p+23); |
| 23 | float big = sk_fsel(x, (float)(1 << 23), -(float)(1 << 23)); |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 24 | return (x + big) - big; |
| 25 | } |
| 26 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 27 | class MathBench : public Benchmark { |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 28 | enum { |
| 29 | kBuffer = 100, |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 30 | }; |
| 31 | SkString fName; |
| 32 | float fSrc[kBuffer], fDst[kBuffer]; |
| 33 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 34 | MathBench(const char name[]) { |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 35 | fName.printf("math_%s", name); |
| 36 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 37 | SkRandom rand; |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 38 | for (int i = 0; i < kBuffer; ++i) { |
| 39 | fSrc[i] = rand.nextSScalar1(); |
| 40 | } |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 41 | } |
tomhudson@google.com | 9dc2713 | 2012-09-13 15:50:24 +0000 | [diff] [blame] | 42 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 43 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 44 | return backend == kNonRendering_Backend; |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 45 | } |
| 46 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 47 | virtual void performTest(float* SK_RESTRICT dst, |
| 48 | const float* SK_RESTRICT src, |
robertphillips@google.com | 6853e80 | 2012-04-16 15:50:18 +0000 | [diff] [blame] | 49 | int count) = 0; |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 50 | |
| 51 | protected: |
| 52 | virtual int mulLoopCount() const { return 1; } |
| 53 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 54 | const char* onGetName() override { |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 55 | return fName.c_str(); |
| 56 | } |
| 57 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 58 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 59 | int n = loops * this->mulLoopCount(); |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 60 | for (int i = 0; i < n; i++) { |
| 61 | this->performTest(fDst, fSrc, kBuffer); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 66 | typedef Benchmark INHERITED; |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 69 | class MathBenchU32 : public MathBench { |
| 70 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 71 | MathBenchU32(const char name[]) : INHERITED(name) {} |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 72 | |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 73 | protected: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 74 | virtual void performITest(uint32_t* SK_RESTRICT dst, |
| 75 | const uint32_t* SK_RESTRICT src, |
robertphillips@google.com | 6853e80 | 2012-04-16 15:50:18 +0000 | [diff] [blame] | 76 | int count) = 0; |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 77 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 78 | void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override { |
Mike Klein | e72e773 | 2018-06-14 14:41:22 -0400 | [diff] [blame] | 79 | uint32_t* d = reinterpret_cast<uint32_t*>(dst); |
| 80 | const uint32_t* s = reinterpret_cast<const uint32_t*>(src); |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 81 | this->performITest(d, s, count); |
| 82 | } |
| 83 | private: |
| 84 | typedef MathBench INHERITED; |
| 85 | }; |
| 86 | |
| 87 | /////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 88 | |
| 89 | class NoOpMathBench : public MathBench { |
| 90 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 91 | NoOpMathBench() : INHERITED("noOp") {} |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 92 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 93 | void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override { |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 94 | for (int i = 0; i < count; ++i) { |
| 95 | dst[i] = src[i] + 1; |
| 96 | } |
| 97 | } |
| 98 | private: |
| 99 | typedef MathBench INHERITED; |
| 100 | }; |
| 101 | |
commit-bot@chromium.org | 11e5b97 | 2013-11-08 20:14:16 +0000 | [diff] [blame] | 102 | class SkRSqrtMathBench : public MathBench { |
| 103 | public: |
| 104 | SkRSqrtMathBench() : INHERITED("sk_float_rsqrt") {} |
| 105 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 106 | void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override { |
commit-bot@chromium.org | 11e5b97 | 2013-11-08 20:14:16 +0000 | [diff] [blame] | 107 | for (int i = 0; i < count; ++i) { |
| 108 | dst[i] = sk_float_rsqrt(src[i]); |
| 109 | } |
| 110 | } |
| 111 | private: |
| 112 | typedef MathBench INHERITED; |
| 113 | }; |
| 114 | |
| 115 | |
robertphillips@google.com | 36bb270 | 2013-08-12 12:02:28 +0000 | [diff] [blame] | 116 | class SlowISqrtMathBench : public MathBench { |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 117 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 118 | SlowISqrtMathBench() : INHERITED("slowIsqrt") {} |
commit-bot@chromium.org | b3ecdc4 | 2013-08-12 08:37:51 +0000 | [diff] [blame] | 119 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 120 | void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override { |
robertphillips@google.com | 36bb270 | 2013-08-12 12:02:28 +0000 | [diff] [blame] | 121 | for (int i = 0; i < count; ++i) { |
| 122 | dst[i] = 1.0f / sk_float_sqrt(src[i]); |
commit-bot@chromium.org | b3ecdc4 | 2013-08-12 08:37:51 +0000 | [diff] [blame] | 123 | } |
commit-bot@chromium.org | b3ecdc4 | 2013-08-12 08:37:51 +0000 | [diff] [blame] | 124 | } |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 125 | private: |
robertphillips@google.com | 36bb270 | 2013-08-12 12:02:28 +0000 | [diff] [blame] | 126 | typedef MathBench INHERITED; |
| 127 | }; |
| 128 | |
robertphillips@google.com | 36bb270 | 2013-08-12 12:02:28 +0000 | [diff] [blame] | 129 | class FastISqrtMathBench : public MathBench { |
| 130 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 131 | FastISqrtMathBench() : INHERITED("fastIsqrt") {} |
robertphillips@google.com | 36bb270 | 2013-08-12 12:02:28 +0000 | [diff] [blame] | 132 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 133 | void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override { |
robertphillips@google.com | 36bb270 | 2013-08-12 12:02:28 +0000 | [diff] [blame] | 134 | for (int i = 0; i < count; ++i) { |
Mike Klein | 1e114f1 | 2016-09-29 11:15:15 -0400 | [diff] [blame] | 135 | dst[i] = sk_float_rsqrt(src[i]); |
robertphillips@google.com | 36bb270 | 2013-08-12 12:02:28 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | private: |
| 139 | typedef MathBench INHERITED; |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 142 | static inline uint32_t QMul64(uint32_t value, U8CPU alpha) { |
| 143 | SkASSERT((uint8_t)alpha == alpha); |
| 144 | const uint32_t mask = 0xFF00FF; |
| 145 | |
| 146 | uint64_t tmp = value; |
| 147 | tmp = (tmp & mask) | ((tmp & ~mask) << 24); |
| 148 | tmp *= alpha; |
caryclark@google.com | 19069a2 | 2012-06-06 12:11:45 +0000 | [diff] [blame] | 149 | return (uint32_t) (((tmp >> 8) & mask) | ((tmp >> 32) & ~mask)); |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | class QMul64Bench : public MathBenchU32 { |
| 153 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 154 | QMul64Bench() : INHERITED("qmul64") {} |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 155 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 156 | void performITest(uint32_t* SK_RESTRICT dst, |
| 157 | const uint32_t* SK_RESTRICT src, |
| 158 | int count) override { |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 159 | for (int i = 0; i < count; ++i) { |
| 160 | dst[i] = QMul64(src[i], (uint8_t)i); |
| 161 | } |
| 162 | } |
| 163 | private: |
| 164 | typedef MathBenchU32 INHERITED; |
| 165 | }; |
| 166 | |
| 167 | class QMul32Bench : public MathBenchU32 { |
| 168 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 169 | QMul32Bench() : INHERITED("qmul32") {} |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 170 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 171 | void performITest(uint32_t* SK_RESTRICT dst, |
| 172 | const uint32_t* SK_RESTRICT src, |
| 173 | int count) override { |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 174 | for (int i = 0; i < count; ++i) { |
| 175 | dst[i] = SkAlphaMulQ(src[i], (uint8_t)i); |
| 176 | } |
| 177 | } |
| 178 | private: |
| 179 | typedef MathBenchU32 INHERITED; |
| 180 | }; |
| 181 | |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 182 | /////////////////////////////////////////////////////////////////////////////// |
| 183 | |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 184 | static bool isFinite_int(float x) { |
| 185 | uint32_t bits = SkFloat2Bits(x); // need unsigned for our shifts |
| 186 | int exponent = bits << 1 >> 24; |
| 187 | return exponent != 0xFF; |
| 188 | } |
| 189 | |
| 190 | static bool isFinite_float(float x) { |
robertphillips@google.com | 6853e80 | 2012-04-16 15:50:18 +0000 | [diff] [blame] | 191 | return SkToBool(sk_float_isfinite(x)); |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static bool isFinite_mulzero(float x) { |
| 195 | float y = x * 0; |
| 196 | return y == y; |
| 197 | } |
| 198 | |
| 199 | static bool isfinite_and_int(const float data[4]) { |
| 200 | return isFinite_int(data[0]) && isFinite_int(data[1]) && isFinite_int(data[2]) && isFinite_int(data[3]); |
| 201 | } |
| 202 | |
| 203 | static bool isfinite_and_float(const float data[4]) { |
| 204 | return isFinite_float(data[0]) && isFinite_float(data[1]) && isFinite_float(data[2]) && isFinite_float(data[3]); |
| 205 | } |
| 206 | |
| 207 | static bool isfinite_and_mulzero(const float data[4]) { |
| 208 | return isFinite_mulzero(data[0]) && isFinite_mulzero(data[1]) && isFinite_mulzero(data[2]) && isFinite_mulzero(data[3]); |
| 209 | } |
| 210 | |
| 211 | #define mulzeroadd(data) (data[0]*0 + data[1]*0 + data[2]*0 + data[3]*0) |
| 212 | |
| 213 | static bool isfinite_plus_int(const float data[4]) { |
| 214 | return isFinite_int(mulzeroadd(data)); |
| 215 | } |
| 216 | |
| 217 | static bool isfinite_plus_float(const float data[4]) { |
reed@google.com | 5ae777d | 2011-12-06 20:18:05 +0000 | [diff] [blame] | 218 | return !sk_float_isnan(mulzeroadd(data)); |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static bool isfinite_plus_mulzero(const float data[4]) { |
| 222 | float x = mulzeroadd(data); |
| 223 | return x == x; |
| 224 | } |
| 225 | |
| 226 | typedef bool (*IsFiniteProc)(const float[]); |
| 227 | |
| 228 | #define MAKEREC(name) { name, #name } |
| 229 | |
| 230 | static const struct { |
| 231 | IsFiniteProc fProc; |
| 232 | const char* fName; |
| 233 | } gRec[] = { |
| 234 | MAKEREC(isfinite_and_int), |
| 235 | MAKEREC(isfinite_and_float), |
| 236 | MAKEREC(isfinite_and_mulzero), |
| 237 | MAKEREC(isfinite_plus_int), |
| 238 | MAKEREC(isfinite_plus_float), |
| 239 | MAKEREC(isfinite_plus_mulzero), |
| 240 | }; |
| 241 | |
| 242 | #undef MAKEREC |
| 243 | |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 244 | static bool isFinite(const SkRect& r) { |
| 245 | // x * 0 will be NaN iff x is infinity or NaN. |
| 246 | // a + b will be NaN iff either a or b is NaN. |
| 247 | float value = r.fLeft * 0 + r.fTop * 0 + r.fRight * 0 + r.fBottom * 0; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 248 | |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 249 | // value is either NaN or it is finite (zero). |
| 250 | // value==value will be true iff value is not NaN |
| 251 | return value == value; |
| 252 | } |
| 253 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 254 | class IsFiniteBench : public Benchmark { |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 255 | enum { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 256 | N = 1000, |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 257 | }; |
| 258 | float fData[N]; |
| 259 | public: |
| 260 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 261 | IsFiniteBench(int index) { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 262 | SkRandom rand; |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 263 | |
| 264 | for (int i = 0; i < N; ++i) { |
| 265 | fData[i] = rand.nextSScalar1(); |
| 266 | } |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 267 | |
| 268 | if (index < 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 269 | fProc = nullptr; |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 270 | fName = "isfinite_rect"; |
| 271 | } else { |
| 272 | fProc = gRec[index].fProc; |
| 273 | fName = gRec[index].fName; |
| 274 | } |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 275 | } |
| 276 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 277 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 278 | return backend == kNonRendering_Backend; |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | protected: |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 282 | void onDraw(int loops, SkCanvas*) override { |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 283 | IsFiniteProc proc = fProc; |
| 284 | const float* data = fData; |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 285 | // do this so the compiler won't throw away the function call |
| 286 | int counter = 0; |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 287 | |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 288 | if (proc) { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 289 | for (int j = 0; j < loops; ++j) { |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 290 | for (int i = 0; i < N - 4; ++i) { |
| 291 | counter += proc(&data[i]); |
| 292 | } |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 293 | } |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 294 | } else { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 295 | for (int j = 0; j < loops; ++j) { |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 296 | for (int i = 0; i < N - 4; ++i) { |
| 297 | const SkRect* r = reinterpret_cast<const SkRect*>(&data[i]); |
caryclark@google.com | 19069a2 | 2012-06-06 12:11:45 +0000 | [diff] [blame] | 298 | if (false) { // avoid bit rot, suppress warning |
| 299 | isFinite(*r); |
| 300 | } |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 301 | counter += r->isFinite(); |
| 302 | } |
| 303 | } |
| 304 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 305 | |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 306 | SkPaint paint; |
| 307 | if (paint.getAlpha() == 0) { |
| 308 | SkDebugf("%d\n", counter); |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 312 | const char* onGetName() override { |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 313 | return fName; |
| 314 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 315 | |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 316 | private: |
| 317 | IsFiniteProc fProc; |
| 318 | const char* fName; |
| 319 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 320 | typedef Benchmark INHERITED; |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 321 | }; |
| 322 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 323 | class FloorBench : public Benchmark { |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 324 | enum { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 325 | ARRAY = 1000, |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 326 | }; |
| 327 | float fData[ARRAY]; |
| 328 | bool fFast; |
| 329 | public: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 330 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 331 | FloorBench(bool fast) : fFast(fast) { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 332 | SkRandom rand; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 333 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 334 | for (int i = 0; i < ARRAY; ++i) { |
| 335 | fData[i] = rand.nextSScalar1(); |
| 336 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 337 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 338 | if (fast) { |
| 339 | fName = "floor_fast"; |
| 340 | } else { |
| 341 | fName = "floor_std"; |
| 342 | } |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 343 | } |
| 344 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 345 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 346 | return backend == kNonRendering_Backend; |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 347 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 348 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 349 | virtual void process(float) {} |
| 350 | |
| 351 | protected: |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 352 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 353 | SkRandom rand; |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 354 | float accum = 0; |
| 355 | const float* data = fData; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 356 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 357 | if (fFast) { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 358 | for (int j = 0; j < loops; ++j) { |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 359 | for (int i = 0; i < ARRAY; ++i) { |
| 360 | accum += fast_floor(data[i]); |
| 361 | } |
| 362 | this->process(accum); |
| 363 | } |
| 364 | } else { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 365 | for (int j = 0; j < loops; ++j) { |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 366 | for (int i = 0; i < ARRAY; ++i) { |
| 367 | accum += sk_float_floor(data[i]); |
| 368 | } |
| 369 | this->process(accum); |
| 370 | } |
| 371 | } |
| 372 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 373 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 374 | const char* onGetName() override { |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 375 | return fName; |
| 376 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 377 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 378 | private: |
| 379 | const char* fName; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 380 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 381 | typedef Benchmark INHERITED; |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 382 | }; |
| 383 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 384 | class CLZBench : public Benchmark { |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 385 | enum { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 386 | ARRAY = 1000, |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 387 | }; |
| 388 | uint32_t fData[ARRAY]; |
| 389 | bool fUsePortable; |
| 390 | |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 391 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 392 | CLZBench(bool usePortable) : fUsePortable(usePortable) { |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 393 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 394 | SkRandom rand; |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 395 | for (int i = 0; i < ARRAY; ++i) { |
| 396 | fData[i] = rand.nextU(); |
| 397 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 398 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 399 | if (fUsePortable) { |
| 400 | fName = "clz_portable"; |
| 401 | } else { |
| 402 | fName = "clz_intrinsic"; |
| 403 | } |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 404 | } |
| 405 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 406 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 407 | return backend == kNonRendering_Backend; |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 408 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 409 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 410 | // just so the compiler doesn't remove our loops |
| 411 | virtual void process(int) {} |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 412 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 413 | protected: |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 414 | void onDraw(int loops, SkCanvas*) override { |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 415 | int accum = 0; |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 416 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 417 | if (fUsePortable) { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 418 | for (int j = 0; j < loops; ++j) { |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 419 | for (int i = 0; i < ARRAY; ++i) { |
| 420 | accum += SkCLZ_portable(fData[i]); |
| 421 | } |
| 422 | this->process(accum); |
| 423 | } |
| 424 | } else { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 425 | for (int j = 0; j < loops; ++j) { |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 426 | for (int i = 0; i < ARRAY; ++i) { |
| 427 | accum += SkCLZ(fData[i]); |
| 428 | } |
| 429 | this->process(accum); |
| 430 | } |
| 431 | } |
| 432 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 433 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 434 | const char* onGetName() override { |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 435 | return fName; |
| 436 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 437 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 438 | private: |
| 439 | const char* fName; |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 440 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 441 | typedef Benchmark INHERITED; |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 442 | }; |
| 443 | |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 444 | /////////////////////////////////////////////////////////////////////////////// |
| 445 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 446 | class NormalizeBench : public Benchmark { |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 447 | enum { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 448 | ARRAY =1000, |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 449 | }; |
| 450 | SkVector fVec[ARRAY]; |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 451 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 452 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 453 | NormalizeBench() { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 454 | SkRandom rand; |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 455 | for (int i = 0; i < ARRAY; ++i) { |
| 456 | fVec[i].set(rand.nextSScalar1(), rand.nextSScalar1()); |
| 457 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 458 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 459 | fName = "point_normalize"; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 460 | } |
| 461 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 462 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 463 | return backend == kNonRendering_Backend; |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 464 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 465 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 466 | // just so the compiler doesn't remove our loops |
| 467 | virtual void process(int) {} |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 468 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 469 | protected: |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 470 | void onDraw(int loops, SkCanvas*) override { |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 471 | int accum = 0; |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 472 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 473 | for (int j = 0; j < loops; ++j) { |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 474 | for (int i = 0; i < ARRAY; ++i) { |
| 475 | accum += fVec[i].normalize(); |
| 476 | } |
| 477 | this->process(accum); |
| 478 | } |
| 479 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 480 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 481 | const char* onGetName() override { |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 482 | return fName; |
| 483 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 484 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 485 | private: |
| 486 | const char* fName; |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 487 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 488 | typedef Benchmark INHERITED; |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 489 | }; |
| 490 | |
| 491 | /////////////////////////////////////////////////////////////////////////////// |
| 492 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 493 | class FixedMathBench : public Benchmark { |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 494 | enum { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 495 | N = 1000, |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 496 | }; |
| 497 | float fData[N]; |
| 498 | SkFixed fResult[N]; |
| 499 | public: |
| 500 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 501 | FixedMathBench() { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 502 | SkRandom rand; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 503 | for (int i = 0; i < N; ++i) { |
| 504 | fData[i] = rand.nextSScalar1(); |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 505 | } |
| 506 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 507 | } |
| 508 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 509 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 510 | return backend == kNonRendering_Backend; |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | protected: |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 514 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 515 | for (int j = 0; j < loops; ++j) { |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 516 | for (int i = 0; i < N - 4; ++i) { |
| 517 | fResult[i] = SkFloatToFixed(fData[i]); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | SkPaint paint; |
| 522 | if (paint.getAlpha() == 0) { |
| 523 | SkDebugf("%d\n", fResult[0]); |
| 524 | } |
| 525 | } |
| 526 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 527 | const char* onGetName() override { |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 528 | return "float_to_fixed"; |
| 529 | } |
| 530 | |
| 531 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 532 | typedef Benchmark INHERITED; |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 533 | }; |
| 534 | |
| 535 | /////////////////////////////////////////////////////////////////////////////// |
| 536 | |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 537 | template <typename T> |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 538 | class DivModBench : public Benchmark { |
mtklein@google.com | 9cb5177 | 2013-09-27 13:39:14 +0000 | [diff] [blame] | 539 | SkString fName; |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 540 | public: |
mtklein@google.com | 9cb5177 | 2013-09-27 13:39:14 +0000 | [diff] [blame] | 541 | explicit DivModBench(const char* name) { |
| 542 | fName.printf("divmod_%s", name); |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 543 | } |
| 544 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 545 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 546 | return backend == kNonRendering_Backend; |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 550 | const char* onGetName() override { |
mtklein@google.com | 9cb5177 | 2013-09-27 13:39:14 +0000 | [diff] [blame] | 551 | return fName.c_str(); |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 552 | } |
| 553 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 554 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 555 | volatile T a = 0, b = 0; |
| 556 | T div = 0, mod = 0; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 557 | for (int i = 0; i < loops; i++) { |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 558 | if ((T)i == 0) continue; // Small T will wrap around. |
| 559 | SkTDivMod((T)(i+1), (T)i, &div, &mod); |
| 560 | a ^= div; |
| 561 | b ^= mod; |
| 562 | } |
| 563 | } |
| 564 | }; |
| 565 | DEF_BENCH(return new DivModBench<uint8_t>("uint8_t")) |
| 566 | DEF_BENCH(return new DivModBench<uint16_t>("uint16_t")) |
| 567 | DEF_BENCH(return new DivModBench<uint32_t>("uint32_t")) |
| 568 | DEF_BENCH(return new DivModBench<uint64_t>("uint64_t")) |
| 569 | |
| 570 | DEF_BENCH(return new DivModBench<int8_t>("int8_t")) |
| 571 | DEF_BENCH(return new DivModBench<int16_t>("int16_t")) |
| 572 | DEF_BENCH(return new DivModBench<int32_t>("int32_t")) |
| 573 | DEF_BENCH(return new DivModBench<int64_t>("int64_t")) |
| 574 | |
| 575 | /////////////////////////////////////////////////////////////////////////////// |
| 576 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 577 | DEF_BENCH( return new NoOpMathBench(); ) |
commit-bot@chromium.org | 11e5b97 | 2013-11-08 20:14:16 +0000 | [diff] [blame] | 578 | DEF_BENCH( return new SkRSqrtMathBench(); ) |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 579 | DEF_BENCH( return new SlowISqrtMathBench(); ) |
| 580 | DEF_BENCH( return new FastISqrtMathBench(); ) |
| 581 | DEF_BENCH( return new QMul64Bench(); ) |
| 582 | DEF_BENCH( return new QMul32Bench(); ) |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 583 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 584 | DEF_BENCH( return new IsFiniteBench(-1); ) |
| 585 | DEF_BENCH( return new IsFiniteBench(0); ) |
| 586 | DEF_BENCH( return new IsFiniteBench(1); ) |
| 587 | DEF_BENCH( return new IsFiniteBench(2); ) |
| 588 | DEF_BENCH( return new IsFiniteBench(3); ) |
| 589 | DEF_BENCH( return new IsFiniteBench(4); ) |
| 590 | DEF_BENCH( return new IsFiniteBench(5); ) |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 591 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 592 | DEF_BENCH( return new FloorBench(false); ) |
| 593 | DEF_BENCH( return new FloorBench(true); ) |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 594 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 595 | DEF_BENCH( return new CLZBench(false); ) |
| 596 | DEF_BENCH( return new CLZBench(true); ) |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 597 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 598 | DEF_BENCH( return new NormalizeBench(); ) |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 599 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 600 | DEF_BENCH( return new FixedMathBench(); ) |
Mike Reed | 828f1d5 | 2017-08-09 11:06:53 -0400 | [diff] [blame] | 601 | |
| 602 | ////////////////////////////////////////////////////////////// |
| 603 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 604 | #include "include/private/SkFloatBits.h" |
Mike Reed | 828f1d5 | 2017-08-09 11:06:53 -0400 | [diff] [blame] | 605 | class Floor2IntBench : public Benchmark { |
| 606 | enum { |
| 607 | ARRAY = 1000, |
| 608 | }; |
| 609 | float fData[ARRAY]; |
| 610 | const bool fSat; |
| 611 | public: |
| 612 | |
| 613 | Floor2IntBench(bool sat) : fSat(sat) { |
| 614 | SkRandom rand; |
| 615 | |
| 616 | for (int i = 0; i < ARRAY; ++i) { |
| 617 | fData[i] = SkBits2Float(rand.nextU()); |
| 618 | } |
| 619 | |
| 620 | if (sat) { |
| 621 | fName = "floor2int_sat"; |
| 622 | } else { |
| 623 | fName = "floor2int_undef"; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | bool isSuitableFor(Backend backend) override { |
| 628 | return backend == kNonRendering_Backend; |
| 629 | } |
| 630 | |
| 631 | // These exist to try to stop the compiler from detecting what we doing, and throwing |
| 632 | // parts away (or knowing exactly how big the loop counts are). |
Mike Reed | c270423 | 2017-08-09 13:32:04 -0400 | [diff] [blame] | 633 | virtual void process(unsigned) {} |
Mike Reed | 828f1d5 | 2017-08-09 11:06:53 -0400 | [diff] [blame] | 634 | virtual int count() { return ARRAY; } |
| 635 | |
| 636 | protected: |
| 637 | void onDraw(int loops, SkCanvas*) override { |
Mike Reed | c270423 | 2017-08-09 13:32:04 -0400 | [diff] [blame] | 638 | // used unsigned to avoid undefined behavior if/when the += might overflow |
| 639 | unsigned accum = 0; |
Mike Reed | 828f1d5 | 2017-08-09 11:06:53 -0400 | [diff] [blame] | 640 | |
| 641 | for (int j = 0; j < loops; ++j) { |
| 642 | int n = this->count(); |
| 643 | if (fSat) { |
| 644 | for (int i = 0; i < n; ++i) { |
| 645 | accum += sk_float_floor2int(fData[i]); |
| 646 | } |
| 647 | } else { |
| 648 | for (int i = 0; i < n; ++i) { |
| 649 | accum += sk_float_floor2int_no_saturate(fData[i]); |
| 650 | } |
| 651 | } |
| 652 | this->process(accum); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | const char* onGetName() override { return fName; } |
| 657 | |
| 658 | private: |
| 659 | const char* fName; |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 660 | |
Mike Reed | 828f1d5 | 2017-08-09 11:06:53 -0400 | [diff] [blame] | 661 | typedef Benchmark INHERITED; |
| 662 | }; |
| 663 | DEF_BENCH( return new Floor2IntBench(false); ) |
| 664 | DEF_BENCH( return new Floor2IntBench(true); ) |
| 665 | |