OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The Android Open Source Project | 2 * Copyright 2014 The Android Open Source Project |
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 #ifndef SkColor_opts_SSE2_DEFINED | 8 #ifndef SkColor_opts_SSE2_DEFINED |
9 #define SkColor_opts_SSE2_DEFINED | 9 #define SkColor_opts_SSE2_DEFINED |
10 | 10 |
11 #include <emmintrin.h> | 11 #include <emmintrin.h> |
12 | 12 |
| 13 // Because no _mm_mul_epi32() in SSE2, we emulate it here. |
| 14 // Multiplies 4 32-bit integers from a by 4 32-bit intergers from b. |
| 15 // The 4 multiplication results should be represented within 32-bit |
| 16 // integers, otherwise they would be overflow. |
| 17 static inline __m128i Multiply32_SSE2(const __m128i& a, const __m128i& b) { |
| 18 // Calculate results of a0 * b0 and a2 * b2. |
| 19 __m128i r1 = _mm_mul_epu32(a, b); |
| 20 // Calculate results of a1 * b1 and a3 * b3. |
| 21 __m128i r2 = _mm_mul_epu32(_mm_srli_si128(a, 4), _mm_srli_si128(b, 4)); |
| 22 // Shuffle results to [63..0] and interleave the results. |
| 23 __m128i r = _mm_unpacklo_epi32(_mm_shuffle_epi32(r1, _MM_SHUFFLE(0,0,2,0)), |
| 24 _mm_shuffle_epi32(r2, _MM_SHUFFLE(0,0,2,0))); |
| 25 return r; |
| 26 } |
| 27 |
13 static inline __m128i SkAlpha255To256_SSE2(const __m128i& alpha) { | 28 static inline __m128i SkAlpha255To256_SSE2(const __m128i& alpha) { |
14 return _mm_add_epi32(alpha, _mm_set1_epi32(1)); | 29 return _mm_add_epi32(alpha, _mm_set1_epi32(1)); |
15 } | 30 } |
16 | 31 |
17 // See #define SkAlphaMulAlpha(a, b) SkMulDiv255Round(a, b) in SkXfermode.cpp. | 32 // See #define SkAlphaMulAlpha(a, b) SkMulDiv255Round(a, b) in SkXfermode.cpp. |
18 static inline __m128i SkAlphaMulAlpha_SSE2(const __m128i& a, | 33 static inline __m128i SkAlphaMulAlpha_SSE2(const __m128i& a, |
19 const __m128i& b) { | 34 const __m128i& b) { |
20 __m128i prod = _mm_mullo_epi16(a, b); | 35 __m128i prod = _mm_mullo_epi16(a, b); |
21 prod = _mm_add_epi32(prod, _mm_set1_epi32(128)); | 36 prod = _mm_add_epi32(prod, _mm_set1_epi32(128)); |
22 prod = _mm_add_epi32(prod, _mm_srli_epi32(prod, 8)); | 37 prod = _mm_add_epi32(prod, _mm_srli_epi32(prod, 8)); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 b2 = _mm_and_si128(b2, _mm_set1_epi32(SK_B16_MASK)); | 177 b2 = _mm_and_si128(b2, _mm_set1_epi32(SK_B16_MASK)); |
163 __m128i b = _mm_packs_epi32(b1, b2); | 178 __m128i b = _mm_packs_epi32(b1, b2); |
164 | 179 |
165 // Store 8 16-bit colors in dst. | 180 // Store 8 16-bit colors in dst. |
166 __m128i d_pixel = SkPackRGB16_SSE2(r, g, b); | 181 __m128i d_pixel = SkPackRGB16_SSE2(r, g, b); |
167 | 182 |
168 return d_pixel; | 183 return d_pixel; |
169 } | 184 } |
170 | 185 |
171 #endif // SkColor_opts_SSE2_DEFINED | 186 #endif // SkColor_opts_SSE2_DEFINED |
OLD | NEW |