| 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 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) { | 8 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) { |
| 9 fColors = that.fColors; | 9 fColors = that.fColors; |
| 10 return *this; | 10 return *this; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 inline SkPMColor SkPMFloat::clamped() const { | 34 inline SkPMColor SkPMFloat::clamped() const { |
| 35 // We don't use _mm_cvtps_epi32, because we want precise control over how 0.
5 rounds (up). | 35 // We don't use _mm_cvtps_epi32, because we want precise control over how 0.
5 rounds (up). |
| 36 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors)), | 36 __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), fColors)), |
| 37 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), | 37 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), |
| 38 fix8 = _mm_packus_epi16(fix8_16, fix8_16); | 38 fix8 = _mm_packus_epi16(fix8_16, fix8_16); |
| 39 SkPMColor c = _mm_cvtsi128_si32(fix8); | 39 SkPMColor c = _mm_cvtsi128_si32(fix8); |
| 40 SkPMColorAssert(c); | 40 SkPMColorAssert(c); |
| 41 return c; | 41 return c; |
| 42 } | 42 } |
| 43 | 43 |
| 44 inline SkPMColor SkPMFloat::trunc() const { |
| 45 // Basically, same as clamped(), but no rounding. |
| 46 __m128i fix8_32 = _mm_cvttps_epi32(fColors), |
| 47 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), |
| 48 fix8 = _mm_packus_epi16(fix8_16, fix8_16); |
| 49 SkPMColor c = _mm_cvtsi128_si32(fix8); |
| 50 SkPMColorAssert(c); |
| 51 return c; |
| 52 } |
| 53 |
| 44 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4], | 54 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4], |
| 45 SkPMFloat* a, SkPMFloat* b, SkPMFloat* c, S
kPMFloat* d) { | 55 SkPMFloat* a, SkPMFloat* b, SkPMFloat* c, S
kPMFloat* d) { |
| 46 // Haven't beaten this yet. | 56 // Haven't beaten this yet. |
| 47 *a = FromPMColor(colors[0]); | 57 *a = FromPMColor(colors[0]); |
| 48 *b = FromPMColor(colors[1]); | 58 *b = FromPMColor(colors[1]); |
| 49 *c = FromPMColor(colors[2]); | 59 *c = FromPMColor(colors[2]); |
| 50 *d = FromPMColor(colors[3]); | 60 *d = FromPMColor(colors[3]); |
| 51 } | 61 } |
| 52 | 62 |
| 53 inline void SkPMFloat::To4PMColors( | 63 inline void SkPMFloat::To4PMColors( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 67 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), c.fColors)), | 77 c2 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), c.fColors)), |
| 68 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), d.fColors)); | 78 c3 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), d.fColors)); |
| 69 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), | 79 __m128i c3210 = _mm_packus_epi16(_mm_packus_epi16(c0, c1), |
| 70 _mm_packus_epi16(c2, c3)); | 80 _mm_packus_epi16(c2, c3)); |
| 71 _mm_storeu_si128((__m128i*)colors, c3210); | 81 _mm_storeu_si128((__m128i*)colors, c3210); |
| 72 SkPMColorAssert(colors[0]); | 82 SkPMColorAssert(colors[0]); |
| 73 SkPMColorAssert(colors[1]); | 83 SkPMColorAssert(colors[1]); |
| 74 SkPMColorAssert(colors[2]); | 84 SkPMColorAssert(colors[2]); |
| 75 SkPMColorAssert(colors[3]); | 85 SkPMColorAssert(colors[3]); |
| 76 } | 86 } |
| OLD | NEW |