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

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

Issue 1565223002: Clean up SkXfermode_opts.h (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: &&&&&& Created 4 years, 11 months 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 | « src/opts/Sk4px_NEON.h ('k') | src/opts/Sk4px_none.h » ('j') | 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 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 namespace { // See Sk4px.h 8 namespace { // See Sk4px.h
9 9
10 inline Sk4px Sk4px::DupPMColor(SkPMColor px) { return Sk16b(_mm_set1_epi32(px)); } 10 inline Sk4px Sk4px::DupPMColor(SkPMColor px) { return Sk16b(_mm_set1_epi32(px)); }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 inline Sk4px Sk4px::zeroColors() const { 95 inline Sk4px Sk4px::zeroColors() const {
96 return Sk16b(_mm_and_si128(_mm_set1_epi32(0xFF << SK_A32_SHIFT), this->fVec) ); 96 return Sk16b(_mm_and_si128(_mm_set1_epi32(0xFF << SK_A32_SHIFT), this->fVec) );
97 } 97 }
98 98
99 inline Sk4px Sk4px::zeroAlphas() const { 99 inline Sk4px Sk4px::zeroAlphas() const {
100 // andnot(a,b) == ~a & b 100 // andnot(a,b) == ~a & b
101 return Sk16b(_mm_andnot_si128(_mm_set1_epi32(0xFF << SK_A32_SHIFT), this->fV ec)); 101 return Sk16b(_mm_andnot_si128(_mm_set1_epi32(0xFF << SK_A32_SHIFT), this->fV ec));
102 } 102 }
103 103
104 static inline __m128i widen_low_half_to_8888(__m128i v) {
105 // RGB565 format: |R....|G.....|B....|
106 // Bit: 16 11 5 0
107
108 // First get each pixel into its own 32-bit lane.
109 // v == ____ ____ ____ ____ rgb3 rgb2 rgb1 rgb0
110 // spread == 0000 rgb3 0000 rgb2 0000 rgb1 0000 rgb0
111 auto spread = _mm_unpacklo_epi16(v, _mm_setzero_si128());
112
113 // Get each color independently, still in 565 precison but down at bit 0.
114 auto r5 = _mm_srli_epi32(spread, 11),
115 g6 = _mm_and_si128(_mm_set1_epi32(63), _mm_srli_epi32(spread, 5)),
116 b5 = _mm_and_si128(_mm_set1_epi32(31), spread);
117
118 // Scale 565 precision up to 8-bit each, filling low 323 bits with high bits of each component.
119 auto r8 = _mm_or_si128(_mm_slli_epi32(r5, 3), _mm_srli_epi32(r5, 2)),
120 g8 = _mm_or_si128(_mm_slli_epi32(g6, 2), _mm_srli_epi32(g6, 4)),
121 b8 = _mm_or_si128(_mm_slli_epi32(b5, 3), _mm_srli_epi32(b5, 2));
122
123 // Now put all the 8-bit components into SkPMColor order.
124 return _mm_or_si128(_mm_slli_epi32(r8, SK_R32_SHIFT), // TODO: one of thes e shifts is zero...
125 _mm_or_si128(_mm_slli_epi32(g8, SK_G32_SHIFT),
126 _mm_or_si128(_mm_slli_epi32(b8, SK_B32_SHIFT),
127 _mm_set1_epi32(0xFF << SK_A32_SHIFT))));
128 }
129
130 static inline __m128i narrow_to_565(__m128i w) {
131 // Extract out top RGB 565 bits of each pixel, with no rounding.
132 auto r5 = _mm_and_si128(_mm_set1_epi32(31), _mm_srli_epi32(w, SK_R32_SHIFT + 3)),
133 g6 = _mm_and_si128(_mm_set1_epi32(63), _mm_srli_epi32(w, SK_G32_SHIFT + 2)),
134 b5 = _mm_and_si128(_mm_set1_epi32(31), _mm_srli_epi32(w, SK_B32_SHIFT + 3));
135
136 // Now put the bits in place in the low 16-bits of each 32-bit lane.
137 auto spread = _mm_or_si128(_mm_slli_epi32(r5, 11),
138 _mm_or_si128(_mm_slli_epi32(g6, 5),
139 b5));
140
141 // We want to pack the bottom 16-bits of spread down into the low half of th e register, v.
142 // spread == 0000 rgb3 0000 rgb2 0000 rgb1 0000 rgb0
143 // v == ____ ____ ____ ____ rgb3 rgb2 rgb1 rgb0
144
145 // Ideally now we'd use _mm_packus_epi32(spread, <anything>) to pack v. But that's from SSE4.
146 // With only SSE2, we need to use _mm_packs_epi32. That does signed saturat ion, and
147 // we need to preserve all 16 bits. So we pretend our data is signed by sig n-extending first.
148 // TODO: is it faster to just _mm_shuffle_epi8 this when we have SSSE3?
149 auto signExtended = _mm_srai_epi32(_mm_slli_epi32(spread, 16), 16);
150 auto v = _mm_packs_epi32(signExtended, signExtended);
151 return v;
152 }
153
154 inline Sk4px Sk4px::Load4(const SkPMColor16 src[4]) {
155 return Sk16b(widen_low_half_to_8888(_mm_loadl_epi64((const __m128i*)src)));
156 }
157 inline Sk4px Sk4px::Load2(const SkPMColor16 src[2]) {
158 auto src2 = ((uint32_t)src[0] )
159 | ((uint32_t)src[1] << 16);
160 return Sk16b(widen_low_half_to_8888(_mm_cvtsi32_si128(src2)));
161 }
162 inline Sk4px Sk4px::Load1(const SkPMColor16 src[1]) {
163 return Sk16b(widen_low_half_to_8888(_mm_insert_epi16(_mm_setzero_si128(), sr c[0], 0)));
164 }
165
166 inline void Sk4px::store4(SkPMColor16 dst[4]) const {
167 _mm_storel_epi64((__m128i*)dst, narrow_to_565(this->fVec));
168 }
169 inline void Sk4px::store2(SkPMColor16 dst[2]) const {
170 uint32_t dst2 = _mm_cvtsi128_si32(narrow_to_565(this->fVec));
171 dst[0] = dst2;
172 dst[1] = dst2 >> 16;
173 }
174 inline void Sk4px::store1(SkPMColor16 dst[1]) const {
175 uint32_t dst2 = _mm_cvtsi128_si32(narrow_to_565(this->fVec));
176 dst[0] = dst2;
177 }
178
179 } // namespace 104 } // namespace
OLDNEW
« no previous file with comments | « src/opts/Sk4px_NEON.h ('k') | src/opts/Sk4px_none.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698