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 "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkNx.h" | 10 #include "SkNx.h" |
11 | 11 |
12 // Used to prevent the compiler from optimizing away the whole loop. | 12 // Used to prevent the compiler from optimizing away the whole loop. |
13 volatile uint32_t blackhole = 0; | 13 volatile uint64_t blackhole = 0; |
14 | 14 |
15 // Not a great random number generator, but it's very fast. | 15 // Not a great random number generator, but it's very fast. |
16 // The code we're measuring is quite fast, so low overhead is essential. | 16 // The code we're measuring is quite fast, so low overhead is essential. |
17 static uint32_t lcg_rand(uint32_t* seed) { | 17 static uint64_t lcg_rand(uint64_t* seed) { |
18 *seed *= 1664525; | 18 *seed *= 1664525; |
19 *seed += 1013904223; | 19 *seed += 1013904223; |
20 return *seed; | 20 return *seed; |
21 } | 21 } |
22 | 22 |
23 struct Sk4fBytesRoundtripBench : public Benchmark { | 23 template <typename T> |
24 Sk4fBytesRoundtripBench() {} | 24 struct Sk4fRoundtripBench : public Benchmark { |
| 25 Sk4fRoundtripBench() {} |
25 | 26 |
26 const char* onGetName() override { return "Sk4f_roundtrip"; } | 27 const char* onGetName() override { |
| 28 switch (sizeof(T)) { |
| 29 case 1: return "Sk4f_roundtrip_u8"; |
| 30 case 2: return "Sk4f_roundtrip_u16"; |
| 31 } |
| 32 SkASSERT(false); |
| 33 return ""; |
| 34 } |
| 35 |
27 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } | 36 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } |
28 | 37 |
29 void onDraw(int loops, SkCanvas* canvas) override { | 38 void onDraw(int loops, SkCanvas* canvas) override { |
30 // Unlike blackhole, junk can and probably will be a register. | 39 // Unlike blackhole, junk can and probably will be a register. |
31 uint32_t junk = 0; | 40 uint64_t junk = 0; |
32 uint32_t seed = 0; | 41 uint64_t seed = 0; |
33 for (int i = 0; i < loops; i++) { | 42 for (int i = 0; i < loops; i++) { |
34 uint32_t color = lcg_rand(&seed), | 43 uint64_t src = lcg_rand(&seed), |
35 back; | 44 back; |
36 auto f = SkNx_cast<float>(Sk4b::Load(&color)); | 45 auto f = SkNx_cast<float>(SkNx<4,T>::Load(&src)); |
37 SkNx_cast<uint8_t>(f).store(&back); | 46 SkNx_cast<T>(f).store(&back); |
38 junk ^= back; | 47 junk ^= back; |
39 } | 48 } |
40 blackhole ^= junk; | 49 blackhole ^= junk; |
41 } | 50 } |
42 }; | 51 }; |
43 DEF_BENCH(return new Sk4fBytesRoundtripBench;) | 52 DEF_BENCH(return new Sk4fRoundtripBench<uint8_t>;) |
| 53 DEF_BENCH(return new Sk4fRoundtripBench<uint16_t>;) |
44 | 54 |
45 struct Sk4fGradientBench : public Benchmark { | 55 struct Sk4fGradientBench : public Benchmark { |
46 const char* onGetName() override { return "Sk4f_gradient"; } | 56 const char* onGetName() override { return "Sk4f_gradient"; } |
47 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } | 57 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi
ng_Backend; } |
48 | 58 |
49 SkPMColor fDevice[100]; | 59 SkPMColor fDevice[100]; |
50 void onDraw(int loops, SkCanvas*) override { | 60 void onDraw(int loops, SkCanvas*) override { |
51 Sk4f c0(0,0,255,255), | 61 Sk4f c0(0,0,255,255), |
52 c1(255,0,0,255), | 62 c1(255,0,0,255), |
53 dc = c1 - c0, | 63 dc = c1 - c0, |
(...skipping 11 matching lines...) Expand all Loading... |
65 Sk4f_ToBytes((uint8_t*)(fDevice+i), a, b, c, d); | 75 Sk4f_ToBytes((uint8_t*)(fDevice+i), a, b, c, d); |
66 a = a + dcdx4; | 76 a = a + dcdx4; |
67 b = b + dcdx4; | 77 b = b + dcdx4; |
68 c = c + dcdx4; | 78 c = c + dcdx4; |
69 d = d + dcdx4; | 79 d = d + dcdx4; |
70 } | 80 } |
71 } | 81 } |
72 } | 82 } |
73 }; | 83 }; |
74 DEF_BENCH(return new Sk4fGradientBench;) | 84 DEF_BENCH(return new Sk4fGradientBench;) |
OLD | NEW |