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

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

Issue 1029163002: Replace _mm_cvtps_epi32(x) with _mm_cvttps_epi32(_mm_add_ps(0.5f), x). (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: tweak test 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 | « src/opts/Sk4x_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 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) { 1 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) {
2 fColors = that.fColors; 2 fColors = that.fColors;
3 return *this; 3 return *this;
4 } 4 }
5 5
6 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo nents in 16 bits 6 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo nents in 16 bits
7 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver t those to floats. 7 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver t those to floats.
8 8
9 // get() and clamped() do the opposite, working from floats to 8-bit-in-32-bit, 9 // get() and clamped() do the opposite, working from floats to 8-bit-in-32-bit,
10 // to 8-bit-in-16-bit, back down to 8-bit components. 10 // to 8-bit-in-16-bit, back down to 8-bit components.
11 // _mm_packus_epi16() gives us clamping for free while narrowing. 11 // _mm_packus_epi16() gives us clamping for free while narrowing.
12 12
13 inline SkPMFloat::SkPMFloat(SkPMColor c) { 13 inline SkPMFloat::SkPMFloat(SkPMColor c) {
14 SkPMColorAssert(c); 14 SkPMColorAssert(c);
15 __m128i fix8 = _mm_set_epi32(0,0,0,c), 15 __m128i fix8 = _mm_set_epi32(0,0,0,c),
16 fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()), 16 fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()),
17 fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128()); 17 fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128());
18 fColors = _mm_cvtepi32_ps(fix8_32); 18 fColors = _mm_cvtepi32_ps(fix8_32);
19 SkASSERT(this->isValid()); 19 SkASSERT(this->isValid());
20 } 20 }
21 21
22 inline SkPMColor SkPMFloat::get() const { 22 inline SkPMColor SkPMFloat::get() const {
23 SkASSERT(this->isValid()); 23 SkASSERT(this->isValid());
24 return this->clamped(); // Haven't beaten this yet. 24 return this->clamped(); // Haven't beaten this yet.
25 } 25 }
26 26
27 inline SkPMColor SkPMFloat::clamped() const { 27 inline SkPMColor SkPMFloat::clamped() const {
28 __m128i fix8_32 = _mm_cvtps_epi32(fColors), // _mm_cvtps_epi32 rounds for u s! 28 // We don't use _mm_cvtps_epi32, because we want precise control over how 0. 5 rounds (up).
29 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors)),
29 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), 30 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32),
30 fix8 = _mm_packus_epi16(fix8_16, fix8_16); 31 fix8 = _mm_packus_epi16(fix8_16, fix8_16);
31 SkPMColor c = _mm_cvtsi128_si32(fix8); 32 SkPMColor c = _mm_cvtsi128_si32(fix8);
32 SkPMColorAssert(c); 33 SkPMColorAssert(c);
33 return c; 34 return c;
34 } 35 }
35 36
36 inline void SkPMFloat::From4PMColors(SkPMFloat floats[4], const SkPMColor colors [4]) { 37 inline void SkPMFloat::From4PMColors(SkPMFloat floats[4], const SkPMColor colors [4]) {
37 // Haven't beaten this yet. 38 // Haven't beaten this yet.
38 for (int i = 0; i < 4; i++) { floats[i] = FromPMColor(colors[i]); } 39 for (int i = 0; i < 4; i++) { floats[i] = FromPMColor(colors[i]); }
39 } 40 }
40 41
41 inline void SkPMFloat::To4PMColors(SkPMColor colors[4], const SkPMFloat floats[4 ]) { 42 inline void SkPMFloat::To4PMColors(SkPMColor colors[4], const SkPMFloat floats[4 ]) {
42 SkASSERT(floats[0].isValid() && floats[1].isValid() 43 SkASSERT(floats[0].isValid() && floats[1].isValid()
43 && floats[2].isValid() && floats[3].isValid()); 44 && floats[2].isValid() && floats[3].isValid());
44 // Haven't beaten this yet. 45 // Haven't beaten this yet.
45 ClampTo4PMColors(colors, floats); 46 ClampTo4PMColors(colors, floats);
46 } 47 }
47 48
48 inline void SkPMFloat::ClampTo4PMColors(SkPMColor colors[4], const SkPMFloat flo ats[4]) { 49 inline void SkPMFloat::ClampTo4PMColors(SkPMColor colors[4], const SkPMFloat flo ats[4]) {
49 // Same as _SSSE3.h's. We use 3 _mm_packus_epi16() where the naive loop use s 8. 50 // Same as _SSSE3.h's. We use 3 _mm_packus_epi16() where the naive loop use s 8.
50 __m128i c0 = _mm_cvtps_epi32(floats[0].fColors), // _mm_cvtps_epi32 rounds for us! 51 // We don't use _mm_cvtps_epi32, because we want precise control over how 0. 5 rounds (up).
51 c1 = _mm_cvtps_epi32(floats[1].fColors), 52 __m128i c0 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), floats[0].fColor s)),
52 c2 = _mm_cvtps_epi32(floats[2].fColors), 53 c1 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), floats[1].fColor s)),
53 c3 = _mm_cvtps_epi32(floats[3].fColors); 54 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), floats[2].fColor s)),
55 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), floats[3].fColor s));
54 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), 56 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1),
55 _mm_packus_epi16(c2, c3)); 57 _mm_packus_epi16(c2, c3));
56 _mm_storeu_si128((__m128i*)colors, c3210); 58 _mm_storeu_si128((__m128i*)colors, c3210);
57 SkPMColorAssert(colors[0]); 59 SkPMColorAssert(colors[0]);
58 SkPMColorAssert(colors[1]); 60 SkPMColorAssert(colors[1]);
59 SkPMColorAssert(colors[2]); 61 SkPMColorAssert(colors[2]);
60 SkPMColorAssert(colors[3]); 62 SkPMColorAssert(colors[3]);
61 } 63 }
OLDNEW
« no previous file with comments | « src/opts/Sk4x_sse.h ('k') | src/opts/SkPMFloat_SSSE3.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698