Index: bench/PMFloatBench.cpp |
diff --git a/bench/PMFloatBench.cpp b/bench/PMFloatBench.cpp |
index ee4914a45b018b8e29b064088a588500c912e5d9..1da667f4430ff317ef4e261167def3e1db1570ce 100644 |
--- a/bench/PMFloatBench.cpp |
+++ b/bench/PMFloatBench.cpp |
@@ -12,10 +12,21 @@ static uint32_t lcg_rand(uint32_t* seed) { |
return *seed; |
} |
+// I'm having better luck getting these to constant-propagate away as template parameters. |
+template <bool kClamp, bool kWide> |
struct PMFloatBench : public Benchmark { |
- explicit PMFloatBench(bool clamp) : fClamp(clamp) {} |
+ PMFloatBench() {} |
- const char* onGetName() SK_OVERRIDE { return fClamp ? "SkPMFloat_clamp" : "SkPMFloat_get"; } |
+ const char* onGetName() SK_OVERRIDE { |
+ switch (kClamp << 1 | kWide) { |
+ case 0: return "SkPMFloat_get_1x"; |
+ case 1: return "SkPMFloat_get_4x"; |
+ case 2: return "SkPMFloat_clamp_1x"; |
+ case 3: return "SkPMFloat_clamp_4x"; |
+ } |
+ SkFAIL("unreachable"); |
+ return "oh bother"; |
+ } |
bool isSuitableFor(Backend backend) SK_OVERRIDE { return backend == kNonRendering_Backend; } |
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
@@ -23,21 +34,47 @@ struct PMFloatBench : public Benchmark { |
uint32_t junk = 0; |
uint32_t seed = 0; |
for (int i = 0; i < loops; i++) { |
+ SkPMColor colors[4]; |
#ifdef SK_DEBUG |
- // Our SkASSERTs will remind us that it's technically required that we premultiply. |
- SkPMColor c = SkPreMultiplyColor(lcg_rand(&seed)); |
+ for (int i = 0; i < 4; i++) { |
+ // Our SkASSERTs will remind us that it's technically required that we premultiply. |
+ colors[i] = SkPreMultiplyColor(lcg_rand(&seed)); |
+ } |
#else |
// But it's a lot faster not to, and this code won't really mind the non-PM colors. |
- SkPMColor c = lcg_rand(&seed); |
+ (void)lcg_rand(&seed); |
+ colors[0] = seed + 0; |
+ colors[1] = seed + 1; |
+ colors[2] = seed + 2; |
+ colors[3] = seed + 3; |
#endif |
- SkPMFloat pmf = SkPMFloat::FromPMColor(c); |
- SkPMColor back = fClamp ? pmf.clamped() : pmf.get(); |
- junk ^= back; |
+ |
+ SkPMFloat floats[4]; |
+ if (kWide) { |
+ SkPMFloat::From4PMColors(floats, colors); |
+ } else { |
+ for (int i = 0; i < 4; i++) { |
+ floats[i] = SkPMFloat::FromPMColor(colors[i]); |
+ } |
+ } |
+ |
+ SkPMColor back[4]; |
+ switch (kClamp << 1 | kWide) { |
+ case 0: for (int i = 0; i < 4; i++) { back[i] = floats[i].get(); } break; |
+ case 1: SkPMFloat::To4PMColors(back, floats); break; |
+ case 2: for (int i = 0; i < 4; i++) { back[i] = floats[i].clamped(); } break; |
+ case 3: SkPMFloat::ClampTo4PMColors(back, floats); break; |
+ } |
+ for (int i = 0; i < 4; i++) { |
+ junk ^= back[i]; |
+ } |
} |
blackhole ^= junk; |
} |
- |
- bool fClamp; |
}; |
-DEF_BENCH(return new PMFloatBench( true);) |
-DEF_BENCH(return new PMFloatBench(false);) |
+ |
+// Extra () help DEF_BENCH not get confused by the comma inside the <>. |
+DEF_BENCH(return (new PMFloatBench< true, true>);) |
+DEF_BENCH(return (new PMFloatBench<false, true>);) |
+DEF_BENCH(return (new PMFloatBench< true, false>);) |
+DEF_BENCH(return (new PMFloatBench<false, false>);) |