reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 1 | #include "SkBenchmark.h" |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 2 | #include "SkColorPriv.h" |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 3 | #include "SkMatrix.h" |
| 4 | #include "SkRandom.h" |
| 5 | #include "SkString.h" |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 6 | #include "SkPaint.h" |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 7 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 8 | static float sk_fsel(float pred, float result_ge, float result_lt) { |
| 9 | return pred >= 0 ? result_ge : result_lt; |
| 10 | } |
| 11 | |
| 12 | static float fast_floor(float x) { |
reed@google.com | f3a8d8e | 2012-05-30 14:08:57 +0000 | [diff] [blame] | 13 | // 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.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 15 | return (x + big) - big; |
| 16 | } |
| 17 | |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 18 | class MathBench : public SkBenchmark { |
| 19 | enum { |
| 20 | kBuffer = 100, |
| 21 | kLoop = 10000 |
| 22 | }; |
| 23 | SkString fName; |
| 24 | float fSrc[kBuffer], fDst[kBuffer]; |
| 25 | public: |
| 26 | MathBench(void* param, const char name[]) : INHERITED(param) { |
| 27 | fName.printf("math_%s", name); |
| 28 | |
| 29 | SkRandom rand; |
| 30 | for (int i = 0; i < kBuffer; ++i) { |
| 31 | fSrc[i] = rand.nextSScalar1(); |
| 32 | } |
tomhudson@google.com | 9dc2713 | 2012-09-13 15:50:24 +0000 | [diff] [blame] | 33 | |
| 34 | fIsRendering = false; |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 35 | } |
| 36 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 37 | virtual void performTest(float* SK_RESTRICT dst, |
| 38 | const float* SK_RESTRICT src, |
robertphillips@google.com | 6853e80 | 2012-04-16 15:50:18 +0000 | [diff] [blame] | 39 | int count) = 0; |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 40 | |
| 41 | protected: |
| 42 | virtual int mulLoopCount() const { return 1; } |
| 43 | |
| 44 | virtual const char* onGetName() { |
| 45 | return fName.c_str(); |
| 46 | } |
| 47 | |
sugoi@google.com | 77472f0 | 2013-03-05 18:50:01 +0000 | [diff] [blame] | 48 | virtual void onDraw(SkCanvas*) { |
tomhudson@google.com | ca529d3 | 2011-10-28 15:34:49 +0000 | [diff] [blame] | 49 | int n = SkBENCHLOOP(kLoop * this->mulLoopCount()); |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 50 | for (int i = 0; i < n; i++) { |
| 51 | this->performTest(fDst, fSrc, kBuffer); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | typedef SkBenchmark INHERITED; |
| 57 | }; |
| 58 | |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 59 | class MathBenchU32 : public MathBench { |
| 60 | public: |
| 61 | MathBenchU32(void* param, const char name[]) : INHERITED(param, name) {} |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 62 | |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 63 | protected: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 64 | virtual void performITest(uint32_t* SK_RESTRICT dst, |
| 65 | const uint32_t* SK_RESTRICT src, |
robertphillips@google.com | 6853e80 | 2012-04-16 15:50:18 +0000 | [diff] [blame] | 66 | int count) = 0; |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 67 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 68 | virtual void performTest(float* SK_RESTRICT dst, |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 69 | const float* SK_RESTRICT src, |
| 70 | int count) SK_OVERRIDE { |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 71 | uint32_t* d = SkTCast<uint32_t*>(dst); |
| 72 | const uint32_t* s = SkTCast<const uint32_t*>(src); |
| 73 | this->performITest(d, s, count); |
| 74 | } |
| 75 | private: |
| 76 | typedef MathBench INHERITED; |
| 77 | }; |
| 78 | |
| 79 | /////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 80 | |
| 81 | class NoOpMathBench : public MathBench { |
| 82 | public: |
bungeman@google.com | 9399cac | 2011-08-31 19:47:59 +0000 | [diff] [blame] | 83 | NoOpMathBench(void* param) : INHERITED(param, "noOp") {} |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 84 | protected: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 85 | virtual void performTest(float* SK_RESTRICT dst, |
| 86 | const float* SK_RESTRICT src, |
robertphillips@google.com | 6853e80 | 2012-04-16 15:50:18 +0000 | [diff] [blame] | 87 | int count) { |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 88 | for (int i = 0; i < count; ++i) { |
| 89 | dst[i] = src[i] + 1; |
| 90 | } |
| 91 | } |
| 92 | private: |
| 93 | typedef MathBench INHERITED; |
| 94 | }; |
| 95 | |
| 96 | class SlowISqrtMathBench : public MathBench { |
| 97 | public: |
| 98 | SlowISqrtMathBench(void* param) : INHERITED(param, "slowIsqrt") {} |
| 99 | protected: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 100 | virtual void performTest(float* SK_RESTRICT dst, |
| 101 | const float* SK_RESTRICT src, |
robertphillips@google.com | 6853e80 | 2012-04-16 15:50:18 +0000 | [diff] [blame] | 102 | int count) { |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 103 | for (int i = 0; i < count; ++i) { |
| 104 | dst[i] = 1.0f / sk_float_sqrt(src[i]); |
| 105 | } |
| 106 | } |
| 107 | private: |
| 108 | typedef MathBench INHERITED; |
| 109 | }; |
| 110 | |
| 111 | static inline float SkFastInvSqrt(float x) { |
| 112 | float xhalf = 0.5f*x; |
bsalomon@google.com | 373ebc6 | 2012-09-26 13:08:56 +0000 | [diff] [blame] | 113 | int i = *SkTCast<int*>(&x); |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 114 | i = 0x5f3759df - (i>>1); |
bsalomon@google.com | 373ebc6 | 2012-09-26 13:08:56 +0000 | [diff] [blame] | 115 | x = *SkTCast<float*>(&i); |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 116 | x = x*(1.5f-xhalf*x*x); |
| 117 | // x = x*(1.5f-xhalf*x*x); // this line takes err from 10^-3 to 10^-6 |
| 118 | return x; |
| 119 | } |
| 120 | |
| 121 | class FastISqrtMathBench : public MathBench { |
| 122 | public: |
| 123 | FastISqrtMathBench(void* param) : INHERITED(param, "fastIsqrt") {} |
| 124 | protected: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 125 | virtual void performTest(float* SK_RESTRICT dst, |
| 126 | const float* SK_RESTRICT src, |
robertphillips@google.com | 6853e80 | 2012-04-16 15:50:18 +0000 | [diff] [blame] | 127 | int count) { |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 128 | for (int i = 0; i < count; ++i) { |
| 129 | dst[i] = SkFastInvSqrt(src[i]); |
| 130 | } |
| 131 | } |
| 132 | private: |
| 133 | typedef MathBench INHERITED; |
| 134 | }; |
| 135 | |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 136 | static inline uint32_t QMul64(uint32_t value, U8CPU alpha) { |
| 137 | SkASSERT((uint8_t)alpha == alpha); |
| 138 | const uint32_t mask = 0xFF00FF; |
| 139 | |
| 140 | uint64_t tmp = value; |
| 141 | tmp = (tmp & mask) | ((tmp & ~mask) << 24); |
| 142 | tmp *= alpha; |
caryclark@google.com | 19069a2 | 2012-06-06 12:11:45 +0000 | [diff] [blame] | 143 | return (uint32_t) (((tmp >> 8) & mask) | ((tmp >> 32) & ~mask)); |
reed@google.com | e05cc8e | 2011-10-10 14:19:40 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | class QMul64Bench : public MathBenchU32 { |
| 147 | public: |
| 148 | QMul64Bench(void* param) : INHERITED(param, "qmul64") {} |
| 149 | protected: |
| 150 | virtual void performITest(uint32_t* SK_RESTRICT dst, |
| 151 | const uint32_t* SK_RESTRICT src, |
| 152 | int count) SK_OVERRIDE { |
| 153 | for (int i = 0; i < count; ++i) { |
| 154 | dst[i] = QMul64(src[i], (uint8_t)i); |
| 155 | } |
| 156 | } |
| 157 | private: |
| 158 | typedef MathBenchU32 INHERITED; |
| 159 | }; |
| 160 | |
| 161 | class QMul32Bench : public MathBenchU32 { |
| 162 | public: |
| 163 | QMul32Bench(void* param) : INHERITED(param, "qmul32") {} |
| 164 | protected: |
| 165 | virtual void performITest(uint32_t* SK_RESTRICT dst, |
| 166 | const uint32_t* SK_RESTRICT src, |
| 167 | int count) SK_OVERRIDE { |
| 168 | for (int i = 0; i < count; ++i) { |
| 169 | dst[i] = SkAlphaMulQ(src[i], (uint8_t)i); |
| 170 | } |
| 171 | } |
| 172 | private: |
| 173 | typedef MathBenchU32 INHERITED; |
| 174 | }; |
| 175 | |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 176 | /////////////////////////////////////////////////////////////////////////////// |
| 177 | |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 178 | static bool isFinite_int(float x) { |
| 179 | uint32_t bits = SkFloat2Bits(x); // need unsigned for our shifts |
| 180 | int exponent = bits << 1 >> 24; |
| 181 | return exponent != 0xFF; |
| 182 | } |
| 183 | |
| 184 | static bool isFinite_float(float x) { |
robertphillips@google.com | 6853e80 | 2012-04-16 15:50:18 +0000 | [diff] [blame] | 185 | return SkToBool(sk_float_isfinite(x)); |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static bool isFinite_mulzero(float x) { |
| 189 | float y = x * 0; |
| 190 | return y == y; |
| 191 | } |
| 192 | |
| 193 | static bool isfinite_and_int(const float data[4]) { |
| 194 | return isFinite_int(data[0]) && isFinite_int(data[1]) && isFinite_int(data[2]) && isFinite_int(data[3]); |
| 195 | } |
| 196 | |
| 197 | static bool isfinite_and_float(const float data[4]) { |
| 198 | return isFinite_float(data[0]) && isFinite_float(data[1]) && isFinite_float(data[2]) && isFinite_float(data[3]); |
| 199 | } |
| 200 | |
| 201 | static bool isfinite_and_mulzero(const float data[4]) { |
| 202 | return isFinite_mulzero(data[0]) && isFinite_mulzero(data[1]) && isFinite_mulzero(data[2]) && isFinite_mulzero(data[3]); |
| 203 | } |
| 204 | |
| 205 | #define mulzeroadd(data) (data[0]*0 + data[1]*0 + data[2]*0 + data[3]*0) |
| 206 | |
| 207 | static bool isfinite_plus_int(const float data[4]) { |
| 208 | return isFinite_int(mulzeroadd(data)); |
| 209 | } |
| 210 | |
| 211 | static bool isfinite_plus_float(const float data[4]) { |
reed@google.com | 5ae777d | 2011-12-06 20:18:05 +0000 | [diff] [blame] | 212 | return !sk_float_isnan(mulzeroadd(data)); |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static bool isfinite_plus_mulzero(const float data[4]) { |
| 216 | float x = mulzeroadd(data); |
| 217 | return x == x; |
| 218 | } |
| 219 | |
| 220 | typedef bool (*IsFiniteProc)(const float[]); |
| 221 | |
| 222 | #define MAKEREC(name) { name, #name } |
| 223 | |
| 224 | static const struct { |
| 225 | IsFiniteProc fProc; |
| 226 | const char* fName; |
| 227 | } gRec[] = { |
| 228 | MAKEREC(isfinite_and_int), |
| 229 | MAKEREC(isfinite_and_float), |
| 230 | MAKEREC(isfinite_and_mulzero), |
| 231 | MAKEREC(isfinite_plus_int), |
| 232 | MAKEREC(isfinite_plus_float), |
| 233 | MAKEREC(isfinite_plus_mulzero), |
| 234 | }; |
| 235 | |
| 236 | #undef MAKEREC |
| 237 | |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 238 | static bool isFinite(const SkRect& r) { |
| 239 | // x * 0 will be NaN iff x is infinity or NaN. |
| 240 | // a + b will be NaN iff either a or b is NaN. |
| 241 | 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] | 242 | |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 243 | // value is either NaN or it is finite (zero). |
| 244 | // value==value will be true iff value is not NaN |
| 245 | return value == value; |
| 246 | } |
| 247 | |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 248 | class IsFiniteBench : public SkBenchmark { |
| 249 | enum { |
| 250 | N = SkBENCHLOOP(1000), |
| 251 | NN = SkBENCHLOOP(1000), |
| 252 | }; |
| 253 | float fData[N]; |
| 254 | public: |
| 255 | |
| 256 | IsFiniteBench(void* param, int index) : INHERITED(param) { |
| 257 | SkRandom rand; |
| 258 | |
| 259 | for (int i = 0; i < N; ++i) { |
| 260 | fData[i] = rand.nextSScalar1(); |
| 261 | } |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 262 | |
| 263 | if (index < 0) { |
| 264 | fProc = NULL; |
| 265 | fName = "isfinite_rect"; |
| 266 | } else { |
| 267 | fProc = gRec[index].fProc; |
| 268 | fName = gRec[index].fName; |
| 269 | } |
tomhudson@google.com | 9dc2713 | 2012-09-13 15:50:24 +0000 | [diff] [blame] | 270 | fIsRendering = false; |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | protected: |
sugoi@google.com | 77472f0 | 2013-03-05 18:50:01 +0000 | [diff] [blame] | 274 | virtual void onDraw(SkCanvas*) { |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 275 | IsFiniteProc proc = fProc; |
| 276 | const float* data = fData; |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 277 | // do this so the compiler won't throw away the function call |
| 278 | int counter = 0; |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 279 | |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 280 | if (proc) { |
| 281 | for (int j = 0; j < NN; ++j) { |
| 282 | for (int i = 0; i < N - 4; ++i) { |
| 283 | counter += proc(&data[i]); |
| 284 | } |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 285 | } |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 286 | } else { |
| 287 | for (int j = 0; j < NN; ++j) { |
| 288 | for (int i = 0; i < N - 4; ++i) { |
| 289 | const SkRect* r = reinterpret_cast<const SkRect*>(&data[i]); |
caryclark@google.com | 19069a2 | 2012-06-06 12:11:45 +0000 | [diff] [blame] | 290 | if (false) { // avoid bit rot, suppress warning |
| 291 | isFinite(*r); |
| 292 | } |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 293 | counter += r->isFinite(); |
| 294 | } |
| 295 | } |
| 296 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 297 | |
reed@google.com | 1607863 | 2011-12-06 18:56:37 +0000 | [diff] [blame] | 298 | SkPaint paint; |
| 299 | if (paint.getAlpha() == 0) { |
| 300 | SkDebugf("%d\n", counter); |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
| 304 | virtual const char* onGetName() { |
| 305 | return fName; |
| 306 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 307 | |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 308 | private: |
| 309 | IsFiniteProc fProc; |
| 310 | const char* fName; |
| 311 | |
| 312 | typedef SkBenchmark INHERITED; |
| 313 | }; |
| 314 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 315 | class FloorBench : public SkBenchmark { |
| 316 | enum { |
| 317 | ARRAY = SkBENCHLOOP(1000), |
| 318 | LOOP = SkBENCHLOOP(1000), |
| 319 | }; |
| 320 | float fData[ARRAY]; |
| 321 | bool fFast; |
| 322 | public: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 323 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 324 | FloorBench(void* param, bool fast) : INHERITED(param), fFast(fast) { |
| 325 | SkRandom rand; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 326 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 327 | for (int i = 0; i < ARRAY; ++i) { |
| 328 | fData[i] = rand.nextSScalar1(); |
| 329 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 330 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 331 | if (fast) { |
| 332 | fName = "floor_fast"; |
| 333 | } else { |
| 334 | fName = "floor_std"; |
| 335 | } |
tomhudson@google.com | 9dc2713 | 2012-09-13 15:50:24 +0000 | [diff] [blame] | 336 | fIsRendering = false; |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 337 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 338 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 339 | virtual void process(float) {} |
| 340 | |
| 341 | protected: |
sugoi@google.com | 77472f0 | 2013-03-05 18:50:01 +0000 | [diff] [blame] | 342 | virtual void onDraw(SkCanvas*) { |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 343 | SkRandom rand; |
| 344 | float accum = 0; |
| 345 | const float* data = fData; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 346 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 347 | if (fFast) { |
| 348 | for (int j = 0; j < LOOP; ++j) { |
| 349 | for (int i = 0; i < ARRAY; ++i) { |
| 350 | accum += fast_floor(data[i]); |
| 351 | } |
| 352 | this->process(accum); |
| 353 | } |
| 354 | } else { |
| 355 | for (int j = 0; j < LOOP; ++j) { |
| 356 | for (int i = 0; i < ARRAY; ++i) { |
| 357 | accum += sk_float_floor(data[i]); |
| 358 | } |
| 359 | this->process(accum); |
| 360 | } |
| 361 | } |
| 362 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 363 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 364 | virtual const char* onGetName() { |
| 365 | return fName; |
| 366 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 367 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 368 | private: |
| 369 | const char* fName; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 370 | |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 371 | typedef SkBenchmark INHERITED; |
| 372 | }; |
| 373 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 374 | class CLZBench : public SkBenchmark { |
| 375 | enum { |
| 376 | ARRAY = SkBENCHLOOP(1000), |
reed@google.com | cb8dce2 | 2013-04-29 14:11:23 +0000 | [diff] [blame] | 377 | LOOP = SkBENCHLOOP(5000), |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 378 | }; |
| 379 | uint32_t fData[ARRAY]; |
| 380 | bool fUsePortable; |
| 381 | |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 382 | public: |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 383 | CLZBench(void* param, bool usePortable) |
| 384 | : INHERITED(param) |
| 385 | , fUsePortable(usePortable) { |
| 386 | |
| 387 | SkRandom rand; |
| 388 | for (int i = 0; i < ARRAY; ++i) { |
| 389 | fData[i] = rand.nextU(); |
| 390 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 391 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 392 | if (fUsePortable) { |
| 393 | fName = "clz_portable"; |
| 394 | } else { |
| 395 | fName = "clz_intrinsic"; |
| 396 | } |
| 397 | fIsRendering = false; |
| 398 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 399 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 400 | // just so the compiler doesn't remove our loops |
| 401 | virtual void process(int) {} |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 402 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 403 | protected: |
| 404 | virtual void onDraw(SkCanvas*) { |
| 405 | int accum = 0; |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 406 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 407 | if (fUsePortable) { |
| 408 | for (int j = 0; j < LOOP; ++j) { |
| 409 | for (int i = 0; i < ARRAY; ++i) { |
| 410 | accum += SkCLZ_portable(fData[i]); |
| 411 | } |
| 412 | this->process(accum); |
| 413 | } |
| 414 | } else { |
| 415 | for (int j = 0; j < LOOP; ++j) { |
| 416 | for (int i = 0; i < ARRAY; ++i) { |
| 417 | accum += SkCLZ(fData[i]); |
| 418 | } |
| 419 | this->process(accum); |
| 420 | } |
| 421 | } |
| 422 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 423 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 424 | virtual const char* onGetName() { |
| 425 | return fName; |
| 426 | } |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 427 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 428 | private: |
| 429 | const char* fName; |
skia.committer@gmail.com | 8152113 | 2013-04-30 07:01:03 +0000 | [diff] [blame] | 430 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 431 | typedef SkBenchmark INHERITED; |
| 432 | }; |
| 433 | |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 434 | /////////////////////////////////////////////////////////////////////////////// |
| 435 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 436 | class NormalizeBench : public SkBenchmark { |
| 437 | enum { |
| 438 | ARRAY = SkBENCHLOOP(1000), |
| 439 | LOOP = SkBENCHLOOP(1000), |
| 440 | }; |
| 441 | SkVector fVec[ARRAY]; |
| 442 | bool fUsePortable; |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 443 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 444 | public: |
| 445 | NormalizeBench(void* param, bool usePortable) |
| 446 | : INHERITED(param) |
| 447 | , fUsePortable(usePortable) { |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 448 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 449 | SkRandom rand; |
| 450 | for (int i = 0; i < ARRAY; ++i) { |
| 451 | fVec[i].set(rand.nextSScalar1(), rand.nextSScalar1()); |
| 452 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 453 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 454 | fName = "point_normalize"; |
| 455 | fIsRendering = false; |
| 456 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 457 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 458 | // just so the compiler doesn't remove our loops |
| 459 | virtual void process(int) {} |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 460 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 461 | protected: |
| 462 | virtual void onDraw(SkCanvas*) { |
| 463 | int accum = 0; |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 464 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 465 | for (int j = 0; j < LOOP; ++j) { |
| 466 | for (int i = 0; i < ARRAY; ++i) { |
| 467 | accum += fVec[i].normalize(); |
| 468 | } |
| 469 | this->process(accum); |
| 470 | } |
| 471 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 472 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 473 | virtual const char* onGetName() { |
| 474 | return fName; |
| 475 | } |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 476 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 477 | private: |
| 478 | const char* fName; |
skia.committer@gmail.com | ecc9d28 | 2013-05-04 07:01:15 +0000 | [diff] [blame] | 479 | |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 480 | typedef SkBenchmark INHERITED; |
| 481 | }; |
| 482 | |
| 483 | /////////////////////////////////////////////////////////////////////////////// |
| 484 | |
reed@google.com | 553ad65 | 2013-04-29 13:48:34 +0000 | [diff] [blame] | 485 | DEF_BENCH( return new NoOpMathBench(p); ) |
| 486 | DEF_BENCH( return new SlowISqrtMathBench(p); ) |
| 487 | DEF_BENCH( return new FastISqrtMathBench(p); ) |
| 488 | DEF_BENCH( return new QMul64Bench(p); ) |
| 489 | DEF_BENCH( return new QMul32Bench(p); ) |
reed@google.com | ddc518b | 2011-08-29 17:49:23 +0000 | [diff] [blame] | 490 | |
reed@google.com | 553ad65 | 2013-04-29 13:48:34 +0000 | [diff] [blame] | 491 | DEF_BENCH( return new IsFiniteBench(p, -1); ) |
| 492 | DEF_BENCH( return new IsFiniteBench(p, 0); ) |
| 493 | DEF_BENCH( return new IsFiniteBench(p, 1); ) |
| 494 | DEF_BENCH( return new IsFiniteBench(p, 2); ) |
| 495 | DEF_BENCH( return new IsFiniteBench(p, 3); ) |
| 496 | DEF_BENCH( return new IsFiniteBench(p, 4); ) |
| 497 | DEF_BENCH( return new IsFiniteBench(p, 5); ) |
reed@google.com | 0be5eb7 | 2011-12-05 21:53:22 +0000 | [diff] [blame] | 498 | |
reed@google.com | 553ad65 | 2013-04-29 13:48:34 +0000 | [diff] [blame] | 499 | DEF_BENCH( return new FloorBench(p, false); ) |
| 500 | DEF_BENCH( return new FloorBench(p, true); ) |
reed@google.com | 7f19241 | 2012-05-30 12:26:52 +0000 | [diff] [blame] | 501 | |
reed@google.com | 0d7aac9 | 2013-04-29 13:55:11 +0000 | [diff] [blame] | 502 | DEF_BENCH( return new CLZBench(p, false); ) |
| 503 | DEF_BENCH( return new CLZBench(p, true); ) |
reed@google.com | 0889f68 | 2013-05-03 12:56:39 +0000 | [diff] [blame] | 504 | |
| 505 | DEF_BENCH( return new NormalizeBench(p, false); ) |