2 #include "SkColorPriv.h"
8 #define TILE(x, width) (((x) & 0xFFFF) * width >> 16)
10 class InterpBench : public Benchmark {
16 int16_t fDst[kBuffer];
19 InterpBench(const char name[]) {
20 fName.printf("interp_%s", name);
25 bool isSuitableFor(Backend backend) override {
26 return backend == kNonRendering_Backend;
29 virtual void performTest(int16_t dst[], float x, float dx, int count) = 0;
32 virtual int mulLoopCount() const { return 1; }
34 virtual const char* onGetName() {
38 virtual void onDraw(const int loops, SkCanvas*) {
39 int n = loops * this->mulLoopCount();
40 for (int i = 0; i < n; i++) {
41 this->performTest(fDst, fFx, fDx, kBuffer);
46 typedef Benchmark INHERITED;
49 class Fixed16D16Interp : public InterpBench {
51 Fixed16D16Interp() : INHERITED("16.16") {}
54 void performTest(int16_t dst[], float fx, float dx, int count) 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;
65 typedef InterpBench INHERITED;
68 class Fixed32D32Interp : public InterpBench {
70 Fixed32D32Interp() : INHERITED("32.32") {}
73 void performTest(int16_t dst[], float fx, float dx, int count) override {
74 int64_t curr = (int64_t)(fx * 65536 * 655536);
75 int64_t step = (int64_t)(dx * 65536 * 655536);
77 for (int i = 0; i < count; i += 4) {
78 tmp = (SkFixed)(curr >> 16);
79 dst[i + 0] = TILE(tmp, count);
82 tmp = (SkFixed)(curr >> 16);
83 dst[i + 1] = TILE(tmp, count);
86 tmp = (SkFixed)(curr >> 16);
87 dst[i + 2] = TILE(tmp, count);
90 tmp = (SkFixed)(curr >> 16);
91 dst[i + 3] = TILE(tmp, count);
96 typedef InterpBench INHERITED;
99 class Fixed16D48Interp : public InterpBench {
101 Fixed16D48Interp() : INHERITED("16.48") {}
104 void performTest(int16_t dst[], float fx, float dx, int count) override {
105 int64_t curr = (int64_t)(fx * 65536 * 655536 * 65536);
106 int64_t step = (int64_t)(dx * 65536 * 655536 * 65536);
108 for (int i = 0; i < count; i += 4) {
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;
116 typedef InterpBench INHERITED;
119 class FloatInterp : public InterpBench {
121 FloatInterp() : INHERITED("float") {}
124 void performTest(int16_t dst[], float fx, float dx, int count) override {
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;
134 typedef InterpBench INHERITED;
137 class DoubleInterp : public InterpBench {
139 DoubleInterp() : INHERITED("double") {}
142 void performTest(int16_t dst[], float fx, float dx, int count) override {
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;
154 typedef InterpBench INHERITED;
157 ///////////////////////////////////////////////////////////////////////////////
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(); )