Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Side by Side Diff: src/opts/SkColor_opts_SSE2.h

Issue 762453002: Eliminate static initializers in SkColor_SSE2.h. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 24 matching lines...) Expand all
35 static inline __m128i SkAlphaMulAlpha_SSE2(const __m128i& a, 35 static inline __m128i SkAlphaMulAlpha_SSE2(const __m128i& a,
36 const __m128i& b) { 36 const __m128i& b) {
37 __m128i prod = _mm_mullo_epi16(a, b); 37 __m128i prod = _mm_mullo_epi16(a, b);
38 prod = _mm_add_epi32(prod, _mm_set1_epi32(128)); 38 prod = _mm_add_epi32(prod, _mm_set1_epi32(128));
39 prod = _mm_add_epi32(prod, _mm_srli_epi32(prod, 8)); 39 prod = _mm_add_epi32(prod, _mm_srli_epi32(prod, 8));
40 prod = _mm_srli_epi32(prod, 8); 40 prod = _mm_srli_epi32(prod, 8);
41 41
42 return prod; 42 return prod;
43 } 43 }
44 44
45 static const __m128i rb_mask = _mm_set1_epi32(0x00FF00FF);
46 static const __m128i ag_mask = _mm_set1_epi32(0xFF00FF00);
47
48 // Portable version SkAlphaMulQ is in SkColorPriv.h. 45 // Portable version SkAlphaMulQ is in SkColorPriv.h.
49 static inline __m128i SkAlphaMulQ_SSE2(const __m128i& c, const __m128i& scale) { 46 static inline __m128i SkAlphaMulQ_SSE2(const __m128i& c, const __m128i& scale) {
47 const __m128i mask = _mm_set1_epi32(0xFF00FF);
50 __m128i s = _mm_or_si128(_mm_slli_epi32(scale, 16), scale); 48 __m128i s = _mm_or_si128(_mm_slli_epi32(scale, 16), scale);
51 49
52 // uint32_t rb = ((c & mask) * scale) >> 8 50 // uint32_t rb = ((c & mask) * scale) >> 8
53 __m128i rb = _mm_and_si128(rb_mask, c); 51 __m128i rb = _mm_and_si128(mask, c);
54 rb = _mm_mullo_epi16(rb, s); 52 rb = _mm_mullo_epi16(rb, s);
55 rb = _mm_srli_epi16(rb, 8); 53 rb = _mm_srli_epi16(rb, 8);
56 54
57 // uint32_t ag = ((c >> 8) & mask) * scale 55 // uint32_t ag = ((c >> 8) & mask) * scale
58 __m128i ag = _mm_srli_epi16(c, 8); 56 __m128i ag = _mm_srli_epi16(c, 8);
59 ASSERT_EQ(ag, _mm_and_si128(rb_mask, ag)); // ag = _mm_srli_epi16(c, 8) did this for us. 57 ASSERT_EQ(ag, _mm_and_si128(mask, ag)); // ag = _mm_srli_epi16(c, 8) did th is for us.
60 ag = _mm_mullo_epi16(ag, s); 58 ag = _mm_mullo_epi16(ag, s);
61 59
62 // (rb & mask) | (ag & ~mask) 60 // (rb & mask) | (ag & ~mask)
63 ASSERT_EQ(rb, _mm_and_si128(rb_mask, rb)); // rb = _mm_srli_epi16(rb, 8) di d this for us. 61 ASSERT_EQ(rb, _mm_and_si128(mask, rb)); // rb = _mm_srli_epi16(rb, 8) did t his for us.
64 ag = _mm_and_si128(ag_mask, ag); 62 ag = _mm_andnot_si128(mask, ag);
65 return _mm_or_si128(rb, ag); 63 return _mm_or_si128(rb, ag);
66 } 64 }
67 65
68 // Fast path for SkAlphaMulQ_SSE2 with a constant scale factor. 66 // Fast path for SkAlphaMulQ_SSE2 with a constant scale factor.
69 static inline __m128i SkAlphaMulQ_SSE2(const __m128i& c, const unsigned scale) { 67 static inline __m128i SkAlphaMulQ_SSE2(const __m128i& c, const unsigned scale) {
68 const __m128i mask = _mm_set1_epi32(0xFF00FF);
70 __m128i s = _mm_set1_epi16(scale << 8); // Move scale factor to upper byte o f word. 69 __m128i s = _mm_set1_epi16(scale << 8); // Move scale factor to upper byte o f word.
71 70
72 // With mulhi, red and blue values are already in the right place and 71 // With mulhi, red and blue values are already in the right place and
73 // don't need to be divided by 256. 72 // don't need to be divided by 256.
74 __m128i rb = _mm_and_si128(rb_mask, c); 73 __m128i rb = _mm_and_si128(mask, c);
75 rb = _mm_mulhi_epu16(rb, s); 74 rb = _mm_mulhi_epu16(rb, s);
76 75
77 __m128i ag = _mm_and_si128(ag_mask, c); 76 __m128i ag = _mm_andnot_si128(mask, c);
78 ag = _mm_mulhi_epu16(ag, s); // Alpha and green values are in the higher byte of each word. 77 ag = _mm_mulhi_epu16(ag, s); // Alpha and green values are in the higher byte of each word.
79 ag = _mm_and_si128(ag_mask, ag); 78 ag = _mm_andnot_si128(mask, ag);
80 79
81 return _mm_or_si128(rb, ag); 80 return _mm_or_si128(rb, ag);
82 } 81 }
83 82
84 static inline __m128i SkGetPackedA32_SSE2(const __m128i& src) { 83 static inline __m128i SkGetPackedA32_SSE2(const __m128i& src) {
85 __m128i a = _mm_slli_epi32(src, (24 - SK_A32_SHIFT)); 84 __m128i a = _mm_slli_epi32(src, (24 - SK_A32_SHIFT));
86 return _mm_srli_epi32(a, 24); 85 return _mm_srli_epi32(a, 24);
87 } 86 }
88 87
89 static inline __m128i SkGetPackedR32_SSE2(const __m128i& src) { 88 static inline __m128i SkGetPackedR32_SSE2(const __m128i& src) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 dst_scale = _mm_mullo_epi16(dst_scale, src_scale); 226 dst_scale = _mm_mullo_epi16(dst_scale, src_scale);
228 dst_scale = _mm_srli_epi16(dst_scale, 8); 227 dst_scale = _mm_srli_epi16(dst_scale, 8);
229 dst_scale = _mm_sub_epi32(_mm_set1_epi32(256), dst_scale); 228 dst_scale = _mm_sub_epi32(_mm_set1_epi32(256), dst_scale);
230 229
231 __m128i result = SkAlphaMulQ_SSE2(src, alpha); 230 __m128i result = SkAlphaMulQ_SSE2(src, alpha);
232 return _mm_add_epi8(result, SkAlphaMulQ_SSE2(dst, dst_scale)); 231 return _mm_add_epi8(result, SkAlphaMulQ_SSE2(dst, dst_scale));
233 } 232 }
234 233
235 #undef ASSERT_EQ 234 #undef ASSERT_EQ
236 #endif // SkColor_opts_SSE2_DEFINED 235 #endif // SkColor_opts_SSE2_DEFINED
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698