OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkPMFloat.h" | 9 #include "SkPMFloat.h" |
10 | 10 |
11 // Used to prevent the compiler from optimizing away the whole loop. | 11 // Used to prevent the compiler from optimizing away the whole loop. |
12 volatile uint32_t blackhole = 0; | 12 volatile uint32_t blackhole = 0; |
13 | 13 |
14 // Not a great random number generator, but it's very fast. | 14 // Not a great random number generator, but it's very fast. |
15 // The code we're measuring is quite fast, so low overhead is essential. | 15 // The code we're measuring is quite fast, so low overhead is essential. |
16 static uint32_t lcg_rand(uint32_t* seed) { | 16 static uint32_t lcg_rand(uint32_t* seed) { |
17 *seed *= 1664525; | 17 *seed *= 1664525; |
18 *seed += 1013904223; | 18 *seed += 1013904223; |
19 return *seed; | 19 return *seed; |
20 } | 20 } |
21 | 21 |
22 // I'm having better luck getting these to constant-propagate away as template p
arameters. | 22 // I'm having better luck getting these to constant-propagate away as template p
arameters. |
23 template <bool kClamp, bool kWide> | 23 template <bool kClamp, bool kWide> |
24 struct PMFloatBench : public Benchmark { | 24 struct PMFloatGetSetBench : public Benchmark { |
25 PMFloatBench() {} | 25 PMFloatGetSetBench() {} |
26 | 26 |
27 const char* onGetName() SK_OVERRIDE { | 27 const char* onGetName() SK_OVERRIDE { |
28 switch (kClamp << 1 | kWide) { | 28 switch (kClamp << 1 | kWide) { |
29 case 0: return "SkPMFloat_get_1x"; | 29 case 0: return "SkPMFloat_get_1x"; |
30 case 1: return "SkPMFloat_get_4x"; | 30 case 1: return "SkPMFloat_get_4x"; |
31 case 2: return "SkPMFloat_clamp_1x"; | 31 case 2: return "SkPMFloat_clamp_1x"; |
32 case 3: return "SkPMFloat_clamp_4x"; | 32 case 3: return "SkPMFloat_clamp_4x"; |
33 } | 33 } |
34 SkFAIL("unreachable"); | 34 SkFAIL("unreachable"); |
35 return "oh bother"; | 35 return "oh bother"; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 for (int i = 0; i < 4; i++) { | 86 for (int i = 0; i < 4; i++) { |
87 junk ^= back[i]; | 87 junk ^= back[i]; |
88 } | 88 } |
89 } | 89 } |
90 blackhole ^= junk; | 90 blackhole ^= junk; |
91 } | 91 } |
92 }; | 92 }; |
93 | 93 |
94 // Extra () help DEF_BENCH not get confused by the comma inside the <>. | 94 // Extra () help DEF_BENCH not get confused by the comma inside the <>. |
95 DEF_BENCH(return (new PMFloatBench< true, true>);) | 95 DEF_BENCH(return (new PMFloatGetSetBench< true, true>);) |
96 DEF_BENCH(return (new PMFloatBench<false, true>);) | 96 DEF_BENCH(return (new PMFloatGetSetBench<false, true>);) |
97 DEF_BENCH(return (new PMFloatBench< true, false>);) | 97 DEF_BENCH(return (new PMFloatGetSetBench< true, false>);) |
98 DEF_BENCH(return (new PMFloatBench<false, false>);) | 98 DEF_BENCH(return (new PMFloatGetSetBench<false, false>);) |
| 99 |
| 100 struct PMFloatGradientBench : public Benchmark { |
| 101 const char* onGetName() override { return "PMFloat_gradient"; } |
| 102 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } |
| 103 |
| 104 SkPMColor fDevice[100]; |
| 105 void onDraw(const int loops, SkCanvas*) override { |
| 106 Sk4f c0 = SkPMFloat::FromARGB(255, 255, 0, 0), |
| 107 c1 = SkPMFloat::FromARGB(255, 0, 0, 255), |
| 108 dc = c1 - c0, |
| 109 fx(0.1f), |
| 110 dx(0.002f), |
| 111 dcdx(dc*dx), |
| 112 dcdx4(dcdx+dcdx+dcdx+dcdx); |
| 113 |
| 114 for (int n = 0; n < loops; n++) { |
| 115 Sk4f a = c0 + dc*fx, // TODO: add 0.5f, here call trunc() instead o
f get(). |
| 116 b = a + dcdx, |
| 117 c = b + dcdx, |
| 118 d = c + dcdx; |
| 119 for (size_t i = 0; i < SK_ARRAY_COUNT(fDevice); i += 4) { |
| 120 fDevice[i+0] = SkPMFloat(a).get(); |
| 121 fDevice[i+1] = SkPMFloat(b).get(); |
| 122 fDevice[i+2] = SkPMFloat(c).get(); |
| 123 fDevice[i+3] = SkPMFloat(d).get(); |
| 124 a += dcdx4; |
| 125 b += dcdx4; |
| 126 c += dcdx4; |
| 127 d += dcdx4; |
| 128 } |
| 129 } |
| 130 } |
| 131 }; |
| 132 |
| 133 DEF_BENCH(return new PMFloatGradientBench;) |
OLD | NEW |