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