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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 9 | #include "SkColorPriv.h" |
benjaminwagner | 6c71e0a | 2016-04-07 08:49:31 -0700 | [diff] [blame] | 10 | #include "SkFixed.h" |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 11 | #include "SkMatrix.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 12 | #include "SkPaint.h" |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 13 | #include "SkRandom.h" |
| 14 | #include "SkString.h" |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 15 | |
| 16 | #define TILE(x, width) (((x) & 0xFFFF) * width >> 16) |
| 17 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 18 | class InterpBench : public Benchmark { |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 19 | enum { |
| 20 | kBuffer = 128, |
| 21 | kLoop = 20000 |
| 22 | }; |
| 23 | SkString fName; |
| 24 | int16_t fDst[kBuffer]; |
| 25 | float fFx, fDx; |
| 26 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 27 | InterpBench(const char name[]) { |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 28 | fName.printf("interp_%s", name); |
robertphillips@google.com | 09042b8 | 2012-04-06 20:01:46 +0000 | [diff] [blame] | 29 | fFx = 3.3f; |
| 30 | fDx = 0.1257f; |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 31 | } |
| 32 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 33 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 34 | return backend == kNonRendering_Backend; |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | virtual void performTest(int16_t dst[], float x, float dx, int count) = 0; |
| 38 | |
| 39 | protected: |
| 40 | virtual int mulLoopCount() const { return 1; } |
| 41 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 42 | const char* onGetName() override { |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 43 | return fName.c_str(); |
| 44 | } |
| 45 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 46 | void onDraw(int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 47 | int n = loops * this->mulLoopCount(); |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 48 | for (int i = 0; i < n; i++) { |
| 49 | this->performTest(fDst, fFx, fDx, kBuffer); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 54 | typedef Benchmark INHERITED; |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | class Fixed16D16Interp : public InterpBench { |
| 58 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 59 | Fixed16D16Interp() : INHERITED("16.16") {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 60 | |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 61 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 62 | void performTest(int16_t dst[], float fx, float dx, int count) override { |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 63 | SkFixed curr = SkFloatToFixed(fx); |
| 64 | SkFixed step = SkFloatToFixed(dx); |
| 65 | for (int i = 0; i < count; i += 4) { |
| 66 | dst[i + 0] = TILE(curr, count); curr += step; |
| 67 | dst[i + 1] = TILE(curr, count); curr += step; |
| 68 | dst[i + 2] = TILE(curr, count); curr += step; |
| 69 | dst[i + 3] = TILE(curr, count); curr += step; |
| 70 | } |
| 71 | } |
| 72 | private: |
| 73 | typedef InterpBench INHERITED; |
| 74 | }; |
| 75 | |
| 76 | class Fixed32D32Interp : public InterpBench { |
| 77 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 78 | Fixed32D32Interp() : INHERITED("32.32") {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 79 | |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 80 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 81 | void performTest(int16_t dst[], float fx, float dx, int count) override { |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 82 | int64_t curr = (int64_t)(fx * 65536 * 655536); |
| 83 | int64_t step = (int64_t)(dx * 65536 * 655536); |
| 84 | SkFixed tmp; |
| 85 | for (int i = 0; i < count; i += 4) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 86 | tmp = (SkFixed)(curr >> 16); |
| 87 | dst[i + 0] = TILE(tmp, count); |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 88 | curr += step; |
| 89 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 90 | tmp = (SkFixed)(curr >> 16); |
| 91 | dst[i + 1] = TILE(tmp, count); |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 92 | curr += step; |
| 93 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 94 | tmp = (SkFixed)(curr >> 16); |
| 95 | dst[i + 2] = TILE(tmp, count); |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 96 | curr += step; |
| 97 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 98 | tmp = (SkFixed)(curr >> 16); |
| 99 | dst[i + 3] = TILE(tmp, count); |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 100 | curr += step; |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | private: |
| 104 | typedef InterpBench INHERITED; |
| 105 | }; |
| 106 | |
| 107 | class Fixed16D48Interp : public InterpBench { |
| 108 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 109 | Fixed16D48Interp() : INHERITED("16.48") {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 110 | |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 111 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 112 | void performTest(int16_t dst[], float fx, float dx, int count) override { |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 113 | int64_t curr = (int64_t)(fx * 65536 * 655536 * 65536); |
| 114 | int64_t step = (int64_t)(dx * 65536 * 655536 * 65536); |
| 115 | SkFixed tmp; |
| 116 | for (int i = 0; i < count; i += 4) { |
caryclark@google.com | 19069a2 | 2012-06-06 12:11:45 +0000 | [diff] [blame] | 117 | tmp = (SkFixed) (curr >> 32); dst[i + 0] = TILE(tmp, count); curr += step; |
| 118 | tmp = (SkFixed) (curr >> 32); dst[i + 1] = TILE(tmp, count); curr += step; |
| 119 | tmp = (SkFixed) (curr >> 32); dst[i + 2] = TILE(tmp, count); curr += step; |
| 120 | tmp = (SkFixed) (curr >> 32); dst[i + 3] = TILE(tmp, count); curr += step; |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | private: |
| 124 | typedef InterpBench INHERITED; |
| 125 | }; |
| 126 | |
| 127 | class FloatInterp : public InterpBench { |
| 128 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 129 | FloatInterp() : INHERITED("float") {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 130 | |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 131 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 132 | void performTest(int16_t dst[], float fx, float dx, int count) override { |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 133 | SkFixed tmp; |
| 134 | for (int i = 0; i < count; i += 4) { |
| 135 | tmp = SkFloatToFixed(fx); dst[i + 0] = TILE(tmp, count); fx += dx; |
| 136 | tmp = SkFloatToFixed(fx); dst[i + 1] = TILE(tmp, count); fx += dx; |
| 137 | tmp = SkFloatToFixed(fx); dst[i + 2] = TILE(tmp, count); fx += dx; |
| 138 | tmp = SkFloatToFixed(fx); dst[i + 3] = TILE(tmp, count); fx += dx; |
| 139 | } |
| 140 | } |
| 141 | private: |
| 142 | typedef InterpBench INHERITED; |
| 143 | }; |
| 144 | |
| 145 | class DoubleInterp : public InterpBench { |
| 146 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 147 | DoubleInterp() : INHERITED("double") {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 148 | |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 149 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 150 | void performTest(int16_t dst[], float fx, float dx, int count) override { |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 151 | double ffx = fx; |
| 152 | double ddx = dx; |
| 153 | SkFixed tmp; |
| 154 | for (int i = 0; i < count; i += 4) { |
| 155 | tmp = SkDoubleToFixed(ffx); dst[i + 0] = TILE(tmp, count); ffx += ddx; |
| 156 | tmp = SkDoubleToFixed(ffx); dst[i + 1] = TILE(tmp, count); ffx += ddx; |
| 157 | tmp = SkDoubleToFixed(ffx); dst[i + 2] = TILE(tmp, count); ffx += ddx; |
| 158 | tmp = SkDoubleToFixed(ffx); dst[i + 3] = TILE(tmp, count); ffx += ddx; |
| 159 | } |
| 160 | } |
| 161 | private: |
| 162 | typedef InterpBench INHERITED; |
| 163 | }; |
| 164 | |
| 165 | /////////////////////////////////////////////////////////////////////////////// |
| 166 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 167 | DEF_BENCH( return new Fixed16D16Interp(); ) |
| 168 | DEF_BENCH( return new Fixed32D32Interp(); ) |
| 169 | DEF_BENCH( return new Fixed16D48Interp(); ) |
| 170 | DEF_BENCH( return new FloatInterp(); ) |
| 171 | DEF_BENCH( return new DoubleInterp(); ) |