Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: bench/PMFloatBench.cpp

Issue 1035583002: Update 4-at-a-time APIs. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: (C) Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkPMFloat.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
1 #include "Benchmark.h" 8 #include "Benchmark.h"
2 #include "SkPMFloat.h" 9 #include "SkPMFloat.h"
3 10
4 // Used to prevent the compiler from optimizing away the whole loop. 11 // Used to prevent the compiler from optimizing away the whole loop.
5 volatile uint32_t blackhole = 0; 12 volatile uint32_t blackhole = 0;
6 13
7 // Not a great random number generator, but it's very fast. 14 // Not a great random number generator, but it's very fast.
8 // 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.
9 static uint32_t lcg_rand(uint32_t* seed) { 16 static uint32_t lcg_rand(uint32_t* seed) {
10 *seed *= 1664525; 17 *seed *= 1664525;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 49 }
43 #else 50 #else
44 // But it's a lot faster not to, and this code won't really mind the non-PM colors. 51 // But it's a lot faster not to, and this code won't really mind the non-PM colors.
45 (void)lcg_rand(&seed); 52 (void)lcg_rand(&seed);
46 colors[0] = seed + 0; 53 colors[0] = seed + 0;
47 colors[1] = seed + 1; 54 colors[1] = seed + 1;
48 colors[2] = seed + 2; 55 colors[2] = seed + 2;
49 colors[3] = seed + 3; 56 colors[3] = seed + 3;
50 #endif 57 #endif
51 58
52 SkPMFloat floats[4]; 59 SkPMFloat fa,fb,fc,fd;
53 if (kWide) { 60 if (kWide) {
54 SkPMFloat::From4PMColors(floats, colors); 61 SkPMFloat::From4PMColors(colors, &fa, &fb, &fc, &fd);
55 } else { 62 } else {
56 for (int i = 0; i < 4; i++) { 63 fa = SkPMFloat::FromPMColor(colors[0]);
57 floats[i] = SkPMFloat::FromPMColor(colors[i]); 64 fb = SkPMFloat::FromPMColor(colors[1]);
58 } 65 fc = SkPMFloat::FromPMColor(colors[2]);
66 fd = SkPMFloat::FromPMColor(colors[3]);
59 } 67 }
60 68
61 SkPMColor back[4]; 69 SkPMColor back[4];
62 switch (kClamp << 1 | kWide) { 70 switch (kClamp << 1 | kWide) {
63 case 0: for (int i = 0; i < 4; i++) { back[i] = floats[i].get(); } break; 71 case 0: {
64 case 1: SkPMFloat::To4PMColors(back, floats); break; 72 back[0] = fa.get();
65 case 2: for (int i = 0; i < 4; i++) { back[i] = floats[i].clampe d(); } break; 73 back[1] = fb.get();
66 case 3: SkPMFloat::ClampTo4PMColors(back, floats); break; 74 back[2] = fc.get();
75 back[3] = fd.get();
76 } break;
77 case 1: SkPMFloat::To4PMColors(fa, fb, fc, fd, back); break;
78 case 2: {
79 back[0] = fa.clamped();
80 back[1] = fb.clamped();
81 back[2] = fc.clamped();
82 back[3] = fd.clamped();
83 } break;
84 case 3: SkPMFloat::ClampTo4PMColors(fa, fb, fc, fd, back); break ;
67 } 85 }
68 for (int i = 0; i < 4; i++) { 86 for (int i = 0; i < 4; i++) {
69 junk ^= back[i]; 87 junk ^= back[i];
70 } 88 }
71 } 89 }
72 blackhole ^= junk; 90 blackhole ^= junk;
73 } 91 }
74 }; 92 };
75 93
76 // 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 <>.
77 DEF_BENCH(return (new PMFloatBench< true, true>);) 95 DEF_BENCH(return (new PMFloatBench< true, true>);)
78 DEF_BENCH(return (new PMFloatBench<false, true>);) 96 DEF_BENCH(return (new PMFloatBench<false, true>);)
79 DEF_BENCH(return (new PMFloatBench< true, false>);) 97 DEF_BENCH(return (new PMFloatBench< true, false>);)
80 DEF_BENCH(return (new PMFloatBench<false, false>);) 98 DEF_BENCH(return (new PMFloatBench<false, false>);)
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPMFloat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698