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

Side by Side Diff: src/opts/SkXfermode_opts_SSE2.cpp

Issue 202903004: Xfermode: SSE2 implementation of multiply_modeproc (Closed) Base URL: https://skia.googlesource.com/skia.git@xfermode
Patch Set: fix buildbot failure Created 6 years, 8 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/SkXfermode_opts_SSE2.h ('k') | src/opts/opts_check_SSE2.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "SkColorPriv.h"
2 #include "SkColor_opts_SSE2.h"
3 #include "SkMathPriv.h"
4 #include "SkXfermode.h"
5 #include "SkXfermode_opts_SSE2.h"
6 #include "SkXfermode_proccoeff.h"
7
8 ////////////////////////////////////////////////////////////////////////////////
9 // 4 pixels SSE2 version functions
10 ////////////////////////////////////////////////////////////////////////////////
11
12 static inline __m128i SkDiv255Round_SSE2(const __m128i& a) {
13 __m128i prod = _mm_add_epi32(a, _mm_set1_epi32(128)); // prod += 128;
14 prod = _mm_add_epi32(prod, _mm_srli_epi32(prod, 8)); // prod + (prod >> 8)
15 prod = _mm_srli_epi32(prod, 8); // >> 8
16
17 return prod;
18 }
19
20 static inline __m128i clamp_div255round_SSE2(const __m128i& prod) {
21 // test if > 0
22 __m128i cmp1 = _mm_cmpgt_epi32(prod, _mm_setzero_si128());
23 // test if < 255*255
24 __m128i cmp2 = _mm_cmplt_epi32(prod, _mm_set1_epi32(255*255));
25
26 __m128i ret = _mm_setzero_si128();
27
28 // if value >= 255*255, value = 255
29 ret = _mm_andnot_si128(cmp2, _mm_set1_epi32(255));
30
31 __m128i div = SkDiv255Round_SSE2(prod);
32
33 // test if > 0 && < 255*255
34 __m128i cmp = _mm_and_si128(cmp1, cmp2);
35
36 ret = _mm_or_si128(_mm_and_si128(cmp, div), _mm_andnot_si128(cmp, ret));
37
38 return ret;
39 }
40
41 static inline __m128i srcover_byte_SSE2(const __m128i& a, const __m128i& b) {
42 // a + b - SkAlphaMulAlpha(a, b);
43 return _mm_sub_epi32(_mm_add_epi32(a, b), SkAlphaMulAlpha_SSE2(a, b));
44
45 }
46
47 static inline __m128i blendfunc_multiply_byte_SSE2(const __m128i& sc, const __m1 28i& dc,
48 const __m128i& sa, const __m1 28i& da) {
49 // sc * (255 - da)
50 __m128i ret1 = _mm_sub_epi32(_mm_set1_epi32(255), da);
51 ret1 = _mm_mullo_epi16(sc, ret1);
52
53 // dc * (255 - sa)
54 __m128i ret2 = _mm_sub_epi32(_mm_set1_epi32(255), sa);
55 ret2 = _mm_mullo_epi16(dc, ret2);
56
57 // sc * dc
58 __m128i ret3 = _mm_mullo_epi16(sc, dc);
59
60 __m128i ret = _mm_add_epi32(ret1, ret2);
61 ret = _mm_add_epi32(ret, ret3);
62
63 return clamp_div255round_SSE2(ret);
64 }
65
66 static __m128i multiply_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
67 __m128i sa = SkGetPackedA32_SSE2(src);
68 __m128i da = SkGetPackedA32_SSE2(dst);
69 __m128i a = srcover_byte_SSE2(sa, da);
70
71 __m128i sr = SkGetPackedR32_SSE2(src);
72 __m128i dr = SkGetPackedR32_SSE2(dst);
73 __m128i r = blendfunc_multiply_byte_SSE2(sr, dr, sa, da);
74
75 __m128i sg = SkGetPackedG32_SSE2(src);
76 __m128i dg = SkGetPackedG32_SSE2(dst);
77 __m128i g = blendfunc_multiply_byte_SSE2(sg, dg, sa, da);
78
79
80 __m128i sb = SkGetPackedB32_SSE2(src);
81 __m128i db = SkGetPackedB32_SSE2(dst);
82 __m128i b = blendfunc_multiply_byte_SSE2(sb, db, sa, da);
83
84 return SkPackARGB32_SSE2(a, r, g, b);
85 }
86
87 ////////////////////////////////////////////////////////////////////////////////
88
89 typedef __m128i (*SkXfermodeProcSIMD)(const __m128i& src, const __m128i& dst);
90
91 extern SkXfermodeProcSIMD gSSE2XfermodeProcs[];
92
93 SkSSE2ProcCoeffXfermode::SkSSE2ProcCoeffXfermode(SkReadBuffer& buffer)
94 : INHERITED(buffer) {
95 fProcSIMD = reinterpret_cast<void*>(gSSE2XfermodeProcs[this->getMode()]);
96 }
97
98 void SkSSE2ProcCoeffXfermode::xfer32(SkPMColor dst[], const SkPMColor src[],
99 int count, const SkAlpha aa[]) const {
100 SkASSERT(dst && src && count >= 0);
101
102 SkXfermodeProc proc = this->getProc();
103 SkXfermodeProcSIMD procSIMD = reinterpret_cast<SkXfermodeProcSIMD>(fProcSIMD );
104 SkASSERT(procSIMD != NULL);
105
106 if (NULL == aa) {
107 if (count >= 4) {
108 while (((size_t)dst & 0x0F) != 0) {
109 *dst = proc(*src, *dst);
110 dst++;
111 src++;
112 count--;
113 }
114
115 const __m128i* s = reinterpret_cast<const __m128i*>(src);
116 __m128i* d = reinterpret_cast<__m128i*>(dst);
117
118 while (count >= 4) {
119 __m128i src_pixel = _mm_loadu_si128(s++);
120 __m128i dst_pixel = _mm_load_si128(d);
121
122 dst_pixel = procSIMD(src_pixel, dst_pixel);
123 _mm_store_si128(d++, dst_pixel);
124 count -= 4;
125 }
126
127 src = reinterpret_cast<const SkPMColor*>(s);
128 dst = reinterpret_cast<SkPMColor*>(d);
129 }
130
131 for (int i = count - 1; i >= 0; --i) {
132 *dst = proc(*src, *dst);
133 dst++;
134 src++;
135 }
136 } else {
137 for (int i = count - 1; i >= 0; --i) {
138 unsigned a = aa[i];
139 if (0 != a) {
140 SkPMColor dstC = dst[i];
141 SkPMColor C = proc(src[i], dstC);
142 if (a != 0xFF) {
143 C = SkFourByteInterp(C, dstC, a);
144 }
145 dst[i] = C;
146 }
147 }
148 }
149 }
150
151 void SkSSE2ProcCoeffXfermode::xfer16(uint16_t dst[], const SkPMColor src[],
152 int count, const SkAlpha aa[]) const {
153 SkASSERT(dst && src && count >= 0);
154
155 SkXfermodeProc proc = this->getProc();
156 SkXfermodeProcSIMD procSIMD = reinterpret_cast<SkXfermodeProcSIMD>(fProcSIMD );
157 SkASSERT(procSIMD != NULL);
158
159 if (NULL == aa) {
160 if (count >= 8) {
161 while (((size_t)dst & 0x0F) != 0) {
162 SkPMColor dstC = SkPixel16ToPixel32(*dst);
163 *dst = SkPixel32ToPixel16_ToU16(proc(*src, dstC));
164 dst++;
165 src++;
166 count--;
167 }
168
169 const __m128i* s = reinterpret_cast<const __m128i*>(src);
170 __m128i* d = reinterpret_cast<__m128i*>(dst);
171
172 while (count >= 8) {
173 __m128i src_pixel1 = _mm_loadu_si128(s++);
174 __m128i src_pixel2 = _mm_loadu_si128(s++);
175 __m128i dst_pixel = _mm_load_si128(d);
176
177 __m128i dst_pixel1 = _mm_unpacklo_epi16(dst_pixel, _mm_setzero_s i128());
178 __m128i dst_pixel2 = _mm_unpackhi_epi16(dst_pixel, _mm_setzero_s i128());
179
180 __m128i dstC1 = SkPixel16ToPixel32_SSE2(dst_pixel1);
181 __m128i dstC2 = SkPixel16ToPixel32_SSE2(dst_pixel2);
182
183 dst_pixel1 = procSIMD(src_pixel1, dstC1);
184 dst_pixel2 = procSIMD(src_pixel2, dstC2);
185 dst_pixel = SkPixel32ToPixel16_ToU16_SSE2(dst_pixel1, dst_pixel2 );
186
187 _mm_store_si128(d++, dst_pixel);
188 count -= 8;
189 }
190
191 src = reinterpret_cast<const SkPMColor*>(s);
192 dst = reinterpret_cast<uint16_t*>(d);
193 }
194
195 for (int i = count - 1; i >= 0; --i) {
196 SkPMColor dstC = SkPixel16ToPixel32(*dst);
197 *dst = SkPixel32ToPixel16_ToU16(proc(*src, dstC));
198 dst++;
199 src++;
200 }
201 } else {
202 for (int i = count - 1; i >= 0; --i) {
203 unsigned a = aa[i];
204 if (0 != a) {
205 SkPMColor dstC = SkPixel16ToPixel32(dst[i]);
206 SkPMColor C = proc(src[i], dstC);
207 if (0xFF != a) {
208 C = SkFourByteInterp(C, dstC, a);
209 }
210 dst[i] = SkPixel32ToPixel16_ToU16(C);
211 }
212 }
213 }
214 }
215
216 #ifndef SK_IGNORE_TO_STRING
217 void SkSSE2ProcCoeffXfermode::toString(SkString* str) const {
218 this->INHERITED::toString(str);
219 }
220 #endif
221
222 ////////////////////////////////////////////////////////////////////////////////
223
224 // 4 pixels modeprocs with SSE2
225 SkXfermodeProcSIMD gSSE2XfermodeProcs[] = {
226 NULL, // kClear_Mode
227 NULL, // kSrc_Mode
228 NULL, // kDst_Mode
229 NULL, // kSrcOver_Mode
230 NULL, // kDstOver_Mode
231 NULL, // kSrcIn_Mode
232 NULL, // kDstIn_Mode
233 NULL, // kSrcOut_Mode
234 NULL, // kDstOut_Mode
235 NULL, // kSrcATop_Mode
236 NULL, // kDstATop_Mode
237 NULL, // kXor_Mode
238 NULL, // kPlus_Mode
239 NULL, // kModulate_Mode
240 NULL, // kScreen_Mode
241
242 NULL, // kOverlay_Mode
243 NULL, // kDarken_Mode
244 NULL, // kLighten_Mode
245 NULL, // kColorDodge_Mode
246 NULL, // kColorBurn_Mode
247 NULL, // kHardLight_Mode
248 NULL, // kSoftLight_Mode
249 NULL, // kDifference_Mode
250 NULL, // kExclusion_Mode
251 multiply_modeproc_SSE2,
252
253 NULL, // kHue_Mode
254 NULL, // kSaturation_Mode
255 NULL, // kColor_Mode
256 NULL, // kLuminosity_Mode
257 };
258
259 SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl_SSE2(const ProcCoeff& rec,
260 SkXfermode::Mode mode) {
261 void* procSIMD = reinterpret_cast<void*>(gSSE2XfermodeProcs[mode]);
262
263 if (procSIMD != NULL) {
264 return SkNEW_ARGS(SkSSE2ProcCoeffXfermode, (rec, mode, procSIMD));
265 }
266 return NULL;
267 }
OLDNEW
« no previous file with comments | « src/opts/SkXfermode_opts_SSE2.h ('k') | src/opts/opts_check_SSE2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698