OLD | NEW |
1 #include "SkColorPriv.h" | 1 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) { |
2 #include <emmintrin.h> | 2 fColors = that.fColors; |
| 3 return *this; |
| 4 } |
3 | 5 |
4 // 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 |
5 // (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. |
6 | 8 |
7 // 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, |
8 // 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. |
9 // _mm_packus_epi16() gives us clamping for free while narrowing. | 11 // _mm_packus_epi16() gives us clamping for free while narrowing. |
10 | 12 |
11 inline SkPMFloat::SkPMFloat(SkPMColor c) { | 13 inline SkPMFloat::SkPMFloat(SkPMColor c) { |
12 SkPMColorAssert(c); | 14 SkPMColorAssert(c); |
13 __m128i fix8 = _mm_set_epi32(0,0,0,c), | 15 __m128i fix8 = _mm_set_epi32(0,0,0,c), |
14 fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()), | 16 fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()), |
15 fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128()); | 17 fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128()); |
16 _mm_store_ps(fColor, _mm_cvtepi32_ps(fix8_32)); | 18 fColors = _mm_cvtepi32_ps(fix8_32); |
17 SkASSERT(this->isValid()); | 19 SkASSERT(this->isValid()); |
18 } | 20 } |
19 | 21 |
20 inline SkPMColor SkPMFloat::get() const { | 22 inline SkPMColor SkPMFloat::get() const { |
21 SkASSERT(this->isValid()); | 23 SkASSERT(this->isValid()); |
22 return this->clamped(); // Haven't beaten this yet. | 24 return this->clamped(); // Haven't beaten this yet. |
23 } | 25 } |
24 | 26 |
25 inline SkPMColor SkPMFloat::clamped() const { | 27 inline SkPMColor SkPMFloat::clamped() const { |
26 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32
rounds for us! | 28 __m128i fix8_32 = _mm_cvtps_epi32(fColors), // _mm_cvtps_epi32 rounds for u
s! |
27 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), | 29 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), |
28 fix8 = _mm_packus_epi16(fix8_16, fix8_16); | 30 fix8 = _mm_packus_epi16(fix8_16, fix8_16); |
29 SkPMColor c = _mm_cvtsi128_si32(fix8); | 31 SkPMColor c = _mm_cvtsi128_si32(fix8); |
30 SkPMColorAssert(c); | 32 SkPMColorAssert(c); |
31 return c; | 33 return c; |
32 } | 34 } |
33 | 35 |
34 inline void SkPMFloat::From4PMColors(SkPMFloat floats[4], const SkPMColor colors
[4]) { | 36 inline void SkPMFloat::From4PMColors(SkPMFloat floats[4], const SkPMColor colors
[4]) { |
35 // Haven't beaten this yet. | 37 // Haven't beaten this yet. |
36 for (int i = 0; i < 4; i++) { floats[i] = FromPMColor(colors[i]); } | 38 for (int i = 0; i < 4; i++) { floats[i] = FromPMColor(colors[i]); } |
37 } | 39 } |
38 | 40 |
39 inline void SkPMFloat::To4PMColors(SkPMColor colors[4], const SkPMFloat floats[4
]) { | 41 inline void SkPMFloat::To4PMColors(SkPMColor colors[4], const SkPMFloat floats[4
]) { |
40 SkASSERT(floats[0].isValid() && floats[1].isValid() | 42 SkASSERT(floats[0].isValid() && floats[1].isValid() |
41 && floats[2].isValid() && floats[3].isValid()); | 43 && floats[2].isValid() && floats[3].isValid()); |
42 // Haven't beaten this yet. | 44 // Haven't beaten this yet. |
43 ClampTo4PMColors(colors, floats); | 45 ClampTo4PMColors(colors, floats); |
44 } | 46 } |
45 | 47 |
46 inline void SkPMFloat::ClampTo4PMColors(SkPMColor colors[4], const SkPMFloat flo
ats[4]) { | 48 inline void SkPMFloat::ClampTo4PMColors(SkPMColor colors[4], const SkPMFloat flo
ats[4]) { |
47 // Same as _SSSE3.h's. We use 3 _mm_packus_epi16() where the naive loop use
s 8. | 49 // Same as _SSSE3.h's. We use 3 _mm_packus_epi16() where the naive loop use
s 8. |
48 __m128i c0 = _mm_cvtps_epi32(_mm_load_ps(floats[0].fColor)), // _mm_cvtps_e
pi32 rounds for us! | 50 __m128i c0 = _mm_cvtps_epi32(floats[0].fColors), // _mm_cvtps_epi32 rounds
for us! |
49 c1 = _mm_cvtps_epi32(_mm_load_ps(floats[1].fColor)), | 51 c1 = _mm_cvtps_epi32(floats[1].fColors), |
50 c2 = _mm_cvtps_epi32(_mm_load_ps(floats[2].fColor)), | 52 c2 = _mm_cvtps_epi32(floats[2].fColors), |
51 c3 = _mm_cvtps_epi32(_mm_load_ps(floats[3].fColor)); | 53 c3 = _mm_cvtps_epi32(floats[3].fColors); |
52 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), | 54 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), |
53 _mm_packus_epi16(c2, c3)); | 55 _mm_packus_epi16(c2, c3)); |
54 _mm_storeu_si128((__m128i*)colors, c3210); | 56 _mm_storeu_si128((__m128i*)colors, c3210); |
55 SkPMColorAssert(colors[0]); | 57 SkPMColorAssert(colors[0]); |
56 SkPMColorAssert(colors[1]); | 58 SkPMColorAssert(colors[1]); |
57 SkPMColorAssert(colors[2]); | 59 SkPMColorAssert(colors[2]); |
58 SkPMColorAssert(colors[3]); | 60 SkPMColorAssert(colors[3]); |
59 } | 61 } |
OLD | NEW |