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

Side by Side Diff: src/opts/SkPMFloat_SSE2.h

Issue 1055123002: New names for SkPMFloat methods. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: one more Created 5 years, 8 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 | « src/effects/SkColorMatrixFilter.cpp ('k') | src/opts/SkPMFloat_SSSE3.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 /* 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 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo nents in 16 bits 8 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo nents in 16 bits
9 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver t those to floats. 9 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver t those to floats.
10 10
11 // get() and clamped() do the opposite, working from floats to 8-bit-in-32-bit, 11 // round() and roundClamp() do the opposite, working from floats to 8-bit-in-32- bit,
12 // to 8-bit-in-16-bit, back down to 8-bit components. 12 // to 8-bit-in-16-bit, back down to 8-bit components.
13 // _mm_packus_epi16() gives us clamping for free while narrowing. 13 // _mm_packus_epi16() gives us clamping for free while narrowing.
14 14
15 inline SkPMFloat::SkPMFloat(SkPMColor c) { 15 inline SkPMFloat::SkPMFloat(SkPMColor c) {
16 SkPMColorAssert(c); 16 SkPMColorAssert(c);
17 __m128i fix8 = _mm_set_epi32(0,0,0,c), 17 __m128i fix8 = _mm_set_epi32(0,0,0,c),
18 fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()), 18 fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()),
19 fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128()); 19 fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128());
20 fColors = _mm_cvtepi32_ps(fix8_32); 20 fColors = _mm_cvtepi32_ps(fix8_32);
21 SkASSERT(this->isValid()); 21 SkASSERT(this->isValid());
22 } 22 }
23 23
24 inline SkPMColor SkPMFloat::get() const { 24 inline SkPMColor SkPMFloat::round() const {
25 return this->clamped(); // Haven't beaten this yet. 25 return this->roundClamp(); // Haven't beaten this yet.
26 } 26 }
27 27
28 inline SkPMColor SkPMFloat::clamped() const { 28 inline SkPMColor SkPMFloat::roundClamp() const {
29 // We don't use _mm_cvtps_epi32, because we want precise control over how 0. 5 rounds (up). 29 // We don't use _mm_cvtps_epi32, because we want precise control over how 0. 5 rounds (up).
30 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors.vec ())), 30 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors.vec ())),
31 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), 31 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32),
32 fix8 = _mm_packus_epi16(fix8_16, fix8_16); 32 fix8 = _mm_packus_epi16(fix8_16, fix8_16);
33 SkPMColor c = _mm_cvtsi128_si32(fix8); 33 SkPMColor c = _mm_cvtsi128_si32(fix8);
34 SkPMColorAssert(c); 34 SkPMColorAssert(c);
35 return c; 35 return c;
36 } 36 }
37 37
38 inline SkPMColor SkPMFloat::trunc() const { 38 inline SkPMColor SkPMFloat::trunc() const {
39 // Basically, same as clamped(), but no rounding. 39 // Basically, same as roundClamp(), but no rounding.
40 __m128i fix8_32 = _mm_cvttps_epi32(fColors.vec()), 40 __m128i fix8_32 = _mm_cvttps_epi32(fColors.vec()),
41 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), 41 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32),
42 fix8 = _mm_packus_epi16(fix8_16, fix8_16); 42 fix8 = _mm_packus_epi16(fix8_16, fix8_16);
43 SkPMColor c = _mm_cvtsi128_si32(fix8); 43 SkPMColor c = _mm_cvtsi128_si32(fix8);
44 SkPMColorAssert(c); 44 SkPMColorAssert(c);
45 return c; 45 return c;
46 } 46 }
47 47
48 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4], 48 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4],
49 SkPMFloat* a, SkPMFloat* b, SkPMFloat* c, S kPMFloat* d) { 49 SkPMFloat* a, SkPMFloat* b, SkPMFloat* c, S kPMFloat* d) {
50 // Haven't beaten this yet. 50 // Haven't beaten this yet.
51 *a = FromPMColor(colors[0]); 51 *a = FromPMColor(colors[0]);
52 *b = FromPMColor(colors[1]); 52 *b = FromPMColor(colors[1]);
53 *c = FromPMColor(colors[2]); 53 *c = FromPMColor(colors[2]);
54 *d = FromPMColor(colors[3]); 54 *d = FromPMColor(colors[3]);
55 } 55 }
56 56
57 inline void SkPMFloat::To4PMColors( 57 inline void SkPMFloat::RoundTo4PMColors(
58 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo at& d, 58 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo at& d,
59 SkPMColor colors[4]) { 59 SkPMColor colors[4]) {
60 // Haven't beaten this yet. 60 // Haven't beaten this yet.
61 ClampTo4PMColors(a,b,c,d, colors); 61 RoundClampTo4PMColors(a,b,c,d, colors);
62 } 62 }
63 63
64 inline void SkPMFloat::ClampTo4PMColors( 64 inline void SkPMFloat::RoundClampTo4PMColors(
65 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo at& d, 65 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo at& d,
66 SkPMColor colors[4]) { 66 SkPMColor colors[4]) {
67 // Same as _SSSE3.h's. We use 3 _mm_packus_epi16() where the naive loop use s 8. 67 // Same as _SSSE3.h's. We use 3 _mm_packus_epi16() where the naive loop use s 8.
68 // We don't use _mm_cvtps_epi32, because we want precise control over how 0. 5 rounds (up). 68 // We don't use _mm_cvtps_epi32, because we want precise control over how 0. 5 rounds (up).
69 __m128i c0 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), a.fColors.vec()) ), 69 __m128i c0 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), a.fColors.vec()) ),
70 c1 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), b.fColors.vec()) ), 70 c1 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), b.fColors.vec()) ),
71 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), c.fColors.vec()) ), 71 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), c.fColors.vec()) ),
72 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), d.fColors.vec()) ); 72 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), d.fColors.vec()) );
73 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), 73 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1),
74 _mm_packus_epi16(c2, c3)); 74 _mm_packus_epi16(c2, c3));
75 _mm_storeu_si128((__m128i*)colors, c3210); 75 _mm_storeu_si128((__m128i*)colors, c3210);
76 SkPMColorAssert(colors[0]); 76 SkPMColorAssert(colors[0]);
77 SkPMColorAssert(colors[1]); 77 SkPMColorAssert(colors[1]);
78 SkPMColorAssert(colors[2]); 78 SkPMColorAssert(colors[2]);
79 SkPMColorAssert(colors[3]); 79 SkPMColorAssert(colors[3]);
80 } 80 }
OLDNEW
« no previous file with comments | « src/effects/SkColorMatrixFilter.cpp ('k') | src/opts/SkPMFloat_SSSE3.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698