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

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

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

Powered by Google App Engine
This is Rietveld 408576698