| 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 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo
nents in 32 bits | 8 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo
nents in 32 bits |
| 9 // (fix8_32), then convert those to floats. | 9 // (fix8_32), then convert those to floats. |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 inline SkPMColor SkPMFloat::trunc() const { | 25 inline SkPMColor SkPMFloat::trunc() const { |
| 26 const int _ = 255; // _ means to zero that byte. | 26 const int _ = 255; // _ means to zero that byte. |
| 27 __m128i fix8_32 = _mm_cvttps_epi32(fColors.vec()), | 27 __m128i fix8_32 = _mm_cvttps_epi32(fColors.vec()), |
| 28 fix8 = _mm_shuffle_epi8(fix8_32, _mm_set_epi8(_,_,_,_, _,_,_,_, _
,_,_,_, 12,8,4,0)); | 28 fix8 = _mm_shuffle_epi8(fix8_32, _mm_set_epi8(_,_,_,_, _,_,_,_, _
,_,_,_, 12,8,4,0)); |
| 29 SkPMColor c = _mm_cvtsi128_si32(fix8); | 29 SkPMColor c = _mm_cvtsi128_si32(fix8); |
| 30 SkPMColorAssert(c); | 30 SkPMColorAssert(c); |
| 31 return c; | 31 return c; |
| 32 } | 32 } |
| 33 | 33 |
| 34 inline SkPMColor SkPMFloat::get() const { | 34 inline SkPMColor SkPMFloat::get() const { |
| 35 SkASSERT(this->isValid()); | |
| 36 return SkPMFloat(Sk4f(0.5f) + *this).trunc(); | 35 return SkPMFloat(Sk4f(0.5f) + *this).trunc(); |
| 37 } | 36 } |
| 38 | 37 |
| 39 inline SkPMColor SkPMFloat::clamped() const { | 38 inline SkPMColor SkPMFloat::clamped() const { |
| 40 // We don't use _mm_cvtps_epi32, because we want precise control over how 0.
5 rounds (up). | 39 // We don't use _mm_cvtps_epi32, because we want precise control over how 0.
5 rounds (up). |
| 41 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors.vec
())), | 40 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors.vec
())), |
| 42 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), | 41 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), |
| 43 fix8 = _mm_packus_epi16(fix8_16, fix8_16); | 42 fix8 = _mm_packus_epi16(fix8_16, fix8_16); |
| 44 SkPMColor c = _mm_cvtsi128_si32(fix8); | 43 SkPMColor c = _mm_cvtsi128_si32(fix8); |
| 45 SkPMColorAssert(c); | 44 SkPMColorAssert(c); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 75 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), c.fColors.vec())
), | 74 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), c.fColors.vec())
), |
| 76 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), d.fColors.vec())
); | 75 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), d.fColors.vec())
); |
| 77 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), | 76 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), |
| 78 _mm_packus_epi16(c2, c3)); | 77 _mm_packus_epi16(c2, c3)); |
| 79 _mm_storeu_si128((__m128i*)colors, c3210); | 78 _mm_storeu_si128((__m128i*)colors, c3210); |
| 80 SkPMColorAssert(colors[0]); | 79 SkPMColorAssert(colors[0]); |
| 81 SkPMColorAssert(colors[1]); | 80 SkPMColorAssert(colors[1]); |
| 82 SkPMColorAssert(colors[2]); | 81 SkPMColorAssert(colors[2]); |
| 83 SkPMColorAssert(colors[3]); | 82 SkPMColorAssert(colors[3]); |
| 84 } | 83 } |
| OLD | NEW |