reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 1 | #include "SkBenchmark.h" |
| 2 | #include "SkColorPriv.h" |
| 3 | #include "SkMatrix.h" |
| 4 | #include "SkRandom.h" |
| 5 | #include "SkString.h" |
| 6 | #include "SkPaint.h" |
| 7 | |
| 8 | #define TILE(x, width) (((x) & 0xFFFF) * width >> 16) |
| 9 | |
| 10 | class InterpBench : public SkBenchmark { |
| 11 | enum { |
| 12 | kBuffer = 128, |
| 13 | kLoop = 20000 |
| 14 | }; |
| 15 | SkString fName; |
| 16 | int16_t fDst[kBuffer]; |
| 17 | float fFx, fDx; |
| 18 | public: |
| 19 | InterpBench(void* param, const char name[]) : INHERITED(param) { |
| 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; |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | virtual void performTest(int16_t dst[], float x, float dx, int count) = 0; |
| 26 | |
| 27 | protected: |
| 28 | virtual int mulLoopCount() const { return 1; } |
| 29 | |
| 30 | virtual const char* onGetName() { |
| 31 | return fName.c_str(); |
| 32 | } |
| 33 | |
| 34 | virtual void onDraw(SkCanvas* canvas) { |
| 35 | int n = SkBENCHLOOP(kLoop * this->mulLoopCount()); |
| 36 | for (int i = 0; i < n; i++) { |
| 37 | this->performTest(fDst, fFx, fDx, kBuffer); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | typedef SkBenchmark INHERITED; |
| 43 | }; |
| 44 | |
| 45 | class Fixed16D16Interp : public InterpBench { |
| 46 | public: |
| 47 | Fixed16D16Interp(void* param) : INHERITED(param, "16.16") {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 48 | |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 49 | protected: |
| 50 | virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE { |
| 51 | SkFixed curr = SkFloatToFixed(fx); |
| 52 | SkFixed step = SkFloatToFixed(dx); |
| 53 | for (int i = 0; i < count; i += 4) { |
| 54 | dst[i + 0] = TILE(curr, count); curr += step; |
| 55 | dst[i + 1] = TILE(curr, count); curr += step; |
| 56 | dst[i + 2] = TILE(curr, count); curr += step; |
| 57 | dst[i + 3] = TILE(curr, count); curr += step; |
| 58 | } |
| 59 | } |
| 60 | private: |
| 61 | typedef InterpBench INHERITED; |
| 62 | }; |
| 63 | |
| 64 | class Fixed32D32Interp : public InterpBench { |
| 65 | public: |
| 66 | Fixed32D32Interp(void* param) : INHERITED(param, "32.32") {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 67 | |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 68 | protected: |
| 69 | virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE { |
| 70 | int64_t curr = (int64_t)(fx * 65536 * 655536); |
| 71 | int64_t step = (int64_t)(dx * 65536 * 655536); |
| 72 | SkFixed tmp; |
| 73 | for (int i = 0; i < count; i += 4) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 74 | tmp = (SkFixed)(curr >> 16); |
| 75 | dst[i + 0] = TILE(tmp, count); |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 76 | curr += step; |
| 77 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 78 | tmp = (SkFixed)(curr >> 16); |
| 79 | dst[i + 1] = 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 + 2] = 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 + 3] = TILE(tmp, count); |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 88 | curr += step; |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | private: |
| 92 | typedef InterpBench INHERITED; |
| 93 | }; |
| 94 | |
| 95 | class Fixed16D48Interp : public InterpBench { |
| 96 | public: |
| 97 | Fixed16D48Interp(void* param) : INHERITED(param, "16.48") {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 98 | |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 99 | protected: |
| 100 | virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE { |
| 101 | int64_t curr = (int64_t)(fx * 65536 * 655536 * 65536); |
| 102 | int64_t step = (int64_t)(dx * 65536 * 655536 * 65536); |
| 103 | SkFixed tmp; |
| 104 | for (int i = 0; i < count; i += 4) { |
caryclark@google.com | 19069a2 | 2012-06-06 12:11:45 +0000 | [diff] [blame] | 105 | tmp = (SkFixed) (curr >> 32); dst[i + 0] = TILE(tmp, count); curr += step; |
| 106 | tmp = (SkFixed) (curr >> 32); dst[i + 1] = TILE(tmp, count); curr += step; |
| 107 | tmp = (SkFixed) (curr >> 32); dst[i + 2] = TILE(tmp, count); curr += step; |
| 108 | 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] | 109 | } |
| 110 | } |
| 111 | private: |
| 112 | typedef InterpBench INHERITED; |
| 113 | }; |
| 114 | |
| 115 | class FloatInterp : public InterpBench { |
| 116 | public: |
| 117 | FloatInterp(void* param) : INHERITED(param, "float") {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 118 | |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 119 | protected: |
| 120 | virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE { |
| 121 | SkFixed tmp; |
| 122 | for (int i = 0; i < count; i += 4) { |
| 123 | tmp = SkFloatToFixed(fx); dst[i + 0] = TILE(tmp, count); fx += dx; |
| 124 | tmp = SkFloatToFixed(fx); dst[i + 1] = TILE(tmp, count); fx += dx; |
| 125 | tmp = SkFloatToFixed(fx); dst[i + 2] = TILE(tmp, count); fx += dx; |
| 126 | tmp = SkFloatToFixed(fx); dst[i + 3] = TILE(tmp, count); fx += dx; |
| 127 | } |
| 128 | } |
| 129 | private: |
| 130 | typedef InterpBench INHERITED; |
| 131 | }; |
| 132 | |
| 133 | class DoubleInterp : public InterpBench { |
| 134 | public: |
| 135 | DoubleInterp(void* param) : INHERITED(param, "double") {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 136 | |
reed@google.com | b8c3917 | 2012-03-07 12:36:07 +0000 | [diff] [blame] | 137 | protected: |
| 138 | virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE { |
| 139 | double ffx = fx; |
| 140 | double ddx = dx; |
| 141 | SkFixed tmp; |
| 142 | for (int i = 0; i < count; i += 4) { |
| 143 | tmp = SkDoubleToFixed(ffx); dst[i + 0] = TILE(tmp, count); ffx += ddx; |
| 144 | tmp = SkDoubleToFixed(ffx); dst[i + 1] = TILE(tmp, count); ffx += ddx; |
| 145 | tmp = SkDoubleToFixed(ffx); dst[i + 2] = TILE(tmp, count); ffx += ddx; |
| 146 | tmp = SkDoubleToFixed(ffx); dst[i + 3] = TILE(tmp, count); ffx += ddx; |
| 147 | } |
| 148 | } |
| 149 | private: |
| 150 | typedef InterpBench INHERITED; |
| 151 | }; |
| 152 | |
| 153 | /////////////////////////////////////////////////////////////////////////////// |
| 154 | |
| 155 | static SkBenchmark* M0(void* p) { return new Fixed16D16Interp(p); } |
| 156 | static SkBenchmark* M1(void* p) { return new Fixed32D32Interp(p); } |
| 157 | static SkBenchmark* M2(void* p) { return new Fixed16D48Interp(p); } |
| 158 | static SkBenchmark* M3(void* p) { return new FloatInterp(p); } |
| 159 | static SkBenchmark* M4(void* p) { return new DoubleInterp(p); } |
| 160 | |
| 161 | static BenchRegistry gReg0(M0); |
| 162 | static BenchRegistry gReg1(M1); |
| 163 | static BenchRegistry gReg2(M2); |
| 164 | static BenchRegistry gReg3(M3); |
| 165 | static BenchRegistry gReg4(M4); |
| 166 | |