OLD | NEW |
1 #include "SkColorPriv.h" | 1 #include "SkColorPriv.h" |
2 #include <tmmintrin.h> | 2 #include <tmmintrin.h> |
3 | 3 |
4 // For set(), we widen our 8 bit components (fix8) to 8-bit components in 32 bit
s (fix8_32), | 4 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo
nents in 32 bits |
5 // then convert those to floats. | 5 // (fix8_32), then convert those to floats. |
6 | 6 |
7 // get() does the opposite, working from floats to 8-bit-in-32-bits, then back t
o packed 8 bit. | 7 // get() does the opposite, working from floats to 8-bit-in-32-bits, then back t
o packed 8 bit. |
8 | 8 |
9 // clamped() is the same as _SSE2: floats to 8-in-32, to 8-in-16, to packed 8 bi
t, with | 9 // clamped() is the same as _SSE2: floats to 8-in-32, to 8-in-16, to packed 8 bi
t, with |
10 // _mm_packus_epi16() both clamping and narrowing. | 10 // _mm_packus_epi16() both clamping and narrowing. |
11 | 11 |
12 inline void SkPMFloat::set(SkPMColor c) { | 12 inline SkPMFloat::SkPMFloat(SkPMColor c) { |
13 SkPMColorAssert(c); | 13 SkPMColorAssert(c); |
14 const int _ = 255; // _ means to zero that byte. | 14 const int _ = 255; // _ means to zero that byte. |
15 __m128i fix8 = _mm_set_epi32(0,0,0,c), | 15 __m128i fix8 = _mm_set_epi32(0,0,0,c), |
16 fix8_32 = _mm_shuffle_epi8(fix8, _mm_set_epi8(_,_,_,3, _,_,_,2, _,_,
_,1, _,_,_,0)); | 16 fix8_32 = _mm_shuffle_epi8(fix8, _mm_set_epi8(_,_,_,3, _,_,_,2, _,_,
_,1, _,_,_,0)); |
17 _mm_store_ps(fColor, _mm_cvtepi32_ps(fix8_32)); | 17 _mm_store_ps(fColor, _mm_cvtepi32_ps(fix8_32)); |
18 SkASSERT(this->isValid()); | 18 SkASSERT(this->isValid()); |
19 } | 19 } |
20 | 20 |
21 inline SkPMColor SkPMFloat::get() const { | 21 inline SkPMColor SkPMFloat::get() const { |
22 SkASSERT(this->isValid()); | 22 SkASSERT(this->isValid()); |
23 const int _ = 255; // _ means to zero that byte. | 23 const int _ = 255; // _ means to zero that byte. |
24 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32
rounds for us! | 24 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32
rounds for us! |
25 fix8 = _mm_shuffle_epi8(fix8_32, _mm_set_epi8(_,_,_,_, _,_,_,_, _
,_,_,_, 12,8,4,0)); | 25 fix8 = _mm_shuffle_epi8(fix8_32, _mm_set_epi8(_,_,_,_, _,_,_,_, _
,_,_,_, 12,8,4,0)); |
26 SkPMColor c = _mm_cvtsi128_si32(fix8); | 26 SkPMColor c = _mm_cvtsi128_si32(fix8); |
27 SkPMColorAssert(c); | 27 SkPMColorAssert(c); |
28 return c; | 28 return c; |
29 } | 29 } |
30 | 30 |
31 inline SkPMColor SkPMFloat::clamped() const { | 31 inline SkPMColor SkPMFloat::clamped() const { |
32 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32
rounds for us! | 32 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32
rounds for us! |
33 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), | 33 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), |
34 fix8 = _mm_packus_epi16(fix8_16, fix8_16); | 34 fix8 = _mm_packus_epi16(fix8_16, fix8_16); |
35 SkPMColor c = _mm_cvtsi128_si32(fix8); | 35 SkPMColor c = _mm_cvtsi128_si32(fix8); |
36 SkPMColorAssert(c); | 36 SkPMColorAssert(c); |
37 return c; | 37 return c; |
38 } | 38 } |
OLD | NEW |