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: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 66 | using INHERITED = Benchmark; |
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: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 84 | using INHERITED = MathBench; |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 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: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 99 | using INHERITED = MathBench; |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 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: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 112 | using INHERITED = MathBench; |
commit-bot@chromium.org | 11e5b97 | 2013-11-08 20:14:16 +0000 | [diff] [blame] | 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: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 126 | using INHERITED = MathBench; |
robertphillips@google.com | 36bb270 | 2013-08-12 12:02:28 +0000 | [diff] [blame] | 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: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 139 | using INHERITED = MathBench; |
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: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 164 | using INHERITED = MathBenchU32; |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 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: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 179 | using INHERITED = MathBenchU32; |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 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 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 320 | using INHERITED = Benchmark; |
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 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 381 | using INHERITED = Benchmark; |
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 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 441 | using INHERITED = Benchmark; |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 442 | }; |
| 443 | |
Ben Wagner | e2a9443 | 2020-05-04 17:42:34 -0400 | [diff] [blame] | 444 | class CTZBench : public Benchmark { |
| 445 | enum { |
| 446 | ARRAY = 1000, |
| 447 | }; |
| 448 | uint32_t fData[ARRAY]; |
| 449 | bool fUsePortable; |
| 450 | |
| 451 | public: |
| 452 | CTZBench(bool usePortable) : fUsePortable(usePortable) { |
| 453 | |
| 454 | SkRandom rand; |
| 455 | for (int i = 0; i < ARRAY; ++i) { |
| 456 | fData[i] = rand.nextU(); |
| 457 | } |
| 458 | |
| 459 | if (fUsePortable) { |
| 460 | fName = "ctz_portable"; |
| 461 | } else { |
| 462 | fName = "ctz_intrinsic"; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | bool isSuitableFor(Backend backend) override { |
| 467 | return backend == kNonRendering_Backend; |
| 468 | } |
| 469 | |
| 470 | // just so the compiler doesn't remove our loops |
| 471 | virtual void process(int) {} |
| 472 | |
| 473 | protected: |
| 474 | void onDraw(int loops, SkCanvas*) override { |
| 475 | int accum = 0; |
| 476 | |
| 477 | if (fUsePortable) { |
| 478 | for (int j = 0; j < loops; ++j) { |
| 479 | for (int i = 0; i < ARRAY; ++i) { |
| 480 | accum += SkCTZ_portable(fData[i]); |
| 481 | } |
| 482 | this->process(accum); |
| 483 | } |
| 484 | } else { |
| 485 | for (int j = 0; j < loops; ++j) { |
| 486 | for (int i = 0; i < ARRAY; ++i) { |
| 487 | accum += SkCTZ(fData[i]); |
| 488 | } |
| 489 | this->process(accum); |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | const char* onGetName() override { |
| 495 | return fName; |
| 496 | } |
| 497 | |
| 498 | private: |
| 499 | const char* fName; |
| 500 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 501 | using INHERITED = Benchmark; |
Ben Wagner | e2a9443 | 2020-05-04 17:42:34 -0400 | [diff] [blame] | 502 | }; |
| 503 | |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 504 | /////////////////////////////////////////////////////////////////////////////// |
| 505 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 506 | class NormalizeBench : public Benchmark { |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 507 | enum { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 508 | ARRAY =1000, |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 509 | }; |
| 510 | SkVector fVec[ARRAY]; |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 511 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 512 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 513 | NormalizeBench() { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 514 | SkRandom rand; |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 515 | for (int i = 0; i < ARRAY; ++i) { |
| 516 | fVec[i].set(rand.nextSScalar1(), rand.nextSScalar1()); |
| 517 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 518 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 519 | fName = "point_normalize"; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 520 | } |
| 521 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 522 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 523 | return backend == kNonRendering_Backend; |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 524 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 525 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 526 | // just so the compiler doesn't remove our loops |
| 527 | virtual void process(int) {} |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 528 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 529 | protected: |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 530 | void onDraw(int loops, SkCanvas*) override { |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 531 | int accum = 0; |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 532 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 533 | for (int j = 0; j < loops; ++j) { |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 534 | for (int i = 0; i < ARRAY; ++i) { |
| 535 | accum += fVec[i].normalize(); |
| 536 | } |
| 537 | this->process(accum); |
| 538 | } |
| 539 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 540 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 541 | const char* onGetName() override { |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 542 | return fName; |
| 543 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 544 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 545 | private: |
| 546 | const char* fName; |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 547 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 548 | using INHERITED = Benchmark; |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 549 | }; |
| 550 | |
| 551 | /////////////////////////////////////////////////////////////////////////////// |
| 552 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 553 | class FixedMathBench : public Benchmark { |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 554 | enum { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 555 | N = 1000, |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 556 | }; |
| 557 | float fData[N]; |
| 558 | SkFixed fResult[N]; |
| 559 | public: |
| 560 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 561 | FixedMathBench() { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 562 | SkRandom rand; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 563 | for (int i = 0; i < N; ++i) { |
| 564 | fData[i] = rand.nextSScalar1(); |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 565 | } |
| 566 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 567 | } |
| 568 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 569 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 570 | return backend == kNonRendering_Backend; |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | protected: |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 574 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 575 | for (int j = 0; j < loops; ++j) { |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 576 | for (int i = 0; i < N - 4; ++i) { |
| 577 | fResult[i] = SkFloatToFixed(fData[i]); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | SkPaint paint; |
| 582 | if (paint.getAlpha() == 0) { |
| 583 | SkDebugf("%d\n", fResult[0]); |
| 584 | } |
| 585 | } |
| 586 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 587 | const char* onGetName() override { |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 588 | return "float_to_fixed"; |
| 589 | } |
| 590 | |
| 591 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 592 | using INHERITED = Benchmark; |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 593 | }; |
| 594 | |
| 595 | /////////////////////////////////////////////////////////////////////////////// |
| 596 | |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 597 | template <typename T> |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 598 | class DivModBench : public Benchmark { |
mtklein@google.com | 9cb5177 | 2013-09-27 13:39:14 +0000 | [diff] [blame] | 599 | SkString fName; |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 600 | public: |
mtklein@google.com | 9cb5177 | 2013-09-27 13:39:14 +0000 | [diff] [blame] | 601 | explicit DivModBench(const char* name) { |
| 602 | fName.printf("divmod_%s", name); |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 603 | } |
| 604 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 605 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 606 | return backend == kNonRendering_Backend; |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 610 | const char* onGetName() override { |
mtklein@google.com | 9cb5177 | 2013-09-27 13:39:14 +0000 | [diff] [blame] | 611 | return fName.c_str(); |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 612 | } |
| 613 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 614 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 615 | volatile T a = 0, b = 0; |
| 616 | T div = 0, mod = 0; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 617 | for (int i = 0; i < loops; i++) { |
commit-bot@chromium.org | 2c86fbb | 2013-09-26 19:22:54 +0000 | [diff] [blame] | 618 | if ((T)i == 0) continue; // Small T will wrap around. |
| 619 | SkTDivMod((T)(i+1), (T)i, &div, &mod); |
| 620 | a ^= div; |
| 621 | b ^= mod; |
| 622 | } |
| 623 | } |
| 624 | }; |
| 625 | DEF_BENCH(return new DivModBench<uint8_t>("uint8_t")) |
| 626 | DEF_BENCH(return new DivModBench<uint16_t>("uint16_t")) |
| 627 | DEF_BENCH(return new DivModBench<uint32_t>("uint32_t")) |
| 628 | DEF_BENCH(return new DivModBench<uint64_t>("uint64_t")) |
| 629 | |
| 630 | DEF_BENCH(return new DivModBench<int8_t>("int8_t")) |
| 631 | DEF_BENCH(return new DivModBench<int16_t>("int16_t")) |
| 632 | DEF_BENCH(return new DivModBench<int32_t>("int32_t")) |
| 633 | DEF_BENCH(return new DivModBench<int64_t>("int64_t")) |
| 634 | |
| 635 | /////////////////////////////////////////////////////////////////////////////// |
| 636 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 637 | DEF_BENCH( return new NoOpMathBench(); ) |
commit-bot@chromium.org | 11e5b97 | 2013-11-08 20:14:16 +0000 | [diff] [blame] | 638 | DEF_BENCH( return new SkRSqrtMathBench(); ) |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 639 | DEF_BENCH( return new SlowISqrtMathBench(); ) |
| 640 | DEF_BENCH( return new FastISqrtMathBench(); ) |
| 641 | DEF_BENCH( return new QMul64Bench(); ) |
| 642 | DEF_BENCH( return new QMul32Bench(); ) |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 643 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 644 | DEF_BENCH( return new IsFiniteBench(-1); ) |
| 645 | DEF_BENCH( return new IsFiniteBench(0); ) |
| 646 | DEF_BENCH( return new IsFiniteBench(1); ) |
| 647 | DEF_BENCH( return new IsFiniteBench(2); ) |
| 648 | DEF_BENCH( return new IsFiniteBench(3); ) |
| 649 | DEF_BENCH( return new IsFiniteBench(4); ) |
| 650 | DEF_BENCH( return new IsFiniteBench(5); ) |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 651 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 652 | DEF_BENCH( return new FloorBench(false); ) |
| 653 | DEF_BENCH( return new FloorBench(true); ) |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 654 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 655 | DEF_BENCH( return new CLZBench(false); ) |
| 656 | DEF_BENCH( return new CLZBench(true); ) |
Ben Wagner | e2a9443 | 2020-05-04 17:42:34 -0400 | [diff] [blame] | 657 | DEF_BENCH( return new CTZBench(false); ) |
| 658 | DEF_BENCH( return new CTZBench(true); ) |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 659 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 660 | DEF_BENCH( return new NormalizeBench(); ) |
djsollen@google.com | 25a11e4 | 2013-07-18 19:11:30 +0000 | [diff] [blame] | 661 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 662 | DEF_BENCH( return new FixedMathBench(); ) |
Mike Reed | 828f1d5 | 2017-08-09 11:06:53 -0400 | [diff] [blame] | 663 | |
| 664 | ////////////////////////////////////////////////////////////// |
| 665 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 666 | #include "include/private/SkFloatBits.h" |
Mike Reed | 828f1d5 | 2017-08-09 11:06:53 -0400 | [diff] [blame] | 667 | class Floor2IntBench : public Benchmark { |
| 668 | enum { |
| 669 | ARRAY = 1000, |
| 670 | }; |
| 671 | float fData[ARRAY]; |
| 672 | const bool fSat; |
| 673 | public: |
| 674 | |
| 675 | Floor2IntBench(bool sat) : fSat(sat) { |
| 676 | SkRandom rand; |
| 677 | |
| 678 | for (int i = 0; i < ARRAY; ++i) { |
| 679 | fData[i] = SkBits2Float(rand.nextU()); |
| 680 | } |
| 681 | |
| 682 | if (sat) { |
| 683 | fName = "floor2int_sat"; |
| 684 | } else { |
| 685 | fName = "floor2int_undef"; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | bool isSuitableFor(Backend backend) override { |
| 690 | return backend == kNonRendering_Backend; |
| 691 | } |
| 692 | |
| 693 | // These exist to try to stop the compiler from detecting what we doing, and throwing |
| 694 | // parts away (or knowing exactly how big the loop counts are). |
Mike Reed | c270423 | 2017-08-09 13:32:04 -0400 | [diff] [blame] | 695 | virtual void process(unsigned) {} |
Mike Reed | 828f1d5 | 2017-08-09 11:06:53 -0400 | [diff] [blame] | 696 | virtual int count() { return ARRAY; } |
| 697 | |
| 698 | protected: |
| 699 | void onDraw(int loops, SkCanvas*) override { |
Mike Reed | c270423 | 2017-08-09 13:32:04 -0400 | [diff] [blame] | 700 | // used unsigned to avoid undefined behavior if/when the += might overflow |
| 701 | unsigned accum = 0; |
Mike Reed | 828f1d5 | 2017-08-09 11:06:53 -0400 | [diff] [blame] | 702 | |
| 703 | for (int j = 0; j < loops; ++j) { |
| 704 | int n = this->count(); |
| 705 | if (fSat) { |
| 706 | for (int i = 0; i < n; ++i) { |
| 707 | accum += sk_float_floor2int(fData[i]); |
| 708 | } |
| 709 | } else { |
| 710 | for (int i = 0; i < n; ++i) { |
| 711 | accum += sk_float_floor2int_no_saturate(fData[i]); |
| 712 | } |
| 713 | } |
| 714 | this->process(accum); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | const char* onGetName() override { return fName; } |
| 719 | |
| 720 | private: |
| 721 | const char* fName; |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 722 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 723 | using INHERITED = Benchmark; |
Mike Reed | 828f1d5 | 2017-08-09 11:06:53 -0400 | [diff] [blame] | 724 | }; |
| 725 | DEF_BENCH( return new Floor2IntBench(false); ) |
| 726 | DEF_BENCH( return new Floor2IntBench(true); ) |
| 727 | |