OLD | NEW |
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 SK_ALWAYS_INLINE SkPMFloat::SkPMFloat(SkPMColor c) { | 8 namespace { // See SkPMFloat.h |
| 9 |
| 10 inline SkPMFloat::SkPMFloat(SkPMColor c) { |
9 SkPMColorAssert(c); | 11 SkPMColorAssert(c); |
10 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 | 12 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 |
11 const int _ = 255; // Zero these bytes. | 13 const int _ = 255; // Zero these bytes. |
12 __m128i fix8 = _mm_cvtsi32_si128((int)c), | 14 __m128i fix8 = _mm_cvtsi32_si128((int)c), |
13 fix8_32 = _mm_shuffle_epi8(fix8, _mm_setr_epi8(0,_,_,_, 1,_,_,_, 2,_
,_,_, 3,_,_,_)); | 15 fix8_32 = _mm_shuffle_epi8(fix8, _mm_setr_epi8(0,_,_,_, 1,_,_,_, 2,_
,_,_, 3,_,_,_)); |
14 #else | 16 #else |
15 __m128i fix8 = _mm_cvtsi32_si128((int)c), | 17 __m128i fix8 = _mm_cvtsi32_si128((int)c), |
16 fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()), | 18 fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()), |
17 fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128()); | 19 fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128()); |
18 #endif | 20 #endif |
19 fVec = _mm_mul_ps(_mm_cvtepi32_ps(fix8_32), _mm_set1_ps(1.0f / 255)); | 21 fVec = _mm_mul_ps(_mm_cvtepi32_ps(fix8_32), _mm_set1_ps(1.0f / 255)); |
20 SkASSERT(this->isValid()); | 22 SkASSERT(this->isValid()); |
21 } | 23 } |
22 | 24 |
23 SK_ALWAYS_INLINE SkPMColor SkPMFloat::round() const { | 25 inline SkPMColor SkPMFloat::round() const { |
24 // We don't use _mm_cvtps_epi32, because we want precise control over how 0.
5 rounds (up). | 26 // We don't use _mm_cvtps_epi32, because we want precise control over how 0.
5 rounds (up). |
25 __m128 scaled = _mm_mul_ps(_mm_set1_ps(255), fVec); | 27 __m128 scaled = _mm_mul_ps(_mm_set1_ps(255), fVec); |
26 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), scaled)), | 28 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), scaled)), |
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 SK_ALWAYS_INLINE Sk4f SkPMFloat::alphas() const { | 36 inline Sk4f SkPMFloat::alphas() const { |
35 static_assert(SK_A32_SHIFT == 24, ""); | 37 static_assert(SK_A32_SHIFT == 24, ""); |
36 return _mm_shuffle_ps(fVec, fVec, 0xff); // Read as 11 11 11 11, copying la
ne 3 to all lanes. | 38 return _mm_shuffle_ps(fVec, fVec, 0xff); // Read as 11 11 11 11, copying la
ne 3 to all lanes. |
37 } | 39 } |
| 40 |
| 41 } // namespace |
OLD | NEW |