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

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

Issue 1032243002: SkPMFloat::trunc() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove isValid assert in _none trunc() 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/SkPMFloat_SSE2.h ('k') | src/opts/SkPMFloat_neon.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) { 8 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) {
9 fColors = that.fColors; 9 fColors = that.fColors;
10 return *this; 10 return *this;
11 } 11 }
12 12
13 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo nents in 32 bits 13 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo nents in 32 bits
14 // (fix8_32), then convert those to floats. 14 // (fix8_32), then convert those to floats.
15 15
16 // get() does the opposite, working from floats to 8-bit-in-32-bits, then back t o packed 8 bit. 16 // get() does the opposite, working from floats to 8-bit-in-32-bits, then back t o packed 8 bit.
17 17
18 // clamped() is the same as _SSE2: floats to 8-in-32, to 8-in-16, to packed 8 bi t, with 18 // clamped() is the same as _SSE2: floats to 8-in-32, to 8-in-16, to packed 8 bi t, with
19 // _mm_packus_epi16() both clamping and narrowing. 19 // _mm_packus_epi16() both clamping and narrowing.
20 20
21 inline SkPMFloat::SkPMFloat(SkPMColor c) { 21 inline SkPMFloat::SkPMFloat(SkPMColor c) {
22 SkPMColorAssert(c); 22 SkPMColorAssert(c);
23 const int _ = 255; // _ means to zero that byte. 23 const int _ = 255; // _ means to zero that byte.
24 __m128i fix8 = _mm_set_epi32(0,0,0,c), 24 __m128i fix8 = _mm_set_epi32(0,0,0,c),
25 fix8_32 = _mm_shuffle_epi8(fix8, _mm_set_epi8(_,_,_,3, _,_,_,2, _,_, _,1, _,_,_,0)); 25 fix8_32 = _mm_shuffle_epi8(fix8, _mm_set_epi8(_,_,_,3, _,_,_,2, _,_, _,1, _,_,_,0));
26 fColors = _mm_cvtepi32_ps(fix8_32); 26 fColors = _mm_cvtepi32_ps(fix8_32);
27 SkASSERT(this->isValid()); 27 SkASSERT(this->isValid());
28 } 28 }
29 29
30 inline SkPMColor SkPMFloat::get() const { 30 inline SkPMColor SkPMFloat::trunc() const {
31 SkASSERT(this->isValid());
32 const int _ = 255; // _ means to zero that byte. 31 const int _ = 255; // _ means to zero that byte.
33 // We don't use _mm_cvtps_epi32, because we want precise control over how 0. 5 rounds (up). 32 __m128i fix8_32 = _mm_cvttps_epi32(fColors),
34 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors)),
35 fix8 = _mm_shuffle_epi8(fix8_32, _mm_set_epi8(_,_,_,_, _,_,_,_, _ ,_,_,_, 12,8,4,0)); 33 fix8 = _mm_shuffle_epi8(fix8_32, _mm_set_epi8(_,_,_,_, _,_,_,_, _ ,_,_,_, 12,8,4,0));
36 SkPMColor c = _mm_cvtsi128_si32(fix8); 34 SkPMColor c = _mm_cvtsi128_si32(fix8);
37 SkPMColorAssert(c); 35 SkPMColorAssert(c);
38 return c; 36 return c;
39 } 37 }
40 38
39 inline SkPMColor SkPMFloat::get() const {
40 SkASSERT(this->isValid());
41 return SkPMFloat(Sk4f(0.5f) + *this).trunc();
42 }
43
41 inline SkPMColor SkPMFloat::clamped() const { 44 inline SkPMColor SkPMFloat::clamped() const {
42 // We don't use _mm_cvtps_epi32, because we want precise control over how 0. 5 rounds (up). 45 // We don't use _mm_cvtps_epi32, because we want precise control over how 0. 5 rounds (up).
43 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors)), 46 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors)),
44 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), 47 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32),
45 fix8 = _mm_packus_epi16(fix8_16, fix8_16); 48 fix8 = _mm_packus_epi16(fix8_16, fix8_16);
46 SkPMColor c = _mm_cvtsi128_si32(fix8); 49 SkPMColor c = _mm_cvtsi128_si32(fix8);
47 SkPMColorAssert(c); 50 SkPMColorAssert(c);
48 return c; 51 return c;
49 } 52 }
50 53
(...skipping 26 matching lines...) Expand all
77 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), c.fColors)), 80 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), c.fColors)),
78 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), d.fColors)); 81 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), d.fColors));
79 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), 82 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1),
80 _mm_packus_epi16(c2, c3)); 83 _mm_packus_epi16(c2, c3));
81 _mm_storeu_si128((__m128i*)colors, c3210); 84 _mm_storeu_si128((__m128i*)colors, c3210);
82 SkPMColorAssert(colors[0]); 85 SkPMColorAssert(colors[0]);
83 SkPMColorAssert(colors[1]); 86 SkPMColorAssert(colors[1]);
84 SkPMColorAssert(colors[2]); 87 SkPMColorAssert(colors[2]);
85 SkPMColorAssert(colors[3]); 88 SkPMColorAssert(colors[3]);
86 } 89 }
OLDNEW
« no previous file with comments | « src/opts/SkPMFloat_SSE2.h ('k') | src/opts/SkPMFloat_neon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698