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