2 * Copyright © 2008 Rodrigo Kumpera
3 * Copyright © 2008 André Tupinambá
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of Red Hat not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. Red Hat makes no representations about the
12 * suitability of this software for any purpose. It is provided "as is"
13 * without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
20 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
21 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24 * Author: Rodrigo Kumpera (kumpera@gmail.com)
25 * André Tupinambá (andrelrt@gmail.com)
27 * Based on work by Owen Taylor and Søren Sandmann
33 #include <xmmintrin.h> /* for _mm_shuffle_pi16 and _MM_SHUFFLE */
34 #include <emmintrin.h> /* for SSE2 intrinsics */
35 #include "pixman-private.h"
36 #include "pixman-combine32.h"
37 #include "pixman-fast-path.h"
39 static __m128i mask_0080;
40 static __m128i mask_00ff;
41 static __m128i mask_0101;
42 static __m128i mask_ffff;
43 static __m128i mask_ff000000;
44 static __m128i mask_alpha;
46 static __m128i mask_565_r;
47 static __m128i mask_565_g1, mask_565_g2;
48 static __m128i mask_565_b;
49 static __m128i mask_red;
50 static __m128i mask_green;
51 static __m128i mask_blue;
53 static __m128i mask_565_fix_rb;
54 static __m128i mask_565_fix_g;
56 static force_inline __m128i
57 unpack_32_1x128 (uint32_t data)
59 return _mm_unpacklo_epi8 (_mm_cvtsi32_si128 (data), _mm_setzero_si128 ());
62 static force_inline void
63 unpack_128_2x128 (__m128i data, __m128i* data_lo, __m128i* data_hi)
65 *data_lo = _mm_unpacklo_epi8 (data, _mm_setzero_si128 ());
66 *data_hi = _mm_unpackhi_epi8 (data, _mm_setzero_si128 ());
69 static force_inline __m128i
70 unpack_565_to_8888 (__m128i lo)
72 __m128i r, g, b, rb, t;
74 r = _mm_and_si128 (_mm_slli_epi32 (lo, 8), mask_red);
75 g = _mm_and_si128 (_mm_slli_epi32 (lo, 5), mask_green);
76 b = _mm_and_si128 (_mm_slli_epi32 (lo, 3), mask_blue);
78 rb = _mm_or_si128 (r, b);
79 t = _mm_and_si128 (rb, mask_565_fix_rb);
80 t = _mm_srli_epi32 (t, 5);
81 rb = _mm_or_si128 (rb, t);
83 t = _mm_and_si128 (g, mask_565_fix_g);
84 t = _mm_srli_epi32 (t, 6);
85 g = _mm_or_si128 (g, t);
87 return _mm_or_si128 (rb, g);
90 static force_inline void
91 unpack_565_128_4x128 (__m128i data,
99 lo = _mm_unpacklo_epi16 (data, _mm_setzero_si128 ());
100 hi = _mm_unpackhi_epi16 (data, _mm_setzero_si128 ());
102 lo = unpack_565_to_8888 (lo);
103 hi = unpack_565_to_8888 (hi);
105 unpack_128_2x128 (lo, data0, data1);
106 unpack_128_2x128 (hi, data2, data3);
109 static force_inline uint16_t
110 pack_565_32_16 (uint32_t pixel)
112 return (uint16_t) (((pixel >> 8) & 0xf800) |
113 ((pixel >> 5) & 0x07e0) |
114 ((pixel >> 3) & 0x001f));
117 static force_inline __m128i
118 pack_2x128_128 (__m128i lo, __m128i hi)
120 return _mm_packus_epi16 (lo, hi);
123 static force_inline __m128i
124 pack_565_2x128_128 (__m128i lo, __m128i hi)
127 __m128i r, g1, g2, b;
129 data = pack_2x128_128 (lo, hi);
131 r = _mm_and_si128 (data, mask_565_r);
132 g1 = _mm_and_si128 (_mm_slli_epi32 (data, 3), mask_565_g1);
133 g2 = _mm_and_si128 (_mm_srli_epi32 (data, 5), mask_565_g2);
134 b = _mm_and_si128 (_mm_srli_epi32 (data, 3), mask_565_b);
136 return _mm_or_si128 (_mm_or_si128 (_mm_or_si128 (r, g1), g2), b);
139 static force_inline __m128i
140 pack_565_4x128_128 (__m128i* xmm0, __m128i* xmm1, __m128i* xmm2, __m128i* xmm3)
142 return _mm_packus_epi16 (pack_565_2x128_128 (*xmm0, *xmm1),
143 pack_565_2x128_128 (*xmm2, *xmm3));
146 static force_inline int
147 is_opaque (__m128i x)
149 __m128i ffs = _mm_cmpeq_epi8 (x, x);
151 return (_mm_movemask_epi8 (_mm_cmpeq_epi8 (x, ffs)) & 0x8888) == 0x8888;
154 static force_inline int
157 return _mm_movemask_epi8 (
158 _mm_cmpeq_epi8 (x, _mm_setzero_si128 ())) == 0xffff;
161 static force_inline int
162 is_transparent (__m128i x)
164 return (_mm_movemask_epi8 (
165 _mm_cmpeq_epi8 (x, _mm_setzero_si128 ())) & 0x8888) == 0x8888;
168 static force_inline __m128i
169 expand_pixel_32_1x128 (uint32_t data)
171 return _mm_shuffle_epi32 (unpack_32_1x128 (data), _MM_SHUFFLE (1, 0, 1, 0));
174 static force_inline __m128i
175 expand_alpha_1x128 (__m128i data)
177 return _mm_shufflehi_epi16 (_mm_shufflelo_epi16 (data,
178 _MM_SHUFFLE (3, 3, 3, 3)),
179 _MM_SHUFFLE (3, 3, 3, 3));
182 static force_inline void
183 expand_alpha_2x128 (__m128i data_lo,
190 lo = _mm_shufflelo_epi16 (data_lo, _MM_SHUFFLE (3, 3, 3, 3));
191 hi = _mm_shufflelo_epi16 (data_hi, _MM_SHUFFLE (3, 3, 3, 3));
193 *alpha_lo = _mm_shufflehi_epi16 (lo, _MM_SHUFFLE (3, 3, 3, 3));
194 *alpha_hi = _mm_shufflehi_epi16 (hi, _MM_SHUFFLE (3, 3, 3, 3));
197 static force_inline void
198 expand_alpha_rev_2x128 (__m128i data_lo,
205 lo = _mm_shufflelo_epi16 (data_lo, _MM_SHUFFLE (0, 0, 0, 0));
206 hi = _mm_shufflelo_epi16 (data_hi, _MM_SHUFFLE (0, 0, 0, 0));
207 *alpha_lo = _mm_shufflehi_epi16 (lo, _MM_SHUFFLE (0, 0, 0, 0));
208 *alpha_hi = _mm_shufflehi_epi16 (hi, _MM_SHUFFLE (0, 0, 0, 0));
211 static force_inline void
212 pix_multiply_2x128 (__m128i* data_lo,
221 lo = _mm_mullo_epi16 (*data_lo, *alpha_lo);
222 hi = _mm_mullo_epi16 (*data_hi, *alpha_hi);
223 lo = _mm_adds_epu16 (lo, mask_0080);
224 hi = _mm_adds_epu16 (hi, mask_0080);
225 *ret_lo = _mm_mulhi_epu16 (lo, mask_0101);
226 *ret_hi = _mm_mulhi_epu16 (hi, mask_0101);
229 static force_inline void
230 pix_add_multiply_2x128 (__m128i* src_lo,
232 __m128i* alpha_dst_lo,
233 __m128i* alpha_dst_hi,
236 __m128i* alpha_src_lo,
237 __m128i* alpha_src_hi,
241 __m128i t1_lo, t1_hi;
242 __m128i t2_lo, t2_hi;
244 pix_multiply_2x128 (src_lo, src_hi, alpha_dst_lo, alpha_dst_hi, &t1_lo, &t1_hi);
245 pix_multiply_2x128 (dst_lo, dst_hi, alpha_src_lo, alpha_src_hi, &t2_lo, &t2_hi);
247 *ret_lo = _mm_adds_epu8 (t1_lo, t2_lo);
248 *ret_hi = _mm_adds_epu8 (t1_hi, t2_hi);
251 static force_inline void
252 negate_2x128 (__m128i data_lo,
257 *neg_lo = _mm_xor_si128 (data_lo, mask_00ff);
258 *neg_hi = _mm_xor_si128 (data_hi, mask_00ff);
261 static force_inline void
262 invert_colors_2x128 (__m128i data_lo,
269 lo = _mm_shufflelo_epi16 (data_lo, _MM_SHUFFLE (3, 0, 1, 2));
270 hi = _mm_shufflelo_epi16 (data_hi, _MM_SHUFFLE (3, 0, 1, 2));
271 *inv_lo = _mm_shufflehi_epi16 (lo, _MM_SHUFFLE (3, 0, 1, 2));
272 *inv_hi = _mm_shufflehi_epi16 (hi, _MM_SHUFFLE (3, 0, 1, 2));
275 static force_inline void
276 over_2x128 (__m128i* src_lo,
285 negate_2x128 (*alpha_lo, *alpha_hi, &t1, &t2);
287 pix_multiply_2x128 (dst_lo, dst_hi, &t1, &t2, dst_lo, dst_hi);
289 *dst_lo = _mm_adds_epu8 (*src_lo, *dst_lo);
290 *dst_hi = _mm_adds_epu8 (*src_hi, *dst_hi);
293 static force_inline void
294 over_rev_non_pre_2x128 (__m128i src_lo,
300 __m128i alpha_lo, alpha_hi;
302 expand_alpha_2x128 (src_lo, src_hi, &alpha_lo, &alpha_hi);
304 lo = _mm_or_si128 (alpha_lo, mask_alpha);
305 hi = _mm_or_si128 (alpha_hi, mask_alpha);
307 invert_colors_2x128 (src_lo, src_hi, &src_lo, &src_hi);
309 pix_multiply_2x128 (&src_lo, &src_hi, &lo, &hi, &lo, &hi);
311 over_2x128 (&lo, &hi, &alpha_lo, &alpha_hi, dst_lo, dst_hi);
314 static force_inline void
315 in_over_2x128 (__m128i* src_lo,
327 pix_multiply_2x128 (src_lo, src_hi, mask_lo, mask_hi, &s_lo, &s_hi);
328 pix_multiply_2x128 (alpha_lo, alpha_hi, mask_lo, mask_hi, &a_lo, &a_hi);
330 over_2x128 (&s_lo, &s_hi, &a_lo, &a_hi, dst_lo, dst_hi);
333 /* load 4 pixels from a 16-byte boundary aligned address */
334 static force_inline __m128i
335 load_128_aligned (__m128i* src)
337 return _mm_load_si128 (src);
340 /* load 4 pixels from a unaligned address */
341 static force_inline __m128i
342 load_128_unaligned (const __m128i* src)
344 return _mm_loadu_si128 (src);
347 /* save 4 pixels using Write Combining memory on a 16-byte
348 * boundary aligned address
350 static force_inline void
351 save_128_write_combining (__m128i* dst,
354 _mm_stream_si128 (dst, data);
357 /* save 4 pixels on a 16-byte boundary aligned address */
358 static force_inline void
359 save_128_aligned (__m128i* dst,
362 _mm_store_si128 (dst, data);
365 /* save 4 pixels on a unaligned address */
366 static force_inline void
367 save_128_unaligned (__m128i* dst,
370 _mm_storeu_si128 (dst, data);
373 static force_inline __m128i
374 load_32_1x128 (uint32_t data)
376 return _mm_cvtsi32_si128 (data);
379 static force_inline __m128i
380 expand_alpha_rev_1x128 (__m128i data)
382 return _mm_shufflelo_epi16 (data, _MM_SHUFFLE (0, 0, 0, 0));
385 static force_inline __m128i
386 expand_pixel_8_1x128 (uint8_t data)
388 return _mm_shufflelo_epi16 (
389 unpack_32_1x128 ((uint32_t)data), _MM_SHUFFLE (0, 0, 0, 0));
392 static force_inline __m128i
393 pix_multiply_1x128 (__m128i data,
396 return _mm_mulhi_epu16 (_mm_adds_epu16 (_mm_mullo_epi16 (data, alpha),
401 static force_inline __m128i
402 pix_add_multiply_1x128 (__m128i* src,
407 __m128i t1 = pix_multiply_1x128 (*src, *alpha_dst);
408 __m128i t2 = pix_multiply_1x128 (*dst, *alpha_src);
410 return _mm_adds_epu8 (t1, t2);
413 static force_inline __m128i
414 negate_1x128 (__m128i data)
416 return _mm_xor_si128 (data, mask_00ff);
419 static force_inline __m128i
420 invert_colors_1x128 (__m128i data)
422 return _mm_shufflelo_epi16 (data, _MM_SHUFFLE (3, 0, 1, 2));
425 static force_inline __m128i
426 over_1x128 (__m128i src, __m128i alpha, __m128i dst)
428 return _mm_adds_epu8 (src, pix_multiply_1x128 (dst, negate_1x128 (alpha)));
431 static force_inline __m128i
432 in_over_1x128 (__m128i* src, __m128i* alpha, __m128i* mask, __m128i* dst)
434 return over_1x128 (pix_multiply_1x128 (*src, *mask),
435 pix_multiply_1x128 (*alpha, *mask),
439 static force_inline __m128i
440 over_rev_non_pre_1x128 (__m128i src, __m128i dst)
442 __m128i alpha = expand_alpha_1x128 (src);
444 return over_1x128 (pix_multiply_1x128 (invert_colors_1x128 (src),
445 _mm_or_si128 (alpha, mask_alpha)),
450 static force_inline uint32_t
451 pack_1x128_32 (__m128i data)
453 return _mm_cvtsi128_si32 (_mm_packus_epi16 (data, _mm_setzero_si128 ()));
456 static force_inline __m128i
457 expand565_16_1x128 (uint16_t pixel)
459 __m128i m = _mm_cvtsi32_si128 (pixel);
461 m = unpack_565_to_8888 (m);
463 return _mm_unpacklo_epi8 (m, _mm_setzero_si128 ());
466 static force_inline uint32_t
467 core_combine_over_u_pixel_sse2 (uint32_t src, uint32_t dst)
480 xmms = unpack_32_1x128 (src);
481 return pack_1x128_32 (
482 over_1x128 (xmms, expand_alpha_1x128 (xmms),
483 unpack_32_1x128 (dst)));
489 static force_inline uint32_t
490 combine1 (const uint32_t *ps, const uint32_t *pm)
498 mm = unpack_32_1x128 (*pm);
499 mm = expand_alpha_1x128 (mm);
501 ms = unpack_32_1x128 (s);
502 ms = pix_multiply_1x128 (ms, mm);
504 s = pack_1x128_32 (ms);
510 static force_inline __m128i
511 combine4 (const __m128i *ps, const __m128i *pm)
513 __m128i xmm_src_lo, xmm_src_hi;
514 __m128i xmm_msk_lo, xmm_msk_hi;
519 xmm_msk_lo = load_128_unaligned (pm);
521 if (is_transparent (xmm_msk_lo))
522 return _mm_setzero_si128 ();
525 s = load_128_unaligned (ps);
529 unpack_128_2x128 (s, &xmm_src_lo, &xmm_src_hi);
530 unpack_128_2x128 (xmm_msk_lo, &xmm_msk_lo, &xmm_msk_hi);
532 expand_alpha_2x128 (xmm_msk_lo, xmm_msk_hi, &xmm_msk_lo, &xmm_msk_hi);
534 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
535 &xmm_msk_lo, &xmm_msk_hi,
536 &xmm_src_lo, &xmm_src_hi);
538 s = pack_2x128_128 (xmm_src_lo, xmm_src_hi);
544 static force_inline void
545 core_combine_over_u_sse2_mask (uint32_t * pd,
552 /* Align dst on a 16-byte boundary */
553 while (w && ((unsigned long)pd & 15))
556 s = combine1 (ps, pm);
559 *pd = core_combine_over_u_pixel_sse2 (s, d);
568 __m128i mask = load_128_unaligned ((__m128i *)pm);
573 __m128i src_hi, src_lo;
574 __m128i mask_hi, mask_lo;
575 __m128i alpha_hi, alpha_lo;
577 src = load_128_unaligned ((__m128i *)ps);
579 if (is_opaque (_mm_and_si128 (src, mask)))
581 save_128_aligned ((__m128i *)pd, src);
585 __m128i dst = load_128_aligned ((__m128i *)pd);
586 __m128i dst_hi, dst_lo;
588 unpack_128_2x128 (mask, &mask_lo, &mask_hi);
589 unpack_128_2x128 (src, &src_lo, &src_hi);
591 expand_alpha_2x128 (mask_lo, mask_hi, &mask_lo, &mask_hi);
592 pix_multiply_2x128 (&src_lo, &src_hi,
596 unpack_128_2x128 (dst, &dst_lo, &dst_hi);
598 expand_alpha_2x128 (src_lo, src_hi,
599 &alpha_lo, &alpha_hi);
601 over_2x128 (&src_lo, &src_hi, &alpha_lo, &alpha_hi,
606 pack_2x128_128 (dst_lo, dst_hi));
618 s = combine1 (ps, pm);
621 *pd = core_combine_over_u_pixel_sse2 (s, d);
630 static force_inline void
631 core_combine_over_u_sse2_no_mask (uint32_t * pd,
637 /* Align dst on a 16-byte boundary */
638 while (w && ((unsigned long)pd & 15))
644 *pd = core_combine_over_u_pixel_sse2 (s, d);
653 __m128i src_hi, src_lo, dst_hi, dst_lo;
654 __m128i alpha_hi, alpha_lo;
656 src = load_128_unaligned ((__m128i *)ps);
662 save_128_aligned ((__m128i *)pd, src);
666 __m128i dst = load_128_aligned ((__m128i *)pd);
668 unpack_128_2x128 (src, &src_lo, &src_hi);
669 unpack_128_2x128 (dst, &dst_lo, &dst_hi);
671 expand_alpha_2x128 (src_lo, src_hi,
672 &alpha_lo, &alpha_hi);
673 over_2x128 (&src_lo, &src_hi, &alpha_lo, &alpha_hi,
678 pack_2x128_128 (dst_lo, dst_hi));
692 *pd = core_combine_over_u_pixel_sse2 (s, d);
700 static force_inline void
701 sse2_combine_over_u (pixman_implementation_t *imp,
709 core_combine_over_u_sse2_mask (pd, ps, pm, w);
711 core_combine_over_u_sse2_no_mask (pd, ps, w);
715 sse2_combine_over_reverse_u (pixman_implementation_t *imp,
724 __m128i xmm_dst_lo, xmm_dst_hi;
725 __m128i xmm_src_lo, xmm_src_hi;
726 __m128i xmm_alpha_lo, xmm_alpha_hi;
728 /* Align dst on a 16-byte boundary */
730 ((unsigned long)pd & 15))
733 s = combine1 (ps, pm);
735 *pd++ = core_combine_over_u_pixel_sse2 (d, s);
744 /* I'm loading unaligned because I'm not sure
745 * about the address alignment.
747 xmm_src_hi = combine4 ((__m128i*)ps, (__m128i*)pm);
748 xmm_dst_hi = load_128_aligned ((__m128i*) pd);
750 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
751 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
753 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi,
754 &xmm_alpha_lo, &xmm_alpha_hi);
756 over_2x128 (&xmm_dst_lo, &xmm_dst_hi,
757 &xmm_alpha_lo, &xmm_alpha_hi,
758 &xmm_src_lo, &xmm_src_hi);
760 /* rebuid the 4 pixel data and save*/
761 save_128_aligned ((__m128i*)pd,
762 pack_2x128_128 (xmm_src_lo, xmm_src_hi));
775 s = combine1 (ps, pm);
777 *pd++ = core_combine_over_u_pixel_sse2 (d, s);
785 static force_inline uint32_t
786 core_combine_in_u_pixel_sse2 (uint32_t src, uint32_t dst)
788 uint32_t maska = src >> 24;
794 else if (maska != 0xff)
796 return pack_1x128_32 (
797 pix_multiply_1x128 (unpack_32_1x128 (dst),
798 expand_alpha_1x128 (unpack_32_1x128 (src))));
805 sse2_combine_in_u (pixman_implementation_t *imp,
814 __m128i xmm_src_lo, xmm_src_hi;
815 __m128i xmm_dst_lo, xmm_dst_hi;
817 while (w && ((unsigned long) pd & 15))
819 s = combine1 (ps, pm);
822 *pd++ = core_combine_in_u_pixel_sse2 (d, s);
831 xmm_dst_hi = load_128_aligned ((__m128i*) pd);
832 xmm_src_hi = combine4 ((__m128i*) ps, (__m128i*) pm);
834 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
835 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
837 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
838 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
839 &xmm_dst_lo, &xmm_dst_hi,
840 &xmm_dst_lo, &xmm_dst_hi);
842 save_128_aligned ((__m128i*)pd,
843 pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
854 s = combine1 (ps, pm);
857 *pd++ = core_combine_in_u_pixel_sse2 (d, s);
866 sse2_combine_in_reverse_u (pixman_implementation_t *imp,
875 __m128i xmm_src_lo, xmm_src_hi;
876 __m128i xmm_dst_lo, xmm_dst_hi;
878 while (w && ((unsigned long) pd & 15))
880 s = combine1 (ps, pm);
883 *pd++ = core_combine_in_u_pixel_sse2 (s, d);
892 xmm_dst_hi = load_128_aligned ((__m128i*) pd);
893 xmm_src_hi = combine4 ((__m128i*) ps, (__m128i*)pm);
895 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
896 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
898 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
899 pix_multiply_2x128 (&xmm_dst_lo, &xmm_dst_hi,
900 &xmm_src_lo, &xmm_src_hi,
901 &xmm_dst_lo, &xmm_dst_hi);
904 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
915 s = combine1 (ps, pm);
918 *pd++ = core_combine_in_u_pixel_sse2 (s, d);
927 sse2_combine_out_reverse_u (pixman_implementation_t *imp,
934 while (w && ((unsigned long) pd & 15))
936 uint32_t s = combine1 (ps, pm);
939 *pd++ = pack_1x128_32 (
941 unpack_32_1x128 (d), negate_1x128 (
942 expand_alpha_1x128 (unpack_32_1x128 (s)))));
952 __m128i xmm_src_lo, xmm_src_hi;
953 __m128i xmm_dst_lo, xmm_dst_hi;
955 xmm_src_hi = combine4 ((__m128i*)ps, (__m128i*)pm);
956 xmm_dst_hi = load_128_aligned ((__m128i*) pd);
958 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
959 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
961 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
962 negate_2x128 (xmm_src_lo, xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
964 pix_multiply_2x128 (&xmm_dst_lo, &xmm_dst_hi,
965 &xmm_src_lo, &xmm_src_hi,
966 &xmm_dst_lo, &xmm_dst_hi);
969 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
981 uint32_t s = combine1 (ps, pm);
984 *pd++ = pack_1x128_32 (
986 unpack_32_1x128 (d), negate_1x128 (
987 expand_alpha_1x128 (unpack_32_1x128 (s)))));
996 sse2_combine_out_u (pixman_implementation_t *imp,
1000 const uint32_t * pm,
1003 while (w && ((unsigned long) pd & 15))
1005 uint32_t s = combine1 (ps, pm);
1008 *pd++ = pack_1x128_32 (
1009 pix_multiply_1x128 (
1010 unpack_32_1x128 (s), negate_1x128 (
1011 expand_alpha_1x128 (unpack_32_1x128 (d)))));
1020 __m128i xmm_src_lo, xmm_src_hi;
1021 __m128i xmm_dst_lo, xmm_dst_hi;
1023 xmm_src_hi = combine4 ((__m128i*) ps, (__m128i*)pm);
1024 xmm_dst_hi = load_128_aligned ((__m128i*) pd);
1026 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
1027 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1029 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1030 negate_2x128 (xmm_dst_lo, xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1032 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
1033 &xmm_dst_lo, &xmm_dst_hi,
1034 &xmm_dst_lo, &xmm_dst_hi);
1037 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
1048 uint32_t s = combine1 (ps, pm);
1051 *pd++ = pack_1x128_32 (
1052 pix_multiply_1x128 (
1053 unpack_32_1x128 (s), negate_1x128 (
1054 expand_alpha_1x128 (unpack_32_1x128 (d)))));
1062 static force_inline uint32_t
1063 core_combine_atop_u_pixel_sse2 (uint32_t src,
1066 __m128i s = unpack_32_1x128 (src);
1067 __m128i d = unpack_32_1x128 (dst);
1069 __m128i sa = negate_1x128 (expand_alpha_1x128 (s));
1070 __m128i da = expand_alpha_1x128 (d);
1072 return pack_1x128_32 (pix_add_multiply_1x128 (&s, &da, &d, &sa));
1076 sse2_combine_atop_u (pixman_implementation_t *imp,
1079 const uint32_t * ps,
1080 const uint32_t * pm,
1085 __m128i xmm_src_lo, xmm_src_hi;
1086 __m128i xmm_dst_lo, xmm_dst_hi;
1087 __m128i xmm_alpha_src_lo, xmm_alpha_src_hi;
1088 __m128i xmm_alpha_dst_lo, xmm_alpha_dst_hi;
1090 while (w && ((unsigned long) pd & 15))
1092 s = combine1 (ps, pm);
1095 *pd++ = core_combine_atop_u_pixel_sse2 (s, d);
1104 xmm_src_hi = combine4 ((__m128i*)ps, (__m128i*)pm);
1105 xmm_dst_hi = load_128_aligned ((__m128i*) pd);
1107 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
1108 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1110 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
1111 &xmm_alpha_src_lo, &xmm_alpha_src_hi);
1112 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi,
1113 &xmm_alpha_dst_lo, &xmm_alpha_dst_hi);
1115 negate_2x128 (xmm_alpha_src_lo, xmm_alpha_src_hi,
1116 &xmm_alpha_src_lo, &xmm_alpha_src_hi);
1118 pix_add_multiply_2x128 (
1119 &xmm_src_lo, &xmm_src_hi, &xmm_alpha_dst_lo, &xmm_alpha_dst_hi,
1120 &xmm_dst_lo, &xmm_dst_hi, &xmm_alpha_src_lo, &xmm_alpha_src_hi,
1121 &xmm_dst_lo, &xmm_dst_hi);
1124 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
1135 s = combine1 (ps, pm);
1138 *pd++ = core_combine_atop_u_pixel_sse2 (s, d);
1146 static force_inline uint32_t
1147 core_combine_reverse_atop_u_pixel_sse2 (uint32_t src,
1150 __m128i s = unpack_32_1x128 (src);
1151 __m128i d = unpack_32_1x128 (dst);
1153 __m128i sa = expand_alpha_1x128 (s);
1154 __m128i da = negate_1x128 (expand_alpha_1x128 (d));
1156 return pack_1x128_32 (pix_add_multiply_1x128 (&s, &da, &d, &sa));
1160 sse2_combine_atop_reverse_u (pixman_implementation_t *imp,
1163 const uint32_t * ps,
1164 const uint32_t * pm,
1169 __m128i xmm_src_lo, xmm_src_hi;
1170 __m128i xmm_dst_lo, xmm_dst_hi;
1171 __m128i xmm_alpha_src_lo, xmm_alpha_src_hi;
1172 __m128i xmm_alpha_dst_lo, xmm_alpha_dst_hi;
1174 while (w && ((unsigned long) pd & 15))
1176 s = combine1 (ps, pm);
1179 *pd++ = core_combine_reverse_atop_u_pixel_sse2 (s, d);
1188 xmm_src_hi = combine4 ((__m128i*)ps, (__m128i*)pm);
1189 xmm_dst_hi = load_128_aligned ((__m128i*) pd);
1191 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
1192 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1194 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
1195 &xmm_alpha_src_lo, &xmm_alpha_src_hi);
1196 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi,
1197 &xmm_alpha_dst_lo, &xmm_alpha_dst_hi);
1199 negate_2x128 (xmm_alpha_dst_lo, xmm_alpha_dst_hi,
1200 &xmm_alpha_dst_lo, &xmm_alpha_dst_hi);
1202 pix_add_multiply_2x128 (
1203 &xmm_src_lo, &xmm_src_hi, &xmm_alpha_dst_lo, &xmm_alpha_dst_hi,
1204 &xmm_dst_lo, &xmm_dst_hi, &xmm_alpha_src_lo, &xmm_alpha_src_hi,
1205 &xmm_dst_lo, &xmm_dst_hi);
1208 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
1219 s = combine1 (ps, pm);
1222 *pd++ = core_combine_reverse_atop_u_pixel_sse2 (s, d);
1230 static force_inline uint32_t
1231 core_combine_xor_u_pixel_sse2 (uint32_t src,
1234 __m128i s = unpack_32_1x128 (src);
1235 __m128i d = unpack_32_1x128 (dst);
1237 __m128i neg_d = negate_1x128 (expand_alpha_1x128 (d));
1238 __m128i neg_s = negate_1x128 (expand_alpha_1x128 (s));
1240 return pack_1x128_32 (pix_add_multiply_1x128 (&s, &neg_d, &d, &neg_s));
1244 sse2_combine_xor_u (pixman_implementation_t *imp,
1247 const uint32_t * src,
1248 const uint32_t * mask,
1254 const uint32_t* ps = src;
1255 const uint32_t* pm = mask;
1257 __m128i xmm_src, xmm_src_lo, xmm_src_hi;
1258 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
1259 __m128i xmm_alpha_src_lo, xmm_alpha_src_hi;
1260 __m128i xmm_alpha_dst_lo, xmm_alpha_dst_hi;
1262 while (w && ((unsigned long) pd & 15))
1264 s = combine1 (ps, pm);
1267 *pd++ = core_combine_xor_u_pixel_sse2 (s, d);
1276 xmm_src = combine4 ((__m128i*) ps, (__m128i*) pm);
1277 xmm_dst = load_128_aligned ((__m128i*) pd);
1279 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
1280 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
1282 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
1283 &xmm_alpha_src_lo, &xmm_alpha_src_hi);
1284 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi,
1285 &xmm_alpha_dst_lo, &xmm_alpha_dst_hi);
1287 negate_2x128 (xmm_alpha_src_lo, xmm_alpha_src_hi,
1288 &xmm_alpha_src_lo, &xmm_alpha_src_hi);
1289 negate_2x128 (xmm_alpha_dst_lo, xmm_alpha_dst_hi,
1290 &xmm_alpha_dst_lo, &xmm_alpha_dst_hi);
1292 pix_add_multiply_2x128 (
1293 &xmm_src_lo, &xmm_src_hi, &xmm_alpha_dst_lo, &xmm_alpha_dst_hi,
1294 &xmm_dst_lo, &xmm_dst_hi, &xmm_alpha_src_lo, &xmm_alpha_src_hi,
1295 &xmm_dst_lo, &xmm_dst_hi);
1298 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
1309 s = combine1 (ps, pm);
1312 *pd++ = core_combine_xor_u_pixel_sse2 (s, d);
1320 static force_inline void
1321 sse2_combine_add_u (pixman_implementation_t *imp,
1324 const uint32_t * src,
1325 const uint32_t * mask,
1331 const uint32_t* ps = src;
1332 const uint32_t* pm = mask;
1334 while (w && (unsigned long)pd & 15)
1336 s = combine1 (ps, pm);
1342 *pd++ = _mm_cvtsi128_si32 (
1343 _mm_adds_epu8 (_mm_cvtsi32_si128 (s), _mm_cvtsi32_si128 (d)));
1351 s = combine4 ((__m128i*)ps, (__m128i*)pm);
1354 (__m128i*)pd, _mm_adds_epu8 (s, load_128_aligned ((__m128i*)pd)));
1365 s = combine1 (ps, pm);
1369 *pd++ = _mm_cvtsi128_si32 (
1370 _mm_adds_epu8 (_mm_cvtsi32_si128 (s), _mm_cvtsi32_si128 (d)));
1376 static force_inline uint32_t
1377 core_combine_saturate_u_pixel_sse2 (uint32_t src,
1380 __m128i ms = unpack_32_1x128 (src);
1381 __m128i md = unpack_32_1x128 (dst);
1382 uint32_t sa = src >> 24;
1383 uint32_t da = ~dst >> 24;
1387 ms = pix_multiply_1x128 (
1388 ms, expand_alpha_1x128 (unpack_32_1x128 (DIV_UN8 (da, sa) << 24)));
1391 return pack_1x128_32 (_mm_adds_epu16 (md, ms));
1395 sse2_combine_saturate_u (pixman_implementation_t *imp,
1398 const uint32_t * ps,
1399 const uint32_t * pm,
1405 __m128i xmm_src, xmm_dst;
1407 while (w && (unsigned long)pd & 15)
1409 s = combine1 (ps, pm);
1412 *pd++ = core_combine_saturate_u_pixel_sse2 (s, d);
1421 xmm_dst = load_128_aligned ((__m128i*)pd);
1422 xmm_src = combine4 ((__m128i*)ps, (__m128i*)pm);
1424 pack_cmp = _mm_movemask_epi8 (
1426 _mm_srli_epi32 (xmm_src, 24),
1427 _mm_srli_epi32 (_mm_xor_si128 (xmm_dst, mask_ff000000), 24)));
1429 /* if some alpha src is grater than respective ~alpha dst */
1432 s = combine1 (ps++, pm);
1434 *pd++ = core_combine_saturate_u_pixel_sse2 (s, d);
1438 s = combine1 (ps++, pm);
1440 *pd++ = core_combine_saturate_u_pixel_sse2 (s, d);
1444 s = combine1 (ps++, pm);
1446 *pd++ = core_combine_saturate_u_pixel_sse2 (s, d);
1450 s = combine1 (ps++, pm);
1452 *pd++ = core_combine_saturate_u_pixel_sse2 (s, d);
1458 save_128_aligned ((__m128i*)pd, _mm_adds_epu8 (xmm_dst, xmm_src));
1471 s = combine1 (ps, pm);
1474 *pd++ = core_combine_saturate_u_pixel_sse2 (s, d);
1482 sse2_combine_src_ca (pixman_implementation_t *imp,
1485 const uint32_t * ps,
1486 const uint32_t * pm,
1491 __m128i xmm_src_lo, xmm_src_hi;
1492 __m128i xmm_mask_lo, xmm_mask_hi;
1493 __m128i xmm_dst_lo, xmm_dst_hi;
1495 while (w && (unsigned long)pd & 15)
1499 *pd++ = pack_1x128_32 (
1500 pix_multiply_1x128 (unpack_32_1x128 (s), unpack_32_1x128 (m)));
1506 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
1507 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
1509 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
1510 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
1512 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
1513 &xmm_mask_lo, &xmm_mask_hi,
1514 &xmm_dst_lo, &xmm_dst_hi);
1517 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
1529 *pd++ = pack_1x128_32 (
1530 pix_multiply_1x128 (unpack_32_1x128 (s), unpack_32_1x128 (m)));
1535 static force_inline uint32_t
1536 core_combine_over_ca_pixel_sse2 (uint32_t src,
1540 __m128i s = unpack_32_1x128 (src);
1541 __m128i expAlpha = expand_alpha_1x128 (s);
1542 __m128i unpk_mask = unpack_32_1x128 (mask);
1543 __m128i unpk_dst = unpack_32_1x128 (dst);
1545 return pack_1x128_32 (in_over_1x128 (&s, &expAlpha, &unpk_mask, &unpk_dst));
1549 sse2_combine_over_ca (pixman_implementation_t *imp,
1552 const uint32_t * ps,
1553 const uint32_t * pm,
1558 __m128i xmm_alpha_lo, xmm_alpha_hi;
1559 __m128i xmm_src_lo, xmm_src_hi;
1560 __m128i xmm_dst_lo, xmm_dst_hi;
1561 __m128i xmm_mask_lo, xmm_mask_hi;
1563 while (w && (unsigned long)pd & 15)
1569 *pd++ = core_combine_over_ca_pixel_sse2 (s, m, d);
1575 xmm_dst_hi = load_128_aligned ((__m128i*)pd);
1576 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
1577 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
1579 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1580 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
1581 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
1583 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
1584 &xmm_alpha_lo, &xmm_alpha_hi);
1586 in_over_2x128 (&xmm_src_lo, &xmm_src_hi,
1587 &xmm_alpha_lo, &xmm_alpha_hi,
1588 &xmm_mask_lo, &xmm_mask_hi,
1589 &xmm_dst_lo, &xmm_dst_hi);
1592 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
1606 *pd++ = core_combine_over_ca_pixel_sse2 (s, m, d);
1611 static force_inline uint32_t
1612 core_combine_over_reverse_ca_pixel_sse2 (uint32_t src,
1616 __m128i d = unpack_32_1x128 (dst);
1618 return pack_1x128_32 (
1619 over_1x128 (d, expand_alpha_1x128 (d),
1620 pix_multiply_1x128 (unpack_32_1x128 (src),
1621 unpack_32_1x128 (mask))));
1625 sse2_combine_over_reverse_ca (pixman_implementation_t *imp,
1628 const uint32_t * ps,
1629 const uint32_t * pm,
1634 __m128i xmm_alpha_lo, xmm_alpha_hi;
1635 __m128i xmm_src_lo, xmm_src_hi;
1636 __m128i xmm_dst_lo, xmm_dst_hi;
1637 __m128i xmm_mask_lo, xmm_mask_hi;
1639 while (w && (unsigned long)pd & 15)
1645 *pd++ = core_combine_over_reverse_ca_pixel_sse2 (s, m, d);
1651 xmm_dst_hi = load_128_aligned ((__m128i*)pd);
1652 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
1653 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
1655 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1656 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
1657 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
1659 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi,
1660 &xmm_alpha_lo, &xmm_alpha_hi);
1661 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
1662 &xmm_mask_lo, &xmm_mask_hi,
1663 &xmm_mask_lo, &xmm_mask_hi);
1665 over_2x128 (&xmm_dst_lo, &xmm_dst_hi,
1666 &xmm_alpha_lo, &xmm_alpha_hi,
1667 &xmm_mask_lo, &xmm_mask_hi);
1670 (__m128i*)pd, pack_2x128_128 (xmm_mask_lo, xmm_mask_hi));
1684 *pd++ = core_combine_over_reverse_ca_pixel_sse2 (s, m, d);
1690 sse2_combine_in_ca (pixman_implementation_t *imp,
1693 const uint32_t * ps,
1694 const uint32_t * pm,
1699 __m128i xmm_alpha_lo, xmm_alpha_hi;
1700 __m128i xmm_src_lo, xmm_src_hi;
1701 __m128i xmm_dst_lo, xmm_dst_hi;
1702 __m128i xmm_mask_lo, xmm_mask_hi;
1704 while (w && (unsigned long)pd & 15)
1710 *pd++ = pack_1x128_32 (
1711 pix_multiply_1x128 (
1712 pix_multiply_1x128 (unpack_32_1x128 (s), unpack_32_1x128 (m)),
1713 expand_alpha_1x128 (unpack_32_1x128 (d))));
1720 xmm_dst_hi = load_128_aligned ((__m128i*)pd);
1721 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
1722 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
1724 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1725 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
1726 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
1728 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi,
1729 &xmm_alpha_lo, &xmm_alpha_hi);
1731 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
1732 &xmm_mask_lo, &xmm_mask_hi,
1733 &xmm_dst_lo, &xmm_dst_hi);
1735 pix_multiply_2x128 (&xmm_dst_lo, &xmm_dst_hi,
1736 &xmm_alpha_lo, &xmm_alpha_hi,
1737 &xmm_dst_lo, &xmm_dst_hi);
1740 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
1754 *pd++ = pack_1x128_32 (
1755 pix_multiply_1x128 (
1756 pix_multiply_1x128 (
1757 unpack_32_1x128 (s), unpack_32_1x128 (m)),
1758 expand_alpha_1x128 (unpack_32_1x128 (d))));
1765 sse2_combine_in_reverse_ca (pixman_implementation_t *imp,
1768 const uint32_t * ps,
1769 const uint32_t * pm,
1774 __m128i xmm_alpha_lo, xmm_alpha_hi;
1775 __m128i xmm_src_lo, xmm_src_hi;
1776 __m128i xmm_dst_lo, xmm_dst_hi;
1777 __m128i xmm_mask_lo, xmm_mask_hi;
1779 while (w && (unsigned long)pd & 15)
1785 *pd++ = pack_1x128_32 (
1786 pix_multiply_1x128 (
1787 unpack_32_1x128 (d),
1788 pix_multiply_1x128 (unpack_32_1x128 (m),
1789 expand_alpha_1x128 (unpack_32_1x128 (s)))));
1795 xmm_dst_hi = load_128_aligned ((__m128i*)pd);
1796 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
1797 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
1799 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1800 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
1801 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
1803 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
1804 &xmm_alpha_lo, &xmm_alpha_hi);
1805 pix_multiply_2x128 (&xmm_mask_lo, &xmm_mask_hi,
1806 &xmm_alpha_lo, &xmm_alpha_hi,
1807 &xmm_alpha_lo, &xmm_alpha_hi);
1809 pix_multiply_2x128 (&xmm_dst_lo, &xmm_dst_hi,
1810 &xmm_alpha_lo, &xmm_alpha_hi,
1811 &xmm_dst_lo, &xmm_dst_hi);
1814 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
1828 *pd++ = pack_1x128_32 (
1829 pix_multiply_1x128 (
1830 unpack_32_1x128 (d),
1831 pix_multiply_1x128 (unpack_32_1x128 (m),
1832 expand_alpha_1x128 (unpack_32_1x128 (s)))));
1838 sse2_combine_out_ca (pixman_implementation_t *imp,
1841 const uint32_t * ps,
1842 const uint32_t * pm,
1847 __m128i xmm_alpha_lo, xmm_alpha_hi;
1848 __m128i xmm_src_lo, xmm_src_hi;
1849 __m128i xmm_dst_lo, xmm_dst_hi;
1850 __m128i xmm_mask_lo, xmm_mask_hi;
1852 while (w && (unsigned long)pd & 15)
1858 *pd++ = pack_1x128_32 (
1859 pix_multiply_1x128 (
1860 pix_multiply_1x128 (
1861 unpack_32_1x128 (s), unpack_32_1x128 (m)),
1862 negate_1x128 (expand_alpha_1x128 (unpack_32_1x128 (d)))));
1868 xmm_dst_hi = load_128_aligned ((__m128i*)pd);
1869 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
1870 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
1872 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1873 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
1874 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
1876 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi,
1877 &xmm_alpha_lo, &xmm_alpha_hi);
1878 negate_2x128 (xmm_alpha_lo, xmm_alpha_hi,
1879 &xmm_alpha_lo, &xmm_alpha_hi);
1881 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
1882 &xmm_mask_lo, &xmm_mask_hi,
1883 &xmm_dst_lo, &xmm_dst_hi);
1884 pix_multiply_2x128 (&xmm_dst_lo, &xmm_dst_hi,
1885 &xmm_alpha_lo, &xmm_alpha_hi,
1886 &xmm_dst_lo, &xmm_dst_hi);
1889 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
1903 *pd++ = pack_1x128_32 (
1904 pix_multiply_1x128 (
1905 pix_multiply_1x128 (
1906 unpack_32_1x128 (s), unpack_32_1x128 (m)),
1907 negate_1x128 (expand_alpha_1x128 (unpack_32_1x128 (d)))));
1914 sse2_combine_out_reverse_ca (pixman_implementation_t *imp,
1917 const uint32_t * ps,
1918 const uint32_t * pm,
1923 __m128i xmm_alpha_lo, xmm_alpha_hi;
1924 __m128i xmm_src_lo, xmm_src_hi;
1925 __m128i xmm_dst_lo, xmm_dst_hi;
1926 __m128i xmm_mask_lo, xmm_mask_hi;
1928 while (w && (unsigned long)pd & 15)
1934 *pd++ = pack_1x128_32 (
1935 pix_multiply_1x128 (
1936 unpack_32_1x128 (d),
1937 negate_1x128 (pix_multiply_1x128 (
1938 unpack_32_1x128 (m),
1939 expand_alpha_1x128 (unpack_32_1x128 (s))))));
1945 xmm_dst_hi = load_128_aligned ((__m128i*)pd);
1946 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
1947 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
1949 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
1950 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
1951 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
1953 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
1954 &xmm_alpha_lo, &xmm_alpha_hi);
1956 pix_multiply_2x128 (&xmm_mask_lo, &xmm_mask_hi,
1957 &xmm_alpha_lo, &xmm_alpha_hi,
1958 &xmm_mask_lo, &xmm_mask_hi);
1960 negate_2x128 (xmm_mask_lo, xmm_mask_hi,
1961 &xmm_mask_lo, &xmm_mask_hi);
1963 pix_multiply_2x128 (&xmm_dst_lo, &xmm_dst_hi,
1964 &xmm_mask_lo, &xmm_mask_hi,
1965 &xmm_dst_lo, &xmm_dst_hi);
1968 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
1982 *pd++ = pack_1x128_32 (
1983 pix_multiply_1x128 (
1984 unpack_32_1x128 (d),
1985 negate_1x128 (pix_multiply_1x128 (
1986 unpack_32_1x128 (m),
1987 expand_alpha_1x128 (unpack_32_1x128 (s))))));
1992 static force_inline uint32_t
1993 core_combine_atop_ca_pixel_sse2 (uint32_t src,
1997 __m128i m = unpack_32_1x128 (mask);
1998 __m128i s = unpack_32_1x128 (src);
1999 __m128i d = unpack_32_1x128 (dst);
2000 __m128i sa = expand_alpha_1x128 (s);
2001 __m128i da = expand_alpha_1x128 (d);
2003 s = pix_multiply_1x128 (s, m);
2004 m = negate_1x128 (pix_multiply_1x128 (m, sa));
2006 return pack_1x128_32 (pix_add_multiply_1x128 (&d, &m, &s, &da));
2010 sse2_combine_atop_ca (pixman_implementation_t *imp,
2013 const uint32_t * ps,
2014 const uint32_t * pm,
2019 __m128i xmm_src_lo, xmm_src_hi;
2020 __m128i xmm_dst_lo, xmm_dst_hi;
2021 __m128i xmm_alpha_src_lo, xmm_alpha_src_hi;
2022 __m128i xmm_alpha_dst_lo, xmm_alpha_dst_hi;
2023 __m128i xmm_mask_lo, xmm_mask_hi;
2025 while (w && (unsigned long)pd & 15)
2031 *pd++ = core_combine_atop_ca_pixel_sse2 (s, m, d);
2037 xmm_dst_hi = load_128_aligned ((__m128i*)pd);
2038 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
2039 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
2041 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
2042 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
2043 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
2045 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
2046 &xmm_alpha_src_lo, &xmm_alpha_src_hi);
2047 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi,
2048 &xmm_alpha_dst_lo, &xmm_alpha_dst_hi);
2050 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
2051 &xmm_mask_lo, &xmm_mask_hi,
2052 &xmm_src_lo, &xmm_src_hi);
2053 pix_multiply_2x128 (&xmm_mask_lo, &xmm_mask_hi,
2054 &xmm_alpha_src_lo, &xmm_alpha_src_hi,
2055 &xmm_mask_lo, &xmm_mask_hi);
2057 negate_2x128 (xmm_mask_lo, xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
2059 pix_add_multiply_2x128 (
2060 &xmm_dst_lo, &xmm_dst_hi, &xmm_mask_lo, &xmm_mask_hi,
2061 &xmm_src_lo, &xmm_src_hi, &xmm_alpha_dst_lo, &xmm_alpha_dst_hi,
2062 &xmm_dst_lo, &xmm_dst_hi);
2065 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
2079 *pd++ = core_combine_atop_ca_pixel_sse2 (s, m, d);
2084 static force_inline uint32_t
2085 core_combine_reverse_atop_ca_pixel_sse2 (uint32_t src,
2089 __m128i m = unpack_32_1x128 (mask);
2090 __m128i s = unpack_32_1x128 (src);
2091 __m128i d = unpack_32_1x128 (dst);
2093 __m128i da = negate_1x128 (expand_alpha_1x128 (d));
2094 __m128i sa = expand_alpha_1x128 (s);
2096 s = pix_multiply_1x128 (s, m);
2097 m = pix_multiply_1x128 (m, sa);
2099 return pack_1x128_32 (pix_add_multiply_1x128 (&d, &m, &s, &da));
2103 sse2_combine_atop_reverse_ca (pixman_implementation_t *imp,
2106 const uint32_t * ps,
2107 const uint32_t * pm,
2112 __m128i xmm_src_lo, xmm_src_hi;
2113 __m128i xmm_dst_lo, xmm_dst_hi;
2114 __m128i xmm_alpha_src_lo, xmm_alpha_src_hi;
2115 __m128i xmm_alpha_dst_lo, xmm_alpha_dst_hi;
2116 __m128i xmm_mask_lo, xmm_mask_hi;
2118 while (w && (unsigned long)pd & 15)
2124 *pd++ = core_combine_reverse_atop_ca_pixel_sse2 (s, m, d);
2130 xmm_dst_hi = load_128_aligned ((__m128i*)pd);
2131 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
2132 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
2134 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
2135 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
2136 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
2138 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
2139 &xmm_alpha_src_lo, &xmm_alpha_src_hi);
2140 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi,
2141 &xmm_alpha_dst_lo, &xmm_alpha_dst_hi);
2143 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
2144 &xmm_mask_lo, &xmm_mask_hi,
2145 &xmm_src_lo, &xmm_src_hi);
2146 pix_multiply_2x128 (&xmm_mask_lo, &xmm_mask_hi,
2147 &xmm_alpha_src_lo, &xmm_alpha_src_hi,
2148 &xmm_mask_lo, &xmm_mask_hi);
2150 negate_2x128 (xmm_alpha_dst_lo, xmm_alpha_dst_hi,
2151 &xmm_alpha_dst_lo, &xmm_alpha_dst_hi);
2153 pix_add_multiply_2x128 (
2154 &xmm_dst_lo, &xmm_dst_hi, &xmm_mask_lo, &xmm_mask_hi,
2155 &xmm_src_lo, &xmm_src_hi, &xmm_alpha_dst_lo, &xmm_alpha_dst_hi,
2156 &xmm_dst_lo, &xmm_dst_hi);
2159 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
2173 *pd++ = core_combine_reverse_atop_ca_pixel_sse2 (s, m, d);
2178 static force_inline uint32_t
2179 core_combine_xor_ca_pixel_sse2 (uint32_t src,
2183 __m128i a = unpack_32_1x128 (mask);
2184 __m128i s = unpack_32_1x128 (src);
2185 __m128i d = unpack_32_1x128 (dst);
2187 __m128i alpha_dst = negate_1x128 (pix_multiply_1x128 (
2188 a, expand_alpha_1x128 (s)));
2189 __m128i dest = pix_multiply_1x128 (s, a);
2190 __m128i alpha_src = negate_1x128 (expand_alpha_1x128 (d));
2192 return pack_1x128_32 (pix_add_multiply_1x128 (&d,
2199 sse2_combine_xor_ca (pixman_implementation_t *imp,
2202 const uint32_t * ps,
2203 const uint32_t * pm,
2208 __m128i xmm_src_lo, xmm_src_hi;
2209 __m128i xmm_dst_lo, xmm_dst_hi;
2210 __m128i xmm_alpha_src_lo, xmm_alpha_src_hi;
2211 __m128i xmm_alpha_dst_lo, xmm_alpha_dst_hi;
2212 __m128i xmm_mask_lo, xmm_mask_hi;
2214 while (w && (unsigned long)pd & 15)
2220 *pd++ = core_combine_xor_ca_pixel_sse2 (s, m, d);
2226 xmm_dst_hi = load_128_aligned ((__m128i*)pd);
2227 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
2228 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
2230 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
2231 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
2232 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
2234 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
2235 &xmm_alpha_src_lo, &xmm_alpha_src_hi);
2236 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi,
2237 &xmm_alpha_dst_lo, &xmm_alpha_dst_hi);
2239 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
2240 &xmm_mask_lo, &xmm_mask_hi,
2241 &xmm_src_lo, &xmm_src_hi);
2242 pix_multiply_2x128 (&xmm_mask_lo, &xmm_mask_hi,
2243 &xmm_alpha_src_lo, &xmm_alpha_src_hi,
2244 &xmm_mask_lo, &xmm_mask_hi);
2246 negate_2x128 (xmm_alpha_dst_lo, xmm_alpha_dst_hi,
2247 &xmm_alpha_dst_lo, &xmm_alpha_dst_hi);
2248 negate_2x128 (xmm_mask_lo, xmm_mask_hi,
2249 &xmm_mask_lo, &xmm_mask_hi);
2251 pix_add_multiply_2x128 (
2252 &xmm_dst_lo, &xmm_dst_hi, &xmm_mask_lo, &xmm_mask_hi,
2253 &xmm_src_lo, &xmm_src_hi, &xmm_alpha_dst_lo, &xmm_alpha_dst_hi,
2254 &xmm_dst_lo, &xmm_dst_hi);
2257 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
2271 *pd++ = core_combine_xor_ca_pixel_sse2 (s, m, d);
2277 sse2_combine_add_ca (pixman_implementation_t *imp,
2280 const uint32_t * ps,
2281 const uint32_t * pm,
2286 __m128i xmm_src_lo, xmm_src_hi;
2287 __m128i xmm_dst_lo, xmm_dst_hi;
2288 __m128i xmm_mask_lo, xmm_mask_hi;
2290 while (w && (unsigned long)pd & 15)
2296 *pd++ = pack_1x128_32 (
2297 _mm_adds_epu8 (pix_multiply_1x128 (unpack_32_1x128 (s),
2298 unpack_32_1x128 (m)),
2299 unpack_32_1x128 (d)));
2305 xmm_src_hi = load_128_unaligned ((__m128i*)ps);
2306 xmm_mask_hi = load_128_unaligned ((__m128i*)pm);
2307 xmm_dst_hi = load_128_aligned ((__m128i*)pd);
2309 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
2310 unpack_128_2x128 (xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
2311 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
2313 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
2314 &xmm_mask_lo, &xmm_mask_hi,
2315 &xmm_src_lo, &xmm_src_hi);
2318 (__m128i*)pd, pack_2x128_128 (
2319 _mm_adds_epu8 (xmm_src_lo, xmm_dst_lo),
2320 _mm_adds_epu8 (xmm_src_hi, xmm_dst_hi)));
2334 *pd++ = pack_1x128_32 (
2335 _mm_adds_epu8 (pix_multiply_1x128 (unpack_32_1x128 (s),
2336 unpack_32_1x128 (m)),
2337 unpack_32_1x128 (d)));
2342 static force_inline __m128i
2343 create_mask_16_128 (uint16_t mask)
2345 return _mm_set1_epi16 (mask);
2348 /* Work around a code generation bug in Sun Studio 12. */
2349 #if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
2350 # define create_mask_2x32_128(mask0, mask1) \
2351 (_mm_set_epi32 ((mask0), (mask1), (mask0), (mask1)))
2353 static force_inline __m128i
2354 create_mask_2x32_128 (uint32_t mask0,
2357 return _mm_set_epi32 (mask0, mask1, mask0, mask1);
2362 sse2_composite_over_n_8888 (pixman_implementation_t *imp,
2364 pixman_image_t * src_image,
2365 pixman_image_t * mask_image,
2366 pixman_image_t * dst_image,
2377 uint32_t *dst_line, *dst, d;
2380 __m128i xmm_src, xmm_alpha;
2381 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
2383 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
2388 PIXMAN_IMAGE_GET_LINE (
2389 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
2391 xmm_src = expand_pixel_32_1x128 (src);
2392 xmm_alpha = expand_alpha_1x128 (xmm_src);
2398 dst_line += dst_stride;
2401 while (w && (unsigned long)dst & 15)
2404 *dst++ = pack_1x128_32 (over_1x128 (xmm_src,
2406 unpack_32_1x128 (d)));
2412 xmm_dst = load_128_aligned ((__m128i*)dst);
2414 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
2416 over_2x128 (&xmm_src, &xmm_src,
2417 &xmm_alpha, &xmm_alpha,
2418 &xmm_dst_lo, &xmm_dst_hi);
2420 /* rebuid the 4 pixel data and save*/
2422 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
2431 *dst++ = pack_1x128_32 (over_1x128 (xmm_src,
2433 unpack_32_1x128 (d)));
2441 sse2_composite_over_n_0565 (pixman_implementation_t *imp,
2443 pixman_image_t * src_image,
2444 pixman_image_t * mask_image,
2445 pixman_image_t * dst_image,
2456 uint16_t *dst_line, *dst, d;
2459 __m128i xmm_src, xmm_alpha;
2460 __m128i xmm_dst, xmm_dst0, xmm_dst1, xmm_dst2, xmm_dst3;
2462 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
2467 PIXMAN_IMAGE_GET_LINE (
2468 dst_image, dest_x, dest_y, uint16_t, dst_stride, dst_line, 1);
2470 xmm_src = expand_pixel_32_1x128 (src);
2471 xmm_alpha = expand_alpha_1x128 (xmm_src);
2477 dst_line += dst_stride;
2480 while (w && (unsigned long)dst & 15)
2484 *dst++ = pack_565_32_16 (
2485 pack_1x128_32 (over_1x128 (xmm_src,
2487 expand565_16_1x128 (d))));
2493 xmm_dst = load_128_aligned ((__m128i*)dst);
2495 unpack_565_128_4x128 (xmm_dst,
2496 &xmm_dst0, &xmm_dst1, &xmm_dst2, &xmm_dst3);
2498 over_2x128 (&xmm_src, &xmm_src,
2499 &xmm_alpha, &xmm_alpha,
2500 &xmm_dst0, &xmm_dst1);
2501 over_2x128 (&xmm_src, &xmm_src,
2502 &xmm_alpha, &xmm_alpha,
2503 &xmm_dst2, &xmm_dst3);
2505 xmm_dst = pack_565_4x128_128 (
2506 &xmm_dst0, &xmm_dst1, &xmm_dst2, &xmm_dst3);
2508 save_128_aligned ((__m128i*)dst, xmm_dst);
2517 *dst++ = pack_565_32_16 (
2518 pack_1x128_32 (over_1x128 (xmm_src, xmm_alpha,
2519 expand565_16_1x128 (d))));
2526 sse2_composite_add_n_8888_8888_ca (pixman_implementation_t *imp,
2528 pixman_image_t * src_image,
2529 pixman_image_t * mask_image,
2530 pixman_image_t * dst_image,
2541 uint32_t *dst_line, d;
2542 uint32_t *mask_line, m;
2544 int dst_stride, mask_stride;
2546 __m128i xmm_src, xmm_alpha;
2548 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
2550 __m128i mmx_src, mmx_alpha, mmx_mask, mmx_dest;
2552 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
2558 PIXMAN_IMAGE_GET_LINE (
2559 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
2560 PIXMAN_IMAGE_GET_LINE (
2561 mask_image, mask_x, mask_y, uint32_t, mask_stride, mask_line, 1);
2563 xmm_src = _mm_unpacklo_epi8 (
2564 create_mask_2x32_128 (src, src), _mm_setzero_si128 ());
2565 xmm_alpha = expand_alpha_1x128 (xmm_src);
2567 mmx_alpha = xmm_alpha;
2572 const uint32_t *pm = (uint32_t *)mask_line;
2573 uint32_t *pd = (uint32_t *)dst_line;
2575 dst_line += dst_stride;
2576 mask_line += mask_stride;
2578 while (w && (unsigned long)pd & 15)
2586 mmx_mask = unpack_32_1x128 (m);
2587 mmx_dest = unpack_32_1x128 (d);
2589 *pd = pack_1x128_32 (
2590 _mm_adds_epu8 (pix_multiply_1x128 (mmx_mask, mmx_src),
2600 xmm_mask = load_128_unaligned ((__m128i*)pm);
2604 _mm_cmpeq_epi32 (xmm_mask, _mm_setzero_si128 ()));
2606 /* if all bits in mask are zero, pack_cmp are equal to 0xffff */
2607 if (pack_cmp != 0xffff)
2609 xmm_dst = load_128_aligned ((__m128i*)pd);
2611 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
2613 pix_multiply_2x128 (&xmm_src, &xmm_src,
2614 &xmm_mask_lo, &xmm_mask_hi,
2615 &xmm_mask_lo, &xmm_mask_hi);
2616 xmm_mask_hi = pack_2x128_128 (xmm_mask_lo, xmm_mask_hi);
2619 (__m128i*)pd, _mm_adds_epu8 (xmm_mask_hi, xmm_dst));
2635 mmx_mask = unpack_32_1x128 (m);
2636 mmx_dest = unpack_32_1x128 (d);
2638 *pd = pack_1x128_32 (
2639 _mm_adds_epu8 (pix_multiply_1x128 (mmx_mask, mmx_src),
2651 sse2_composite_over_n_8888_8888_ca (pixman_implementation_t *imp,
2653 pixman_image_t * src_image,
2654 pixman_image_t * mask_image,
2655 pixman_image_t * dst_image,
2666 uint32_t *dst_line, d;
2667 uint32_t *mask_line, m;
2669 int dst_stride, mask_stride;
2671 __m128i xmm_src, xmm_alpha;
2672 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
2673 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
2675 __m128i mmx_src, mmx_alpha, mmx_mask, mmx_dest;
2677 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
2682 PIXMAN_IMAGE_GET_LINE (
2683 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
2684 PIXMAN_IMAGE_GET_LINE (
2685 mask_image, mask_x, mask_y, uint32_t, mask_stride, mask_line, 1);
2687 xmm_src = _mm_unpacklo_epi8 (
2688 create_mask_2x32_128 (src, src), _mm_setzero_si128 ());
2689 xmm_alpha = expand_alpha_1x128 (xmm_src);
2691 mmx_alpha = xmm_alpha;
2696 const uint32_t *pm = (uint32_t *)mask_line;
2697 uint32_t *pd = (uint32_t *)dst_line;
2699 dst_line += dst_stride;
2700 mask_line += mask_stride;
2702 while (w && (unsigned long)pd & 15)
2709 mmx_mask = unpack_32_1x128 (m);
2710 mmx_dest = unpack_32_1x128 (d);
2712 *pd = pack_1x128_32 (in_over_1x128 (&mmx_src,
2724 xmm_mask = load_128_unaligned ((__m128i*)pm);
2728 _mm_cmpeq_epi32 (xmm_mask, _mm_setzero_si128 ()));
2730 /* if all bits in mask are zero, pack_cmp are equal to 0xffff */
2731 if (pack_cmp != 0xffff)
2733 xmm_dst = load_128_aligned ((__m128i*)pd);
2735 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
2736 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
2738 in_over_2x128 (&xmm_src, &xmm_src,
2739 &xmm_alpha, &xmm_alpha,
2740 &xmm_mask_lo, &xmm_mask_hi,
2741 &xmm_dst_lo, &xmm_dst_hi);
2744 (__m128i*)pd, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
2759 mmx_mask = unpack_32_1x128 (m);
2760 mmx_dest = unpack_32_1x128 (d);
2762 *pd = pack_1x128_32 (
2763 in_over_1x128 (&mmx_src, &mmx_alpha, &mmx_mask, &mmx_dest));
2774 sse2_composite_over_8888_n_8888 (pixman_implementation_t *imp,
2776 pixman_image_t * src_image,
2777 pixman_image_t * mask_image,
2778 pixman_image_t * dst_image,
2788 uint32_t *dst_line, *dst;
2789 uint32_t *src_line, *src;
2792 int dst_stride, src_stride;
2795 __m128i xmm_src, xmm_src_lo, xmm_src_hi;
2796 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
2797 __m128i xmm_alpha_lo, xmm_alpha_hi;
2799 PIXMAN_IMAGE_GET_LINE (
2800 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
2801 PIXMAN_IMAGE_GET_LINE (
2802 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
2804 mask = _pixman_image_get_solid (imp, mask_image, PIXMAN_a8r8g8b8);
2806 xmm_mask = create_mask_16_128 (mask >> 24);
2811 dst_line += dst_stride;
2813 src_line += src_stride;
2816 while (w && (unsigned long)dst & 15)
2818 uint32_t s = *src++;
2824 __m128i ms = unpack_32_1x128 (s);
2825 __m128i alpha = expand_alpha_1x128 (ms);
2826 __m128i dest = xmm_mask;
2827 __m128i alpha_dst = unpack_32_1x128 (d);
2829 *dst = pack_1x128_32 (
2830 in_over_1x128 (&ms, &alpha, &dest, &alpha_dst));
2838 xmm_src = load_128_unaligned ((__m128i*)src);
2840 if (!is_zero (xmm_src))
2842 xmm_dst = load_128_aligned ((__m128i*)dst);
2844 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
2845 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
2846 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
2847 &xmm_alpha_lo, &xmm_alpha_hi);
2849 in_over_2x128 (&xmm_src_lo, &xmm_src_hi,
2850 &xmm_alpha_lo, &xmm_alpha_hi,
2851 &xmm_mask, &xmm_mask,
2852 &xmm_dst_lo, &xmm_dst_hi);
2855 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
2865 uint32_t s = *src++;
2871 __m128i ms = unpack_32_1x128 (s);
2872 __m128i alpha = expand_alpha_1x128 (ms);
2873 __m128i mask = xmm_mask;
2874 __m128i dest = unpack_32_1x128 (d);
2876 *dst = pack_1x128_32 (
2877 in_over_1x128 (&ms, &alpha, &mask, &dest));
2888 sse2_composite_src_x888_8888 (pixman_implementation_t *imp,
2890 pixman_image_t * src_image,
2891 pixman_image_t * mask_image,
2892 pixman_image_t * dst_image,
2902 uint32_t *dst_line, *dst;
2903 uint32_t *src_line, *src;
2905 int dst_stride, src_stride;
2908 PIXMAN_IMAGE_GET_LINE (
2909 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
2910 PIXMAN_IMAGE_GET_LINE (
2911 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
2916 dst_line += dst_stride;
2918 src_line += src_stride;
2921 while (w && (unsigned long)dst & 15)
2923 *dst++ = *src++ | 0xff000000;
2929 __m128i xmm_src1, xmm_src2, xmm_src3, xmm_src4;
2931 xmm_src1 = load_128_unaligned ((__m128i*)src + 0);
2932 xmm_src2 = load_128_unaligned ((__m128i*)src + 1);
2933 xmm_src3 = load_128_unaligned ((__m128i*)src + 2);
2934 xmm_src4 = load_128_unaligned ((__m128i*)src + 3);
2936 save_128_aligned ((__m128i*)dst + 0, _mm_or_si128 (xmm_src1, mask_ff000000));
2937 save_128_aligned ((__m128i*)dst + 1, _mm_or_si128 (xmm_src2, mask_ff000000));
2938 save_128_aligned ((__m128i*)dst + 2, _mm_or_si128 (xmm_src3, mask_ff000000));
2939 save_128_aligned ((__m128i*)dst + 3, _mm_or_si128 (xmm_src4, mask_ff000000));
2948 *dst++ = *src++ | 0xff000000;
2956 sse2_composite_over_x888_n_8888 (pixman_implementation_t *imp,
2958 pixman_image_t * src_image,
2959 pixman_image_t * mask_image,
2960 pixman_image_t * dst_image,
2970 uint32_t *dst_line, *dst;
2971 uint32_t *src_line, *src;
2973 int dst_stride, src_stride;
2976 __m128i xmm_mask, xmm_alpha;
2977 __m128i xmm_src, xmm_src_lo, xmm_src_hi;
2978 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
2980 PIXMAN_IMAGE_GET_LINE (
2981 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
2982 PIXMAN_IMAGE_GET_LINE (
2983 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
2985 mask = _pixman_image_get_solid (imp, mask_image, PIXMAN_a8r8g8b8);
2987 xmm_mask = create_mask_16_128 (mask >> 24);
2988 xmm_alpha = mask_00ff;
2993 dst_line += dst_stride;
2995 src_line += src_stride;
2998 while (w && (unsigned long)dst & 15)
3000 uint32_t s = (*src++) | 0xff000000;
3003 __m128i src = unpack_32_1x128 (s);
3004 __m128i alpha = xmm_alpha;
3005 __m128i mask = xmm_mask;
3006 __m128i dest = unpack_32_1x128 (d);
3008 *dst++ = pack_1x128_32 (
3009 in_over_1x128 (&src, &alpha, &mask, &dest));
3016 xmm_src = _mm_or_si128 (
3017 load_128_unaligned ((__m128i*)src), mask_ff000000);
3018 xmm_dst = load_128_aligned ((__m128i*)dst);
3020 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
3021 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
3023 in_over_2x128 (&xmm_src_lo, &xmm_src_hi,
3024 &xmm_alpha, &xmm_alpha,
3025 &xmm_mask, &xmm_mask,
3026 &xmm_dst_lo, &xmm_dst_hi);
3029 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
3039 uint32_t s = (*src++) | 0xff000000;
3042 __m128i src = unpack_32_1x128 (s);
3043 __m128i alpha = xmm_alpha;
3044 __m128i mask = xmm_mask;
3045 __m128i dest = unpack_32_1x128 (d);
3047 *dst++ = pack_1x128_32 (
3048 in_over_1x128 (&src, &alpha, &mask, &dest));
3057 sse2_composite_over_8888_8888 (pixman_implementation_t *imp,
3059 pixman_image_t * src_image,
3060 pixman_image_t * mask_image,
3061 pixman_image_t * dst_image,
3071 int dst_stride, src_stride;
3072 uint32_t *dst_line, *dst;
3073 uint32_t *src_line, *src;
3075 PIXMAN_IMAGE_GET_LINE (
3076 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
3077 PIXMAN_IMAGE_GET_LINE (
3078 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
3085 sse2_combine_over_u (imp, op, dst, src, NULL, width);
3092 static force_inline uint16_t
3093 composite_over_8888_0565pixel (uint32_t src, uint16_t dst)
3097 ms = unpack_32_1x128 (src);
3098 return pack_565_32_16 (
3101 ms, expand_alpha_1x128 (ms), expand565_16_1x128 (dst))));
3105 sse2_composite_over_8888_0565 (pixman_implementation_t *imp,
3107 pixman_image_t * src_image,
3108 pixman_image_t * mask_image,
3109 pixman_image_t * dst_image,
3119 uint16_t *dst_line, *dst, d;
3120 uint32_t *src_line, *src, s;
3121 int dst_stride, src_stride;
3124 __m128i xmm_alpha_lo, xmm_alpha_hi;
3125 __m128i xmm_src, xmm_src_lo, xmm_src_hi;
3126 __m128i xmm_dst, xmm_dst0, xmm_dst1, xmm_dst2, xmm_dst3;
3128 PIXMAN_IMAGE_GET_LINE (
3129 dst_image, dest_x, dest_y, uint16_t, dst_stride, dst_line, 1);
3130 PIXMAN_IMAGE_GET_LINE (
3131 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
3138 dst_line += dst_stride;
3139 src_line += src_stride;
3142 /* Align dst on a 16-byte boundary */
3144 ((unsigned long)dst & 15))
3149 *dst++ = composite_over_8888_0565pixel (s, d);
3153 /* It's a 8 pixel loop */
3156 /* I'm loading unaligned because I'm not sure
3157 * about the address alignment.
3159 xmm_src = load_128_unaligned ((__m128i*) src);
3160 xmm_dst = load_128_aligned ((__m128i*) dst);
3163 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
3164 unpack_565_128_4x128 (xmm_dst,
3165 &xmm_dst0, &xmm_dst1, &xmm_dst2, &xmm_dst3);
3166 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
3167 &xmm_alpha_lo, &xmm_alpha_hi);
3169 /* I'm loading next 4 pixels from memory
3170 * before to optimze the memory read.
3172 xmm_src = load_128_unaligned ((__m128i*) (src + 4));
3174 over_2x128 (&xmm_src_lo, &xmm_src_hi,
3175 &xmm_alpha_lo, &xmm_alpha_hi,
3176 &xmm_dst0, &xmm_dst1);
3179 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
3180 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
3181 &xmm_alpha_lo, &xmm_alpha_hi);
3183 over_2x128 (&xmm_src_lo, &xmm_src_hi,
3184 &xmm_alpha_lo, &xmm_alpha_hi,
3185 &xmm_dst2, &xmm_dst3);
3188 (__m128i*)dst, pack_565_4x128_128 (
3189 &xmm_dst0, &xmm_dst1, &xmm_dst2, &xmm_dst3));
3201 *dst++ = composite_over_8888_0565pixel (s, d);
3208 sse2_composite_over_n_8_8888 (pixman_implementation_t *imp,
3210 pixman_image_t * src_image,
3211 pixman_image_t * mask_image,
3212 pixman_image_t * dst_image,
3223 uint32_t *dst_line, *dst;
3224 uint8_t *mask_line, *mask;
3225 int dst_stride, mask_stride;
3229 __m128i xmm_src, xmm_alpha, xmm_def;
3230 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
3231 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
3233 __m128i mmx_src, mmx_alpha, mmx_mask, mmx_dest;
3235 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
3241 PIXMAN_IMAGE_GET_LINE (
3242 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
3243 PIXMAN_IMAGE_GET_LINE (
3244 mask_image, mask_x, mask_y, uint8_t, mask_stride, mask_line, 1);
3246 xmm_def = create_mask_2x32_128 (src, src);
3247 xmm_src = expand_pixel_32_1x128 (src);
3248 xmm_alpha = expand_alpha_1x128 (xmm_src);
3250 mmx_alpha = xmm_alpha;
3255 dst_line += dst_stride;
3257 mask_line += mask_stride;
3260 while (w && (unsigned long)dst & 15)
3262 uint8_t m = *mask++;
3267 mmx_mask = expand_pixel_8_1x128 (m);
3268 mmx_dest = unpack_32_1x128 (d);
3270 *dst = pack_1x128_32 (in_over_1x128 (&mmx_src,
3282 m = *((uint32_t*)mask);
3284 if (srca == 0xff && m == 0xffffffff)
3286 save_128_aligned ((__m128i*)dst, xmm_def);
3290 xmm_dst = load_128_aligned ((__m128i*) dst);
3291 xmm_mask = unpack_32_1x128 (m);
3292 xmm_mask = _mm_unpacklo_epi8 (xmm_mask, _mm_setzero_si128 ());
3295 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
3296 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
3298 expand_alpha_rev_2x128 (xmm_mask_lo, xmm_mask_hi,
3299 &xmm_mask_lo, &xmm_mask_hi);
3301 in_over_2x128 (&xmm_src, &xmm_src,
3302 &xmm_alpha, &xmm_alpha,
3303 &xmm_mask_lo, &xmm_mask_hi,
3304 &xmm_dst_lo, &xmm_dst_hi);
3307 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
3317 uint8_t m = *mask++;
3322 mmx_mask = expand_pixel_8_1x128 (m);
3323 mmx_dest = unpack_32_1x128 (d);
3325 *dst = pack_1x128_32 (in_over_1x128 (&mmx_src,
3338 static pixman_bool_t
3339 pixman_fill_sse2 (uint32_t *bits,
3348 uint32_t byte_width;
3358 stride = stride * (int) sizeof (uint32_t) / 1;
3359 byte_line = (uint8_t *)(((uint8_t *)bits) + stride * y + x);
3365 data = (w << 16) | w;
3369 stride = stride * (int) sizeof (uint32_t) / 2;
3370 byte_line = (uint8_t *)(((uint16_t *)bits) + stride * y + x);
3371 byte_width = 2 * width;
3374 data = (data & 0xffff) * 0x00010001;
3378 stride = stride * (int) sizeof (uint32_t) / 4;
3379 byte_line = (uint8_t *)(((uint32_t *)bits) + stride * y + x);
3380 byte_width = 4 * width;
3388 xmm_def = create_mask_2x32_128 (data, data);
3393 uint8_t *d = byte_line;
3394 byte_line += stride;
3397 while (w >= 1 && ((unsigned long)d & 1))
3399 *(uint8_t *)d = data;
3404 while (w >= 2 && ((unsigned long)d & 3))
3406 *(uint16_t *)d = data;
3411 while (w >= 4 && ((unsigned long)d & 15))
3413 *(uint32_t *)d = data;
3421 save_128_aligned ((__m128i*)(d), xmm_def);
3422 save_128_aligned ((__m128i*)(d + 16), xmm_def);
3423 save_128_aligned ((__m128i*)(d + 32), xmm_def);
3424 save_128_aligned ((__m128i*)(d + 48), xmm_def);
3425 save_128_aligned ((__m128i*)(d + 64), xmm_def);
3426 save_128_aligned ((__m128i*)(d + 80), xmm_def);
3427 save_128_aligned ((__m128i*)(d + 96), xmm_def);
3428 save_128_aligned ((__m128i*)(d + 112), xmm_def);
3436 save_128_aligned ((__m128i*)(d), xmm_def);
3437 save_128_aligned ((__m128i*)(d + 16), xmm_def);
3438 save_128_aligned ((__m128i*)(d + 32), xmm_def);
3439 save_128_aligned ((__m128i*)(d + 48), xmm_def);
3447 save_128_aligned ((__m128i*)(d), xmm_def);
3448 save_128_aligned ((__m128i*)(d + 16), xmm_def);
3456 save_128_aligned ((__m128i*)(d), xmm_def);
3464 *(uint32_t *)d = data;
3472 *(uint16_t *)d = data;
3479 *(uint8_t *)d = data;
3489 sse2_composite_src_n_8_8888 (pixman_implementation_t *imp,
3491 pixman_image_t * src_image,
3492 pixman_image_t * mask_image,
3493 pixman_image_t * dst_image,
3504 uint32_t *dst_line, *dst;
3505 uint8_t *mask_line, *mask;
3506 int dst_stride, mask_stride;
3510 __m128i xmm_src, xmm_def;
3511 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
3513 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
3518 pixman_fill_sse2 (dst_image->bits.bits, dst_image->bits.rowstride,
3519 PIXMAN_FORMAT_BPP (dst_image->bits.format),
3520 dest_x, dest_y, width, height, 0);
3524 PIXMAN_IMAGE_GET_LINE (
3525 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
3526 PIXMAN_IMAGE_GET_LINE (
3527 mask_image, mask_x, mask_y, uint8_t, mask_stride, mask_line, 1);
3529 xmm_def = create_mask_2x32_128 (src, src);
3530 xmm_src = expand_pixel_32_1x128 (src);
3535 dst_line += dst_stride;
3537 mask_line += mask_stride;
3540 while (w && (unsigned long)dst & 15)
3542 uint8_t m = *mask++;
3546 *dst = pack_1x128_32 (
3547 pix_multiply_1x128 (xmm_src, expand_pixel_8_1x128 (m)));
3560 m = *((uint32_t*)mask);
3562 if (srca == 0xff && m == 0xffffffff)
3564 save_128_aligned ((__m128i*)dst, xmm_def);
3568 xmm_mask = unpack_32_1x128 (m);
3569 xmm_mask = _mm_unpacklo_epi8 (xmm_mask, _mm_setzero_si128 ());
3572 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
3574 expand_alpha_rev_2x128 (xmm_mask_lo, xmm_mask_hi,
3575 &xmm_mask_lo, &xmm_mask_hi);
3577 pix_multiply_2x128 (&xmm_src, &xmm_src,
3578 &xmm_mask_lo, &xmm_mask_hi,
3579 &xmm_mask_lo, &xmm_mask_hi);
3582 (__m128i*)dst, pack_2x128_128 (xmm_mask_lo, xmm_mask_hi));
3586 save_128_aligned ((__m128i*)dst, _mm_setzero_si128 ());
3596 uint8_t m = *mask++;
3600 *dst = pack_1x128_32 (
3601 pix_multiply_1x128 (
3602 xmm_src, expand_pixel_8_1x128 (m)));
3617 sse2_composite_over_n_8_0565 (pixman_implementation_t *imp,
3619 pixman_image_t * src_image,
3620 pixman_image_t * mask_image,
3621 pixman_image_t * dst_image,
3632 uint16_t *dst_line, *dst, d;
3633 uint8_t *mask_line, *mask;
3634 int dst_stride, mask_stride;
3637 __m128i mmx_src, mmx_alpha, mmx_mask, mmx_dest;
3639 __m128i xmm_src, xmm_alpha;
3640 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
3641 __m128i xmm_dst, xmm_dst0, xmm_dst1, xmm_dst2, xmm_dst3;
3643 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
3649 PIXMAN_IMAGE_GET_LINE (
3650 dst_image, dest_x, dest_y, uint16_t, dst_stride, dst_line, 1);
3651 PIXMAN_IMAGE_GET_LINE (
3652 mask_image, mask_x, mask_y, uint8_t, mask_stride, mask_line, 1);
3654 xmm_src = expand_pixel_32_1x128 (src);
3655 xmm_alpha = expand_alpha_1x128 (xmm_src);
3657 mmx_alpha = xmm_alpha;
3662 dst_line += dst_stride;
3664 mask_line += mask_stride;
3667 while (w && (unsigned long)dst & 15)
3674 mmx_mask = expand_alpha_rev_1x128 (unpack_32_1x128 (m));
3675 mmx_dest = expand565_16_1x128 (d);
3677 *dst = pack_565_32_16 (
3680 &mmx_src, &mmx_alpha, &mmx_mask, &mmx_dest)));
3689 xmm_dst = load_128_aligned ((__m128i*) dst);
3690 unpack_565_128_4x128 (xmm_dst,
3691 &xmm_dst0, &xmm_dst1, &xmm_dst2, &xmm_dst3);
3693 m = *((uint32_t*)mask);
3698 xmm_mask = unpack_32_1x128 (m);
3699 xmm_mask = _mm_unpacklo_epi8 (xmm_mask, _mm_setzero_si128 ());
3702 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
3704 expand_alpha_rev_2x128 (xmm_mask_lo, xmm_mask_hi,
3705 &xmm_mask_lo, &xmm_mask_hi);
3707 in_over_2x128 (&xmm_src, &xmm_src,
3708 &xmm_alpha, &xmm_alpha,
3709 &xmm_mask_lo, &xmm_mask_hi,
3710 &xmm_dst0, &xmm_dst1);
3713 m = *((uint32_t*)mask);
3718 xmm_mask = unpack_32_1x128 (m);
3719 xmm_mask = _mm_unpacklo_epi8 (xmm_mask, _mm_setzero_si128 ());
3722 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
3724 expand_alpha_rev_2x128 (xmm_mask_lo, xmm_mask_hi,
3725 &xmm_mask_lo, &xmm_mask_hi);
3726 in_over_2x128 (&xmm_src, &xmm_src,
3727 &xmm_alpha, &xmm_alpha,
3728 &xmm_mask_lo, &xmm_mask_hi,
3729 &xmm_dst2, &xmm_dst3);
3733 (__m128i*)dst, pack_565_4x128_128 (
3734 &xmm_dst0, &xmm_dst1, &xmm_dst2, &xmm_dst3));
3747 mmx_mask = expand_alpha_rev_1x128 (unpack_32_1x128 (m));
3748 mmx_dest = expand565_16_1x128 (d);
3750 *dst = pack_565_32_16 (
3753 &mmx_src, &mmx_alpha, &mmx_mask, &mmx_dest)));
3764 sse2_composite_over_pixbuf_0565 (pixman_implementation_t *imp,
3766 pixman_image_t * src_image,
3767 pixman_image_t * mask_image,
3768 pixman_image_t * dst_image,
3778 uint16_t *dst_line, *dst, d;
3779 uint32_t *src_line, *src, s;
3780 int dst_stride, src_stride;
3782 uint32_t opaque, zero;
3785 __m128i xmm_src, xmm_src_lo, xmm_src_hi;
3786 __m128i xmm_dst, xmm_dst0, xmm_dst1, xmm_dst2, xmm_dst3;
3788 PIXMAN_IMAGE_GET_LINE (
3789 dst_image, dest_x, dest_y, uint16_t, dst_stride, dst_line, 1);
3790 PIXMAN_IMAGE_GET_LINE (
3791 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
3796 dst_line += dst_stride;
3798 src_line += src_stride;
3801 while (w && (unsigned long)dst & 15)
3806 ms = unpack_32_1x128 (s);
3808 *dst++ = pack_565_32_16 (
3810 over_rev_non_pre_1x128 (ms, expand565_16_1x128 (d))));
3817 xmm_src = load_128_unaligned ((__m128i*)src);
3818 xmm_dst = load_128_aligned ((__m128i*)dst);
3820 opaque = is_opaque (xmm_src);
3821 zero = is_zero (xmm_src);
3823 unpack_565_128_4x128 (xmm_dst,
3824 &xmm_dst0, &xmm_dst1, &xmm_dst2, &xmm_dst3);
3825 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
3827 /* preload next round*/
3828 xmm_src = load_128_unaligned ((__m128i*)(src + 4));
3832 invert_colors_2x128 (xmm_src_lo, xmm_src_hi,
3833 &xmm_dst0, &xmm_dst1);
3837 over_rev_non_pre_2x128 (xmm_src_lo, xmm_src_hi,
3838 &xmm_dst0, &xmm_dst1);
3842 opaque = is_opaque (xmm_src);
3843 zero = is_zero (xmm_src);
3845 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
3849 invert_colors_2x128 (xmm_src_lo, xmm_src_hi,
3850 &xmm_dst2, &xmm_dst3);
3854 over_rev_non_pre_2x128 (xmm_src_lo, xmm_src_hi,
3855 &xmm_dst2, &xmm_dst3);
3859 (__m128i*)dst, pack_565_4x128_128 (
3860 &xmm_dst0, &xmm_dst1, &xmm_dst2, &xmm_dst3));
3872 ms = unpack_32_1x128 (s);
3874 *dst++ = pack_565_32_16 (
3876 over_rev_non_pre_1x128 (ms, expand565_16_1x128 (d))));
3884 sse2_composite_over_pixbuf_8888 (pixman_implementation_t *imp,
3886 pixman_image_t * src_image,
3887 pixman_image_t * mask_image,
3888 pixman_image_t * dst_image,
3898 uint32_t *dst_line, *dst, d;
3899 uint32_t *src_line, *src, s;
3900 int dst_stride, src_stride;
3902 uint32_t opaque, zero;
3904 __m128i xmm_src_lo, xmm_src_hi;
3905 __m128i xmm_dst_lo, xmm_dst_hi;
3907 PIXMAN_IMAGE_GET_LINE (
3908 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
3909 PIXMAN_IMAGE_GET_LINE (
3910 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
3915 dst_line += dst_stride;
3917 src_line += src_stride;
3920 while (w && (unsigned long)dst & 15)
3925 *dst++ = pack_1x128_32 (
3926 over_rev_non_pre_1x128 (
3927 unpack_32_1x128 (s), unpack_32_1x128 (d)));
3934 xmm_src_hi = load_128_unaligned ((__m128i*)src);
3936 opaque = is_opaque (xmm_src_hi);
3937 zero = is_zero (xmm_src_hi);
3939 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
3943 invert_colors_2x128 (xmm_src_lo, xmm_src_hi,
3944 &xmm_dst_lo, &xmm_dst_hi);
3947 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
3951 xmm_dst_hi = load_128_aligned ((__m128i*)dst);
3953 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
3955 over_rev_non_pre_2x128 (xmm_src_lo, xmm_src_hi,
3956 &xmm_dst_lo, &xmm_dst_hi);
3959 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
3972 *dst++ = pack_1x128_32 (
3973 over_rev_non_pre_1x128 (
3974 unpack_32_1x128 (s), unpack_32_1x128 (d)));
3983 sse2_composite_over_n_8888_0565_ca (pixman_implementation_t *imp,
3985 pixman_image_t * src_image,
3986 pixman_image_t * mask_image,
3987 pixman_image_t * dst_image,
3998 uint16_t *dst_line, *dst, d;
3999 uint32_t *mask_line, *mask, m;
4000 int dst_stride, mask_stride;
4004 __m128i xmm_src, xmm_alpha;
4005 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
4006 __m128i xmm_dst, xmm_dst0, xmm_dst1, xmm_dst2, xmm_dst3;
4008 __m128i mmx_src, mmx_alpha, mmx_mask, mmx_dest;
4010 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
4015 PIXMAN_IMAGE_GET_LINE (
4016 dst_image, dest_x, dest_y, uint16_t, dst_stride, dst_line, 1);
4017 PIXMAN_IMAGE_GET_LINE (
4018 mask_image, mask_x, mask_y, uint32_t, mask_stride, mask_line, 1);
4020 xmm_src = expand_pixel_32_1x128 (src);
4021 xmm_alpha = expand_alpha_1x128 (xmm_src);
4023 mmx_alpha = xmm_alpha;
4030 mask_line += mask_stride;
4031 dst_line += dst_stride;
4033 while (w && ((unsigned long)dst & 15))
4035 m = *(uint32_t *) mask;
4040 mmx_mask = unpack_32_1x128 (m);
4041 mmx_dest = expand565_16_1x128 (d);
4043 *dst = pack_565_32_16 (
4046 &mmx_src, &mmx_alpha, &mmx_mask, &mmx_dest)));
4057 xmm_mask = load_128_unaligned ((__m128i*)mask);
4058 xmm_dst = load_128_aligned ((__m128i*)dst);
4060 pack_cmp = _mm_movemask_epi8 (
4061 _mm_cmpeq_epi32 (xmm_mask, _mm_setzero_si128 ()));
4063 unpack_565_128_4x128 (xmm_dst,
4064 &xmm_dst0, &xmm_dst1, &xmm_dst2, &xmm_dst3);
4065 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
4067 /* preload next round */
4068 xmm_mask = load_128_unaligned ((__m128i*)(mask + 4));
4070 /* preload next round */
4071 if (pack_cmp != 0xffff)
4073 in_over_2x128 (&xmm_src, &xmm_src,
4074 &xmm_alpha, &xmm_alpha,
4075 &xmm_mask_lo, &xmm_mask_hi,
4076 &xmm_dst0, &xmm_dst1);
4080 pack_cmp = _mm_movemask_epi8 (
4081 _mm_cmpeq_epi32 (xmm_mask, _mm_setzero_si128 ()));
4083 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
4085 if (pack_cmp != 0xffff)
4087 in_over_2x128 (&xmm_src, &xmm_src,
4088 &xmm_alpha, &xmm_alpha,
4089 &xmm_mask_lo, &xmm_mask_hi,
4090 &xmm_dst2, &xmm_dst3);
4094 (__m128i*)dst, pack_565_4x128_128 (
4095 &xmm_dst0, &xmm_dst1, &xmm_dst2, &xmm_dst3));
4104 m = *(uint32_t *) mask;
4109 mmx_mask = unpack_32_1x128 (m);
4110 mmx_dest = expand565_16_1x128 (d);
4112 *dst = pack_565_32_16 (
4115 &mmx_src, &mmx_alpha, &mmx_mask, &mmx_dest)));
4127 sse2_composite_in_n_8_8 (pixman_implementation_t *imp,
4129 pixman_image_t * src_image,
4130 pixman_image_t * mask_image,
4131 pixman_image_t * dst_image,
4141 uint8_t *dst_line, *dst;
4142 uint8_t *mask_line, *mask;
4143 int dst_stride, mask_stride;
4150 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
4151 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
4153 PIXMAN_IMAGE_GET_LINE (
4154 dst_image, dest_x, dest_y, uint8_t, dst_stride, dst_line, 1);
4155 PIXMAN_IMAGE_GET_LINE (
4156 mask_image, mask_x, mask_y, uint8_t, mask_stride, mask_line, 1);
4158 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
4162 xmm_alpha = expand_alpha_1x128 (expand_pixel_32_1x128 (src));
4167 dst_line += dst_stride;
4169 mask_line += mask_stride;
4172 while (w && ((unsigned long)dst & 15))
4174 m = (uint32_t) *mask++;
4175 d = (uint32_t) *dst;
4177 *dst++ = (uint8_t) pack_1x128_32 (
4178 pix_multiply_1x128 (
4179 pix_multiply_1x128 (xmm_alpha,
4180 unpack_32_1x128 (m)),
4181 unpack_32_1x128 (d)));
4187 xmm_mask = load_128_unaligned ((__m128i*)mask);
4188 xmm_dst = load_128_aligned ((__m128i*)dst);
4190 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
4191 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
4193 pix_multiply_2x128 (&xmm_alpha, &xmm_alpha,
4194 &xmm_mask_lo, &xmm_mask_hi,
4195 &xmm_mask_lo, &xmm_mask_hi);
4197 pix_multiply_2x128 (&xmm_mask_lo, &xmm_mask_hi,
4198 &xmm_dst_lo, &xmm_dst_hi,
4199 &xmm_dst_lo, &xmm_dst_hi);
4202 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
4211 m = (uint32_t) *mask++;
4212 d = (uint32_t) *dst;
4214 *dst++ = (uint8_t) pack_1x128_32 (
4215 pix_multiply_1x128 (
4216 pix_multiply_1x128 (
4217 xmm_alpha, unpack_32_1x128 (m)),
4218 unpack_32_1x128 (d)));
4226 sse2_composite_in_n_8 (pixman_implementation_t *imp,
4228 pixman_image_t * src_image,
4229 pixman_image_t * mask_image,
4230 pixman_image_t * dst_image,
4240 uint8_t *dst_line, *dst;
4247 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
4249 PIXMAN_IMAGE_GET_LINE (
4250 dst_image, dest_x, dest_y, uint8_t, dst_stride, dst_line, 1);
4252 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
4254 xmm_alpha = expand_alpha_1x128 (expand_pixel_32_1x128 (src));
4263 pixman_fill (dst_image->bits.bits, dst_image->bits.rowstride,
4264 8, dest_x, dest_y, width, height, src);
4272 dst_line += dst_stride;
4275 while (w && ((unsigned long)dst & 15))
4277 d = (uint32_t) *dst;
4279 *dst++ = (uint8_t) pack_1x128_32 (
4280 pix_multiply_1x128 (
4282 unpack_32_1x128 (d)));
4288 xmm_dst = load_128_aligned ((__m128i*)dst);
4290 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
4292 pix_multiply_2x128 (&xmm_alpha, &xmm_alpha,
4293 &xmm_dst_lo, &xmm_dst_hi,
4294 &xmm_dst_lo, &xmm_dst_hi);
4297 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
4305 d = (uint32_t) *dst;
4307 *dst++ = (uint8_t) pack_1x128_32 (
4308 pix_multiply_1x128 (
4310 unpack_32_1x128 (d)));
4318 sse2_composite_in_8_8 (pixman_implementation_t *imp,
4320 pixman_image_t * src_image,
4321 pixman_image_t * mask_image,
4322 pixman_image_t * dst_image,
4332 uint8_t *dst_line, *dst;
4333 uint8_t *src_line, *src;
4334 int src_stride, dst_stride;
4338 __m128i xmm_src, xmm_src_lo, xmm_src_hi;
4339 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
4341 PIXMAN_IMAGE_GET_LINE (
4342 dst_image, dest_x, dest_y, uint8_t, dst_stride, dst_line, 1);
4343 PIXMAN_IMAGE_GET_LINE (
4344 src_image, src_x, src_y, uint8_t, src_stride, src_line, 1);
4349 dst_line += dst_stride;
4351 src_line += src_stride;
4354 while (w && ((unsigned long)dst & 15))
4356 s = (uint32_t) *src++;
4357 d = (uint32_t) *dst;
4359 *dst++ = (uint8_t) pack_1x128_32 (
4360 pix_multiply_1x128 (
4361 unpack_32_1x128 (s), unpack_32_1x128 (d)));
4367 xmm_src = load_128_unaligned ((__m128i*)src);
4368 xmm_dst = load_128_aligned ((__m128i*)dst);
4370 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
4371 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
4373 pix_multiply_2x128 (&xmm_src_lo, &xmm_src_hi,
4374 &xmm_dst_lo, &xmm_dst_hi,
4375 &xmm_dst_lo, &xmm_dst_hi);
4378 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
4387 s = (uint32_t) *src++;
4388 d = (uint32_t) *dst;
4390 *dst++ = (uint8_t) pack_1x128_32 (
4391 pix_multiply_1x128 (unpack_32_1x128 (s), unpack_32_1x128 (d)));
4399 sse2_composite_add_n_8_8 (pixman_implementation_t *imp,
4401 pixman_image_t * src_image,
4402 pixman_image_t * mask_image,
4403 pixman_image_t * dst_image,
4413 uint8_t *dst_line, *dst;
4414 uint8_t *mask_line, *mask;
4415 int dst_stride, mask_stride;
4422 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
4423 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
4425 PIXMAN_IMAGE_GET_LINE (
4426 dst_image, dest_x, dest_y, uint8_t, dst_stride, dst_line, 1);
4427 PIXMAN_IMAGE_GET_LINE (
4428 mask_image, mask_x, mask_y, uint8_t, mask_stride, mask_line, 1);
4430 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
4434 xmm_alpha = expand_alpha_1x128 (expand_pixel_32_1x128 (src));
4439 dst_line += dst_stride;
4441 mask_line += mask_stride;
4444 while (w && ((unsigned long)dst & 15))
4446 m = (uint32_t) *mask++;
4447 d = (uint32_t) *dst;
4449 *dst++ = (uint8_t) pack_1x128_32 (
4451 pix_multiply_1x128 (
4452 xmm_alpha, unpack_32_1x128 (m)),
4453 unpack_32_1x128 (d)));
4459 xmm_mask = load_128_unaligned ((__m128i*)mask);
4460 xmm_dst = load_128_aligned ((__m128i*)dst);
4462 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
4463 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
4465 pix_multiply_2x128 (&xmm_alpha, &xmm_alpha,
4466 &xmm_mask_lo, &xmm_mask_hi,
4467 &xmm_mask_lo, &xmm_mask_hi);
4469 xmm_dst_lo = _mm_adds_epu16 (xmm_mask_lo, xmm_dst_lo);
4470 xmm_dst_hi = _mm_adds_epu16 (xmm_mask_hi, xmm_dst_hi);
4473 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
4482 m = (uint32_t) *mask++;
4483 d = (uint32_t) *dst;
4485 *dst++ = (uint8_t) pack_1x128_32 (
4487 pix_multiply_1x128 (
4488 xmm_alpha, unpack_32_1x128 (m)),
4489 unpack_32_1x128 (d)));
4498 sse2_composite_add_n_8 (pixman_implementation_t *imp,
4500 pixman_image_t * src_image,
4501 pixman_image_t * mask_image,
4502 pixman_image_t * dst_image,
4512 uint8_t *dst_line, *dst;
4519 PIXMAN_IMAGE_GET_LINE (
4520 dst_image, dest_x, dest_y, uint8_t, dst_stride, dst_line, 1);
4522 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
4531 pixman_fill (dst_image->bits.bits, dst_image->bits.rowstride,
4532 8, dest_x, dest_y, width, height, 0xff);
4537 src = (src << 24) | (src << 16) | (src << 8) | src;
4538 xmm_src = _mm_set_epi32 (src, src, src, src);
4543 dst_line += dst_stride;
4546 while (w && ((unsigned long)dst & 15))
4548 *dst = (uint8_t)_mm_cvtsi128_si32 (
4551 _mm_cvtsi32_si128 (*dst)));
4560 (__m128i*)dst, _mm_adds_epu8 (xmm_src, load_128_aligned ((__m128i*)dst)));
4568 *dst = (uint8_t)_mm_cvtsi128_si32 (
4571 _mm_cvtsi32_si128 (*dst)));
4581 sse2_composite_add_8_8 (pixman_implementation_t *imp,
4583 pixman_image_t * src_image,
4584 pixman_image_t * mask_image,
4585 pixman_image_t * dst_image,
4595 uint8_t *dst_line, *dst;
4596 uint8_t *src_line, *src;
4597 int dst_stride, src_stride;
4601 PIXMAN_IMAGE_GET_LINE (
4602 src_image, src_x, src_y, uint8_t, src_stride, src_line, 1);
4603 PIXMAN_IMAGE_GET_LINE (
4604 dst_image, dest_x, dest_y, uint8_t, dst_stride, dst_line, 1);
4611 dst_line += dst_stride;
4612 src_line += src_stride;
4616 while (w && (unsigned long)dst & 3)
4618 t = (*dst) + (*src++);
4619 *dst++ = t | (0 - (t >> 8));
4623 sse2_combine_add_u (imp, op,
4624 (uint32_t*)dst, (uint32_t*)src, NULL, w >> 2);
4634 t = (*dst) + (*src++);
4635 *dst++ = t | (0 - (t >> 8));
4643 sse2_composite_add_8888_8888 (pixman_implementation_t *imp,
4645 pixman_image_t * src_image,
4646 pixman_image_t * mask_image,
4647 pixman_image_t * dst_image,
4657 uint32_t *dst_line, *dst;
4658 uint32_t *src_line, *src;
4659 int dst_stride, src_stride;
4661 PIXMAN_IMAGE_GET_LINE (
4662 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
4663 PIXMAN_IMAGE_GET_LINE (
4664 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
4669 dst_line += dst_stride;
4671 src_line += src_stride;
4673 sse2_combine_add_u (imp, op, dst, src, NULL, width);
4678 static pixman_bool_t
4679 pixman_blt_sse2 (uint32_t *src_bits,
4692 uint8_t * src_bytes;
4693 uint8_t * dst_bytes;
4696 if (src_bpp != dst_bpp)
4701 src_stride = src_stride * (int) sizeof (uint32_t) / 2;
4702 dst_stride = dst_stride * (int) sizeof (uint32_t) / 2;
4703 src_bytes =(uint8_t *)(((uint16_t *)src_bits) + src_stride * (src_y) + (src_x));
4704 dst_bytes = (uint8_t *)(((uint16_t *)dst_bits) + dst_stride * (dst_y) + (dst_x));
4705 byte_width = 2 * width;
4709 else if (src_bpp == 32)
4711 src_stride = src_stride * (int) sizeof (uint32_t) / 4;
4712 dst_stride = dst_stride * (int) sizeof (uint32_t) / 4;
4713 src_bytes = (uint8_t *)(((uint32_t *)src_bits) + src_stride * (src_y) + (src_x));
4714 dst_bytes = (uint8_t *)(((uint32_t *)dst_bits) + dst_stride * (dst_y) + (dst_x));
4715 byte_width = 4 * width;
4727 uint8_t *s = src_bytes;
4728 uint8_t *d = dst_bytes;
4729 src_bytes += src_stride;
4730 dst_bytes += dst_stride;
4733 while (w >= 2 && ((unsigned long)d & 3))
4735 *(uint16_t *)d = *(uint16_t *)s;
4741 while (w >= 4 && ((unsigned long)d & 15))
4743 *(uint32_t *)d = *(uint32_t *)s;
4752 __m128i xmm0, xmm1, xmm2, xmm3;
4754 xmm0 = load_128_unaligned ((__m128i*)(s));
4755 xmm1 = load_128_unaligned ((__m128i*)(s + 16));
4756 xmm2 = load_128_unaligned ((__m128i*)(s + 32));
4757 xmm3 = load_128_unaligned ((__m128i*)(s + 48));
4759 save_128_aligned ((__m128i*)(d), xmm0);
4760 save_128_aligned ((__m128i*)(d + 16), xmm1);
4761 save_128_aligned ((__m128i*)(d + 32), xmm2);
4762 save_128_aligned ((__m128i*)(d + 48), xmm3);
4771 save_128_aligned ((__m128i*)d, load_128_unaligned ((__m128i*)s) );
4780 *(uint32_t *)d = *(uint32_t *)s;
4789 *(uint16_t *)d = *(uint16_t *)s;
4801 sse2_composite_copy_area (pixman_implementation_t *imp,
4803 pixman_image_t * src_image,
4804 pixman_image_t * mask_image,
4805 pixman_image_t * dst_image,
4815 pixman_blt_sse2 (src_image->bits.bits,
4816 dst_image->bits.bits,
4817 src_image->bits.rowstride,
4818 dst_image->bits.rowstride,
4819 PIXMAN_FORMAT_BPP (src_image->bits.format),
4820 PIXMAN_FORMAT_BPP (dst_image->bits.format),
4821 src_x, src_y, dest_x, dest_y, width, height);
4825 sse2_composite_over_x888_8_8888 (pixman_implementation_t *imp,
4827 pixman_image_t * src_image,
4828 pixman_image_t * mask_image,
4829 pixman_image_t * dst_image,
4839 uint32_t *src, *src_line, s;
4840 uint32_t *dst, *dst_line, d;
4841 uint8_t *mask, *mask_line;
4843 int src_stride, mask_stride, dst_stride;
4847 __m128i xmm_src, xmm_src_lo, xmm_src_hi;
4848 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
4849 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
4851 PIXMAN_IMAGE_GET_LINE (
4852 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
4853 PIXMAN_IMAGE_GET_LINE (
4854 mask_image, mask_x, mask_y, uint8_t, mask_stride, mask_line, 1);
4855 PIXMAN_IMAGE_GET_LINE (
4856 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
4861 src_line += src_stride;
4863 dst_line += dst_stride;
4865 mask_line += mask_stride;
4869 while (w && (unsigned long)dst & 15)
4871 s = 0xff000000 | *src++;
4872 m = (uint32_t) *mask++;
4874 ms = unpack_32_1x128 (s);
4878 __m128i ma = expand_alpha_rev_1x128 (unpack_32_1x128 (m));
4879 __m128i md = unpack_32_1x128 (d);
4881 ms = in_over_1x128 (&ms, &mask_00ff, &ma, &md);
4884 *dst++ = pack_1x128_32 (ms);
4890 m = *(uint32_t*) mask;
4891 xmm_src = _mm_or_si128 (
4892 load_128_unaligned ((__m128i*)src), mask_ff000000);
4894 if (m == 0xffffffff)
4896 save_128_aligned ((__m128i*)dst, xmm_src);
4900 xmm_dst = load_128_aligned ((__m128i*)dst);
4902 xmm_mask = _mm_unpacklo_epi16 (unpack_32_1x128 (m), _mm_setzero_si128());
4904 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
4905 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
4906 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
4908 expand_alpha_rev_2x128 (
4909 xmm_mask_lo, xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
4911 in_over_2x128 (&xmm_src_lo, &xmm_src_hi,
4912 &mask_00ff, &mask_00ff, &xmm_mask_lo, &xmm_mask_hi,
4913 &xmm_dst_lo, &xmm_dst_hi);
4915 save_128_aligned ((__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
4926 m = (uint32_t) *mask++;
4930 s = 0xff000000 | *src;
4942 ma = expand_alpha_rev_1x128 (unpack_32_1x128 (m));
4943 md = unpack_32_1x128 (d);
4944 ms = unpack_32_1x128 (s);
4946 *dst = pack_1x128_32 (in_over_1x128 (&ms, &mask_00ff, &ma, &md));
4960 sse2_composite_over_8888_8_8888 (pixman_implementation_t *imp,
4962 pixman_image_t * src_image,
4963 pixman_image_t * mask_image,
4964 pixman_image_t * dst_image,
4974 uint32_t *src, *src_line, s;
4975 uint32_t *dst, *dst_line, d;
4976 uint8_t *mask, *mask_line;
4978 int src_stride, mask_stride, dst_stride;
4981 __m128i xmm_src, xmm_src_lo, xmm_src_hi, xmm_srca_lo, xmm_srca_hi;
4982 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
4983 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
4985 PIXMAN_IMAGE_GET_LINE (
4986 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
4987 PIXMAN_IMAGE_GET_LINE (
4988 mask_image, mask_x, mask_y, uint8_t, mask_stride, mask_line, 1);
4989 PIXMAN_IMAGE_GET_LINE (
4990 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
4995 src_line += src_stride;
4997 dst_line += dst_stride;
4999 mask_line += mask_stride;
5003 while (w && (unsigned long)dst & 15)
5008 m = (uint32_t) *mask++;
5015 if (sa == 0xff && m == 0xff)
5021 __m128i ms, md, ma, msa;
5023 ma = expand_alpha_rev_1x128 (load_32_1x128 (m));
5024 ms = unpack_32_1x128 (s);
5025 md = unpack_32_1x128 (d);
5027 msa = expand_alpha_rev_1x128 (load_32_1x128 (sa));
5029 *dst = pack_1x128_32 (in_over_1x128 (&ms, &msa, &ma, &md));
5039 m = *(uint32_t *) mask;
5043 xmm_src = load_128_unaligned ((__m128i*)src);
5045 if (m == 0xffffffff && is_opaque (xmm_src))
5047 save_128_aligned ((__m128i *)dst, xmm_src);
5051 xmm_dst = load_128_aligned ((__m128i *)dst);
5053 xmm_mask = _mm_unpacklo_epi16 (unpack_32_1x128 (m), _mm_setzero_si128());
5055 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
5056 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
5057 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
5059 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi, &xmm_srca_lo, &xmm_srca_hi);
5060 expand_alpha_rev_2x128 (xmm_mask_lo, xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
5062 in_over_2x128 (&xmm_src_lo, &xmm_src_hi, &xmm_srca_lo, &xmm_srca_hi,
5063 &xmm_mask_lo, &xmm_mask_hi, &xmm_dst_lo, &xmm_dst_hi);
5065 save_128_aligned ((__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
5080 m = (uint32_t) *mask++;
5087 if (sa == 0xff && m == 0xff)
5093 __m128i ms, md, ma, msa;
5095 ma = expand_alpha_rev_1x128 (load_32_1x128 (m));
5096 ms = unpack_32_1x128 (s);
5097 md = unpack_32_1x128 (d);
5099 msa = expand_alpha_rev_1x128 (load_32_1x128 (sa));
5101 *dst = pack_1x128_32 (in_over_1x128 (&ms, &msa, &ma, &md));
5113 sse2_composite_over_reverse_n_8888 (pixman_implementation_t *imp,
5115 pixman_image_t * src_image,
5116 pixman_image_t * mask_image,
5117 pixman_image_t * dst_image,
5128 uint32_t *dst_line, *dst;
5130 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
5131 __m128i xmm_dsta_hi, xmm_dsta_lo;
5135 src = _pixman_image_get_solid (imp, src_image, dst_image->bits.format);
5140 PIXMAN_IMAGE_GET_LINE (
5141 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
5143 xmm_src = expand_pixel_32_1x128 (src);
5149 dst_line += dst_stride;
5152 while (w && (unsigned long)dst & 15)
5156 vd = unpack_32_1x128 (*dst);
5158 *dst = pack_1x128_32 (over_1x128 (vd, expand_alpha_1x128 (vd),
5166 __m128i tmp_lo, tmp_hi;
5168 xmm_dst = load_128_aligned ((__m128i*)dst);
5170 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
5171 expand_alpha_2x128 (xmm_dst_lo, xmm_dst_hi, &xmm_dsta_lo, &xmm_dsta_hi);
5176 over_2x128 (&xmm_dst_lo, &xmm_dst_hi,
5177 &xmm_dsta_lo, &xmm_dsta_hi,
5181 (__m128i*)dst, pack_2x128_128 (tmp_lo, tmp_hi));
5191 vd = unpack_32_1x128 (*dst);
5193 *dst = pack_1x128_32 (over_1x128 (vd, expand_alpha_1x128 (vd),
5204 sse2_composite_over_8888_8888_8888 (pixman_implementation_t *imp,
5206 pixman_image_t * src_image,
5207 pixman_image_t * mask_image,
5208 pixman_image_t * dst_image,
5218 uint32_t *src, *src_line, s;
5219 uint32_t *dst, *dst_line, d;
5220 uint32_t *mask, *mask_line;
5222 int src_stride, mask_stride, dst_stride;
5225 __m128i xmm_src, xmm_src_lo, xmm_src_hi, xmm_srca_lo, xmm_srca_hi;
5226 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
5227 __m128i xmm_mask, xmm_mask_lo, xmm_mask_hi;
5229 PIXMAN_IMAGE_GET_LINE (
5230 dst_image, dest_x, dest_y, uint32_t, dst_stride, dst_line, 1);
5231 PIXMAN_IMAGE_GET_LINE (
5232 mask_image, mask_x, mask_y, uint32_t, mask_stride, mask_line, 1);
5233 PIXMAN_IMAGE_GET_LINE (
5234 src_image, src_x, src_y, uint32_t, src_stride, src_line, 1);
5239 src_line += src_stride;
5241 dst_line += dst_stride;
5243 mask_line += mask_stride;
5247 while (w && (unsigned long)dst & 15)
5252 m = (*mask++) >> 24;
5259 if (sa == 0xff && m == 0xff)
5265 __m128i ms, md, ma, msa;
5267 ma = expand_alpha_rev_1x128 (load_32_1x128 (m));
5268 ms = unpack_32_1x128 (s);
5269 md = unpack_32_1x128 (d);
5271 msa = expand_alpha_rev_1x128 (load_32_1x128 (sa));
5273 *dst = pack_1x128_32 (in_over_1x128 (&ms, &msa, &ma, &md));
5283 xmm_mask = load_128_unaligned ((__m128i*)mask);
5285 if (!is_transparent (xmm_mask))
5287 xmm_src = load_128_unaligned ((__m128i*)src);
5289 if (is_opaque (xmm_mask) && is_opaque (xmm_src))
5291 save_128_aligned ((__m128i *)dst, xmm_src);
5295 xmm_dst = load_128_aligned ((__m128i *)dst);
5297 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
5298 unpack_128_2x128 (xmm_mask, &xmm_mask_lo, &xmm_mask_hi);
5299 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
5301 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi, &xmm_srca_lo, &xmm_srca_hi);
5302 expand_alpha_2x128 (xmm_mask_lo, xmm_mask_hi, &xmm_mask_lo, &xmm_mask_hi);
5304 in_over_2x128 (&xmm_src_lo, &xmm_src_hi, &xmm_srca_lo, &xmm_srca_hi,
5305 &xmm_mask_lo, &xmm_mask_hi, &xmm_dst_lo, &xmm_dst_hi);
5307 save_128_aligned ((__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
5322 m = (*mask++) >> 24;
5329 if (sa == 0xff && m == 0xff)
5335 __m128i ms, md, ma, msa;
5337 ma = expand_alpha_rev_1x128 (load_32_1x128 (m));
5338 ms = unpack_32_1x128 (s);
5339 md = unpack_32_1x128 (d);
5341 msa = expand_alpha_rev_1x128 (load_32_1x128 (sa));
5343 *dst = pack_1x128_32 (in_over_1x128 (&ms, &msa, &ma, &md));
5354 /* A variant of 'sse2_combine_over_u' with minor tweaks */
5355 static force_inline void
5356 scaled_nearest_scanline_sse2_8888_8888_OVER (uint32_t* pd,
5360 pixman_fixed_t unit_x,
5361 pixman_fixed_t max_vx,
5362 pixman_bool_t fully_transparent_src)
5365 const uint32_t* pm = NULL;
5367 __m128i xmm_dst_lo, xmm_dst_hi;
5368 __m128i xmm_src_lo, xmm_src_hi;
5369 __m128i xmm_alpha_lo, xmm_alpha_hi;
5371 if (fully_transparent_src)
5374 /* Align dst on a 16-byte boundary */
5375 while (w && ((unsigned long)pd & 15))
5378 s = combine1 (ps + (vx >> 16), pm);
5381 *pd++ = core_combine_over_u_pixel_sse2 (s, d);
5390 uint32_t tmp1, tmp2, tmp3, tmp4;
5392 tmp1 = ps[vx >> 16];
5394 tmp2 = ps[vx >> 16];
5396 tmp3 = ps[vx >> 16];
5398 tmp4 = ps[vx >> 16];
5401 tmp = _mm_set_epi32 (tmp4, tmp3, tmp2, tmp1);
5403 xmm_src_hi = combine4 ((__m128i*)&tmp, (__m128i*)pm);
5405 if (is_opaque (xmm_src_hi))
5407 save_128_aligned ((__m128i*)pd, xmm_src_hi);
5409 else if (!is_zero (xmm_src_hi))
5411 xmm_dst_hi = load_128_aligned ((__m128i*) pd);
5413 unpack_128_2x128 (xmm_src_hi, &xmm_src_lo, &xmm_src_hi);
5414 unpack_128_2x128 (xmm_dst_hi, &xmm_dst_lo, &xmm_dst_hi);
5416 expand_alpha_2x128 (
5417 xmm_src_lo, xmm_src_hi, &xmm_alpha_lo, &xmm_alpha_hi);
5419 over_2x128 (&xmm_src_lo, &xmm_src_hi,
5420 &xmm_alpha_lo, &xmm_alpha_hi,
5421 &xmm_dst_lo, &xmm_dst_hi);
5423 /* rebuid the 4 pixel data and save*/
5424 save_128_aligned ((__m128i*)pd,
5425 pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
5437 s = combine1 (ps + (vx >> 16), pm);
5440 *pd++ = core_combine_over_u_pixel_sse2 (s, d);
5448 FAST_NEAREST_MAINLOOP (sse2_8888_8888_cover_OVER,
5449 scaled_nearest_scanline_sse2_8888_8888_OVER,
5450 uint32_t, uint32_t, COVER)
5451 FAST_NEAREST_MAINLOOP (sse2_8888_8888_none_OVER,
5452 scaled_nearest_scanline_sse2_8888_8888_OVER,
5453 uint32_t, uint32_t, NONE)
5454 FAST_NEAREST_MAINLOOP (sse2_8888_8888_pad_OVER,
5455 scaled_nearest_scanline_sse2_8888_8888_OVER,
5456 uint32_t, uint32_t, PAD)
5458 static force_inline void
5459 scaled_nearest_scanline_sse2_8888_n_8888_OVER (const uint32_t * mask,
5461 const uint32_t * src,
5464 pixman_fixed_t unit_x,
5465 pixman_fixed_t max_vx,
5466 pixman_bool_t zero_src)
5469 __m128i xmm_src, xmm_src_lo, xmm_src_hi;
5470 __m128i xmm_dst, xmm_dst_lo, xmm_dst_hi;
5471 __m128i xmm_alpha_lo, xmm_alpha_hi;
5473 if (zero_src || (*mask >> 24) == 0)
5476 xmm_mask = create_mask_16_128 (*mask >> 24);
5478 while (w && (unsigned long)dst & 15)
5480 uint32_t s = src[pixman_fixed_to_int (vx)];
5487 __m128i ms = unpack_32_1x128 (s);
5488 __m128i alpha = expand_alpha_1x128 (ms);
5489 __m128i dest = xmm_mask;
5490 __m128i alpha_dst = unpack_32_1x128 (d);
5492 *dst = pack_1x128_32 (
5493 in_over_1x128 (&ms, &alpha, &dest, &alpha_dst));
5501 uint32_t tmp1, tmp2, tmp3, tmp4;
5503 tmp1 = src[pixman_fixed_to_int (vx)];
5505 tmp2 = src[pixman_fixed_to_int (vx)];
5507 tmp3 = src[pixman_fixed_to_int (vx)];
5509 tmp4 = src[pixman_fixed_to_int (vx)];
5512 xmm_src = _mm_set_epi32 (tmp4, tmp3, tmp2, tmp1);
5514 if (!is_zero (xmm_src))
5516 xmm_dst = load_128_aligned ((__m128i*)dst);
5518 unpack_128_2x128 (xmm_src, &xmm_src_lo, &xmm_src_hi);
5519 unpack_128_2x128 (xmm_dst, &xmm_dst_lo, &xmm_dst_hi);
5520 expand_alpha_2x128 (xmm_src_lo, xmm_src_hi,
5521 &xmm_alpha_lo, &xmm_alpha_hi);
5523 in_over_2x128 (&xmm_src_lo, &xmm_src_hi,
5524 &xmm_alpha_lo, &xmm_alpha_hi,
5525 &xmm_mask, &xmm_mask,
5526 &xmm_dst_lo, &xmm_dst_hi);
5529 (__m128i*)dst, pack_2x128_128 (xmm_dst_lo, xmm_dst_hi));
5538 uint32_t s = src[pixman_fixed_to_int (vx)];
5545 __m128i ms = unpack_32_1x128 (s);
5546 __m128i alpha = expand_alpha_1x128 (ms);
5547 __m128i mask = xmm_mask;
5548 __m128i dest = unpack_32_1x128 (d);
5550 *dst = pack_1x128_32 (
5551 in_over_1x128 (&ms, &alpha, &mask, &dest));
5560 FAST_NEAREST_MAINLOOP_COMMON (sse2_8888_n_8888_cover_OVER,
5561 scaled_nearest_scanline_sse2_8888_n_8888_OVER,
5562 uint32_t, uint32_t, uint32_t, COVER, TRUE, TRUE)
5563 FAST_NEAREST_MAINLOOP_COMMON (sse2_8888_n_8888_pad_OVER,
5564 scaled_nearest_scanline_sse2_8888_n_8888_OVER,
5565 uint32_t, uint32_t, uint32_t, PAD, TRUE, TRUE)
5566 FAST_NEAREST_MAINLOOP_COMMON (sse2_8888_n_8888_none_OVER,
5567 scaled_nearest_scanline_sse2_8888_n_8888_OVER,
5568 uint32_t, uint32_t, uint32_t, NONE, TRUE, TRUE)
5571 bilinear_interpolate_line_sse2 (uint32_t * out,
5572 const uint32_t * top,
5573 const uint32_t * bottom,
5580 const __m128i xmm_wt = _mm_set_epi16 (wt, wt, wt, wt, wt, wt, wt, wt);
5581 const __m128i xmm_wb = _mm_set_epi16 (wb, wb, wb, wb, wb, wb, wb, wb);
5582 const __m128i xmm_xorc = _mm_set_epi16 (0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff);
5583 const __m128i xmm_addc = _mm_set_epi16 (0, 0, 0, 0, 1, 1, 1, 1);
5584 const __m128i xmm_ux = _mm_set_epi16 (ux, ux, ux, ux, ux, ux, ux, ux);
5585 const __m128i xmm_zero = _mm_setzero_si128 ();
5586 __m128i xmm_x = _mm_set_epi16 (x, x, x, x, x, x, x, x);
5587 uint32_t pix1, pix2, pix3, pix4;
5589 #define INTERPOLATE_ONE_PIXEL(pix) \
5591 __m128i xmm_wh, xmm_lo, xmm_hi, a; \
5592 /* fetch 2x2 pixel block into sse2 register */ \
5593 uint32_t tl = top [pixman_fixed_to_int (x)]; \
5594 uint32_t tr = top [pixman_fixed_to_int (x) + 1]; \
5595 uint32_t bl = bottom [pixman_fixed_to_int (x)]; \
5596 uint32_t br = bottom [pixman_fixed_to_int (x) + 1]; \
5597 a = _mm_set_epi32 (tr, tl, br, bl); \
5599 /* vertical interpolation */ \
5600 a = _mm_add_epi16 (_mm_mullo_epi16 (_mm_unpackhi_epi8 (a, xmm_zero), \
5602 _mm_mullo_epi16 (_mm_unpacklo_epi8 (a, xmm_zero), \
5604 /* calculate horizontal weights */ \
5605 xmm_wh = _mm_add_epi16 (xmm_addc, \
5606 _mm_xor_si128 (xmm_xorc, \
5607 _mm_srli_epi16 (xmm_x, 8))); \
5608 xmm_x = _mm_add_epi16 (xmm_x, xmm_ux); \
5609 /* horizontal interpolation */ \
5610 xmm_lo = _mm_mullo_epi16 (a, xmm_wh); \
5611 xmm_hi = _mm_mulhi_epu16 (a, xmm_wh); \
5612 a = _mm_add_epi32 (_mm_unpacklo_epi16 (xmm_lo, xmm_hi), \
5613 _mm_unpackhi_epi16 (xmm_lo, xmm_hi)); \
5614 /* shift and pack the result */ \
5615 a = _mm_srli_epi32 (a, 16); \
5616 a = _mm_packs_epi32 (a, a); \
5617 a = _mm_packus_epi16 (a, a); \
5618 pix = _mm_cvtsi128_si32 (a); \
5621 while ((width -= 4) >= 0)
5623 INTERPOLATE_ONE_PIXEL (pix1);
5624 INTERPOLATE_ONE_PIXEL (pix2);
5625 INTERPOLATE_ONE_PIXEL (pix3);
5626 INTERPOLATE_ONE_PIXEL (pix4);
5634 INTERPOLATE_ONE_PIXEL (pix1);
5635 INTERPOLATE_ONE_PIXEL (pix2);
5641 INTERPOLATE_ONE_PIXEL (pix1);
5645 #undef INTERPOLATE_ONE_PIXEL
5648 static force_inline void
5649 scaled_bilinear_scanline_sse2_8888_8888_SRC (uint32_t * dst,
5650 const uint32_t * mask,
5651 const uint32_t * src_top,
5652 const uint32_t * src_bottom,
5657 pixman_fixed_t unit_x,
5658 pixman_fixed_t max_vx,
5659 pixman_bool_t zero_src)
5661 bilinear_interpolate_line_sse2 (dst, src_top, src_bottom,
5662 wt, wb, vx, unit_x, w);
5665 FAST_BILINEAR_MAINLOOP_COMMON (sse2_8888_8888_cover_SRC,
5666 scaled_bilinear_scanline_sse2_8888_8888_SRC,
5667 uint32_t, uint32_t, uint32_t,
5668 COVER, FALSE, FALSE)
5669 FAST_BILINEAR_MAINLOOP_COMMON (sse2_8888_8888_pad_SRC,
5670 scaled_bilinear_scanline_sse2_8888_8888_SRC,
5671 uint32_t, uint32_t, uint32_t,
5673 FAST_BILINEAR_MAINLOOP_COMMON (sse2_8888_8888_none_SRC,
5674 scaled_bilinear_scanline_sse2_8888_8888_SRC,
5675 uint32_t, uint32_t, uint32_t,
5678 static const pixman_fast_path_t sse2_fast_paths[] =
5680 /* PIXMAN_OP_OVER */
5681 PIXMAN_STD_FAST_PATH (OVER, solid, a8, r5g6b5, sse2_composite_over_n_8_0565),
5682 PIXMAN_STD_FAST_PATH (OVER, solid, a8, b5g6r5, sse2_composite_over_n_8_0565),
5683 PIXMAN_STD_FAST_PATH (OVER, solid, null, a8r8g8b8, sse2_composite_over_n_8888),
5684 PIXMAN_STD_FAST_PATH (OVER, solid, null, x8r8g8b8, sse2_composite_over_n_8888),
5685 PIXMAN_STD_FAST_PATH (OVER, solid, null, r5g6b5, sse2_composite_over_n_0565),
5686 PIXMAN_STD_FAST_PATH (OVER, a8r8g8b8, null, a8r8g8b8, sse2_composite_over_8888_8888),
5687 PIXMAN_STD_FAST_PATH (OVER, a8r8g8b8, null, x8r8g8b8, sse2_composite_over_8888_8888),
5688 PIXMAN_STD_FAST_PATH (OVER, a8b8g8r8, null, a8b8g8r8, sse2_composite_over_8888_8888),
5689 PIXMAN_STD_FAST_PATH (OVER, a8b8g8r8, null, x8b8g8r8, sse2_composite_over_8888_8888),
5690 PIXMAN_STD_FAST_PATH (OVER, a8r8g8b8, null, r5g6b5, sse2_composite_over_8888_0565),
5691 PIXMAN_STD_FAST_PATH (OVER, a8b8g8r8, null, b5g6r5, sse2_composite_over_8888_0565),
5692 PIXMAN_STD_FAST_PATH (OVER, solid, a8, a8r8g8b8, sse2_composite_over_n_8_8888),
5693 PIXMAN_STD_FAST_PATH (OVER, solid, a8, x8r8g8b8, sse2_composite_over_n_8_8888),
5694 PIXMAN_STD_FAST_PATH (OVER, solid, a8, a8b8g8r8, sse2_composite_over_n_8_8888),
5695 PIXMAN_STD_FAST_PATH (OVER, solid, a8, x8b8g8r8, sse2_composite_over_n_8_8888),
5696 PIXMAN_STD_FAST_PATH (OVER, a8r8g8b8, a8r8g8b8, a8r8g8b8, sse2_composite_over_8888_8888_8888),
5697 PIXMAN_STD_FAST_PATH (OVER, a8r8g8b8, a8, x8r8g8b8, sse2_composite_over_8888_8_8888),
5698 PIXMAN_STD_FAST_PATH (OVER, a8r8g8b8, a8, a8r8g8b8, sse2_composite_over_8888_8_8888),
5699 PIXMAN_STD_FAST_PATH (OVER, a8b8g8r8, a8, x8b8g8r8, sse2_composite_over_8888_8_8888),
5700 PIXMAN_STD_FAST_PATH (OVER, a8b8g8r8, a8, a8b8g8r8, sse2_composite_over_8888_8_8888),
5701 PIXMAN_STD_FAST_PATH (OVER, x8r8g8b8, a8, x8r8g8b8, sse2_composite_over_x888_8_8888),
5702 PIXMAN_STD_FAST_PATH (OVER, x8r8g8b8, a8, a8r8g8b8, sse2_composite_over_x888_8_8888),
5703 PIXMAN_STD_FAST_PATH (OVER, x8b8g8r8, a8, x8b8g8r8, sse2_composite_over_x888_8_8888),
5704 PIXMAN_STD_FAST_PATH (OVER, x8b8g8r8, a8, a8b8g8r8, sse2_composite_over_x888_8_8888),
5705 PIXMAN_STD_FAST_PATH (OVER, x8r8g8b8, solid, a8r8g8b8, sse2_composite_over_x888_n_8888),
5706 PIXMAN_STD_FAST_PATH (OVER, x8r8g8b8, solid, x8r8g8b8, sse2_composite_over_x888_n_8888),
5707 PIXMAN_STD_FAST_PATH (OVER, x8b8g8r8, solid, a8b8g8r8, sse2_composite_over_x888_n_8888),
5708 PIXMAN_STD_FAST_PATH (OVER, x8b8g8r8, solid, x8b8g8r8, sse2_composite_over_x888_n_8888),
5709 PIXMAN_STD_FAST_PATH (OVER, a8r8g8b8, solid, a8r8g8b8, sse2_composite_over_8888_n_8888),
5710 PIXMAN_STD_FAST_PATH (OVER, a8r8g8b8, solid, x8r8g8b8, sse2_composite_over_8888_n_8888),
5711 PIXMAN_STD_FAST_PATH (OVER, a8b8g8r8, solid, a8b8g8r8, sse2_composite_over_8888_n_8888),
5712 PIXMAN_STD_FAST_PATH (OVER, a8b8g8r8, solid, x8b8g8r8, sse2_composite_over_8888_n_8888),
5713 PIXMAN_STD_FAST_PATH_CA (OVER, solid, a8r8g8b8, a8r8g8b8, sse2_composite_over_n_8888_8888_ca),
5714 PIXMAN_STD_FAST_PATH_CA (OVER, solid, a8r8g8b8, x8r8g8b8, sse2_composite_over_n_8888_8888_ca),
5715 PIXMAN_STD_FAST_PATH_CA (OVER, solid, a8b8g8r8, a8b8g8r8, sse2_composite_over_n_8888_8888_ca),
5716 PIXMAN_STD_FAST_PATH_CA (OVER, solid, a8b8g8r8, x8b8g8r8, sse2_composite_over_n_8888_8888_ca),
5717 PIXMAN_STD_FAST_PATH_CA (OVER, solid, a8r8g8b8, r5g6b5, sse2_composite_over_n_8888_0565_ca),
5718 PIXMAN_STD_FAST_PATH_CA (OVER, solid, a8b8g8r8, b5g6r5, sse2_composite_over_n_8888_0565_ca),
5719 PIXMAN_STD_FAST_PATH (OVER, pixbuf, pixbuf, a8r8g8b8, sse2_composite_over_pixbuf_8888),
5720 PIXMAN_STD_FAST_PATH (OVER, pixbuf, pixbuf, x8r8g8b8, sse2_composite_over_pixbuf_8888),
5721 PIXMAN_STD_FAST_PATH (OVER, rpixbuf, rpixbuf, a8b8g8r8, sse2_composite_over_pixbuf_8888),
5722 PIXMAN_STD_FAST_PATH (OVER, rpixbuf, rpixbuf, x8b8g8r8, sse2_composite_over_pixbuf_8888),
5723 PIXMAN_STD_FAST_PATH (OVER, pixbuf, pixbuf, r5g6b5, sse2_composite_over_pixbuf_0565),
5724 PIXMAN_STD_FAST_PATH (OVER, rpixbuf, rpixbuf, b5g6r5, sse2_composite_over_pixbuf_0565),
5725 PIXMAN_STD_FAST_PATH (OVER, x8r8g8b8, null, x8r8g8b8, sse2_composite_copy_area),
5726 PIXMAN_STD_FAST_PATH (OVER, x8b8g8r8, null, x8b8g8r8, sse2_composite_copy_area),
5728 /* PIXMAN_OP_OVER_REVERSE */
5729 PIXMAN_STD_FAST_PATH (OVER_REVERSE, solid, null, a8r8g8b8, sse2_composite_over_reverse_n_8888),
5730 PIXMAN_STD_FAST_PATH (OVER_REVERSE, solid, null, a8b8g8r8, sse2_composite_over_reverse_n_8888),
5733 PIXMAN_STD_FAST_PATH_CA (ADD, solid, a8r8g8b8, a8r8g8b8, sse2_composite_add_n_8888_8888_ca),
5734 PIXMAN_STD_FAST_PATH (ADD, a8, null, a8, sse2_composite_add_8_8),
5735 PIXMAN_STD_FAST_PATH (ADD, a8r8g8b8, null, a8r8g8b8, sse2_composite_add_8888_8888),
5736 PIXMAN_STD_FAST_PATH (ADD, a8b8g8r8, null, a8b8g8r8, sse2_composite_add_8888_8888),
5737 PIXMAN_STD_FAST_PATH (ADD, solid, a8, a8, sse2_composite_add_n_8_8),
5738 PIXMAN_STD_FAST_PATH (ADD, solid, null, a8, sse2_composite_add_n_8),
5741 PIXMAN_STD_FAST_PATH (SRC, solid, a8, a8r8g8b8, sse2_composite_src_n_8_8888),
5742 PIXMAN_STD_FAST_PATH (SRC, solid, a8, x8r8g8b8, sse2_composite_src_n_8_8888),
5743 PIXMAN_STD_FAST_PATH (SRC, solid, a8, a8b8g8r8, sse2_composite_src_n_8_8888),
5744 PIXMAN_STD_FAST_PATH (SRC, solid, a8, x8b8g8r8, sse2_composite_src_n_8_8888),
5745 PIXMAN_STD_FAST_PATH (SRC, x8r8g8b8, null, a8r8g8b8, sse2_composite_src_x888_8888),
5746 PIXMAN_STD_FAST_PATH (SRC, x8b8g8r8, null, a8b8g8r8, sse2_composite_src_x888_8888),
5747 PIXMAN_STD_FAST_PATH (SRC, a8r8g8b8, null, a8r8g8b8, sse2_composite_copy_area),
5748 PIXMAN_STD_FAST_PATH (SRC, a8b8g8r8, null, a8b8g8r8, sse2_composite_copy_area),
5749 PIXMAN_STD_FAST_PATH (SRC, a8r8g8b8, null, x8r8g8b8, sse2_composite_copy_area),
5750 PIXMAN_STD_FAST_PATH (SRC, a8b8g8r8, null, x8b8g8r8, sse2_composite_copy_area),
5751 PIXMAN_STD_FAST_PATH (SRC, x8r8g8b8, null, x8r8g8b8, sse2_composite_copy_area),
5752 PIXMAN_STD_FAST_PATH (SRC, x8b8g8r8, null, x8b8g8r8, sse2_composite_copy_area),
5753 PIXMAN_STD_FAST_PATH (SRC, r5g6b5, null, r5g6b5, sse2_composite_copy_area),
5754 PIXMAN_STD_FAST_PATH (SRC, b5g6r5, null, b5g6r5, sse2_composite_copy_area),
5757 PIXMAN_STD_FAST_PATH (IN, a8, null, a8, sse2_composite_in_8_8),
5758 PIXMAN_STD_FAST_PATH (IN, solid, a8, a8, sse2_composite_in_n_8_8),
5759 PIXMAN_STD_FAST_PATH (IN, solid, null, a8, sse2_composite_in_n_8),
5761 SIMPLE_NEAREST_FAST_PATH_COVER (OVER, a8r8g8b8, x8r8g8b8, sse2_8888_8888),
5762 SIMPLE_NEAREST_FAST_PATH_COVER (OVER, a8b8g8r8, x8b8g8r8, sse2_8888_8888),
5763 SIMPLE_NEAREST_FAST_PATH_COVER (OVER, a8r8g8b8, a8r8g8b8, sse2_8888_8888),
5764 SIMPLE_NEAREST_FAST_PATH_COVER (OVER, a8b8g8r8, a8b8g8r8, sse2_8888_8888),
5765 SIMPLE_NEAREST_FAST_PATH_NONE (OVER, a8r8g8b8, x8r8g8b8, sse2_8888_8888),
5766 SIMPLE_NEAREST_FAST_PATH_NONE (OVER, a8b8g8r8, x8b8g8r8, sse2_8888_8888),
5767 SIMPLE_NEAREST_FAST_PATH_NONE (OVER, a8r8g8b8, a8r8g8b8, sse2_8888_8888),
5768 SIMPLE_NEAREST_FAST_PATH_NONE (OVER, a8b8g8r8, a8b8g8r8, sse2_8888_8888),
5769 SIMPLE_NEAREST_FAST_PATH_PAD (OVER, a8r8g8b8, x8r8g8b8, sse2_8888_8888),
5770 SIMPLE_NEAREST_FAST_PATH_PAD (OVER, a8b8g8r8, x8b8g8r8, sse2_8888_8888),
5771 SIMPLE_NEAREST_FAST_PATH_PAD (OVER, a8r8g8b8, a8r8g8b8, sse2_8888_8888),
5772 SIMPLE_NEAREST_FAST_PATH_PAD (OVER, a8b8g8r8, a8b8g8r8, sse2_8888_8888),
5774 SIMPLE_NEAREST_SOLID_MASK_FAST_PATH (OVER, a8r8g8b8, a8r8g8b8, sse2_8888_n_8888),
5775 SIMPLE_NEAREST_SOLID_MASK_FAST_PATH (OVER, a8b8g8r8, a8b8g8r8, sse2_8888_n_8888),
5776 SIMPLE_NEAREST_SOLID_MASK_FAST_PATH (OVER, a8r8g8b8, x8r8g8b8, sse2_8888_n_8888),
5777 SIMPLE_NEAREST_SOLID_MASK_FAST_PATH (OVER, a8b8g8r8, x8b8g8r8, sse2_8888_n_8888),
5779 SIMPLE_BILINEAR_FAST_PATH (SRC, a8r8g8b8, a8r8g8b8, sse2_8888_8888),
5780 SIMPLE_BILINEAR_FAST_PATH (SRC, a8r8g8b8, x8r8g8b8, sse2_8888_8888),
5781 SIMPLE_BILINEAR_FAST_PATH (SRC, x8r8g8b8, x8r8g8b8, sse2_8888_8888),
5786 static pixman_bool_t
5787 sse2_blt (pixman_implementation_t *imp,
5788 uint32_t * src_bits,
5789 uint32_t * dst_bits,
5801 if (!pixman_blt_sse2 (
5802 src_bits, dst_bits, src_stride, dst_stride, src_bpp, dst_bpp,
5803 src_x, src_y, dst_x, dst_y, width, height))
5806 return _pixman_implementation_blt (
5808 src_bits, dst_bits, src_stride, dst_stride, src_bpp, dst_bpp,
5809 src_x, src_y, dst_x, dst_y, width, height);
5815 #if defined(__GNUC__) && !defined(__x86_64__) && !defined(__amd64__)
5816 __attribute__((__force_align_arg_pointer__))
5818 static pixman_bool_t
5819 sse2_fill (pixman_implementation_t *imp,
5829 if (!pixman_fill_sse2 (bits, stride, bpp, x, y, width, height, xor))
5831 return _pixman_implementation_fill (
5832 imp->delegate, bits, stride, bpp, x, y, width, height, xor);
5839 sse2_fetch_x8r8g8b8 (pixman_iter_t *iter, const uint32_t *mask)
5841 int w = iter->width;
5842 __m128i ff000000 = mask_ff000000;
5843 uint32_t *dst = iter->buffer;
5844 uint32_t *src = (uint32_t *)iter->bits;
5846 iter->bits += iter->stride;
5848 while (w && ((unsigned long)dst) & 0x0f)
5850 *dst++ = (*src++) | 0xff000000;
5857 (__m128i *)dst, _mm_or_si128 (
5858 load_128_unaligned ((__m128i *)src), ff000000));
5867 *dst++ = (*src++) | 0xff000000;
5871 return iter->buffer;
5875 sse2_fetch_r5g6b5 (pixman_iter_t *iter, const uint32_t *mask)
5877 int w = iter->width;
5878 uint32_t *dst = iter->buffer;
5879 uint16_t *src = (uint16_t *)iter->bits;
5880 __m128i ff000000 = mask_ff000000;
5882 iter->bits += iter->stride;
5884 while (w && ((unsigned long)dst) & 0x0f)
5886 uint16_t s = *src++;
5888 *dst++ = CONVERT_0565_TO_8888 (s);
5896 s = _mm_loadu_si128 ((__m128i *)src);
5898 lo = unpack_565_to_8888 (_mm_unpacklo_epi16 (s, _mm_setzero_si128 ()));
5899 hi = unpack_565_to_8888 (_mm_unpackhi_epi16 (s, _mm_setzero_si128 ()));
5901 save_128_aligned ((__m128i *)(dst + 0), _mm_or_si128 (lo, ff000000));
5902 save_128_aligned ((__m128i *)(dst + 4), _mm_or_si128 (hi, ff000000));
5911 uint16_t s = *src++;
5913 *dst++ = CONVERT_0565_TO_8888 (s);
5917 return iter->buffer;
5921 sse2_fetch_a8 (pixman_iter_t *iter, const uint32_t *mask)
5923 int w = iter->width;
5924 uint32_t *dst = iter->buffer;
5925 uint8_t *src = iter->bits;
5926 __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6;
5928 iter->bits += iter->stride;
5930 while (w && (((unsigned long)dst) & 15))
5932 *dst++ = *(src++) << 24;
5938 xmm0 = _mm_loadu_si128((__m128i *)src);
5940 xmm1 = _mm_unpacklo_epi8 (_mm_setzero_si128(), xmm0);
5941 xmm2 = _mm_unpackhi_epi8 (_mm_setzero_si128(), xmm0);
5942 xmm3 = _mm_unpacklo_epi16 (_mm_setzero_si128(), xmm1);
5943 xmm4 = _mm_unpackhi_epi16 (_mm_setzero_si128(), xmm1);
5944 xmm5 = _mm_unpacklo_epi16 (_mm_setzero_si128(), xmm2);
5945 xmm6 = _mm_unpackhi_epi16 (_mm_setzero_si128(), xmm2);
5947 _mm_store_si128(((__m128i *)(dst + 0)), xmm3);
5948 _mm_store_si128(((__m128i *)(dst + 4)), xmm4);
5949 _mm_store_si128(((__m128i *)(dst + 8)), xmm5);
5950 _mm_store_si128(((__m128i *)(dst + 12)), xmm6);
5959 *dst++ = *(src++) << 24;
5963 return iter->buffer;
5968 pixman_format_code_t format;
5969 pixman_iter_get_scanline_t get_scanline;
5972 static const fetcher_info_t fetchers[] =
5974 { PIXMAN_x8r8g8b8, sse2_fetch_x8r8g8b8 },
5975 { PIXMAN_r5g6b5, sse2_fetch_r5g6b5 },
5976 { PIXMAN_a8, sse2_fetch_a8 },
5981 sse2_src_iter_init (pixman_implementation_t *imp,
5982 pixman_iter_t *iter,
5983 pixman_image_t *image,
5984 int x, int y, int width, int height,
5985 uint8_t *buffer, iter_flags_t flags)
5988 (FAST_PATH_STANDARD_FLAGS | FAST_PATH_ID_TRANSFORM)
5990 if ((flags & ITER_NARROW) &&
5991 (image->common.flags & FLAGS) == FLAGS &&
5993 x + width <= image->bits.width &&
5994 y + height <= image->bits.height)
5996 const fetcher_info_t *f;
5998 for (f = &fetchers[0]; f->format != PIXMAN_null; f++)
6000 if (image->common.extended_format_code == f->format)
6002 uint8_t *b = (uint8_t *)image->bits.bits;
6003 int s = image->bits.rowstride * 4;
6005 iter->bits = b + s * y + x * PIXMAN_FORMAT_BPP (f->format) / 8;
6008 iter->get_scanline = f->get_scanline;
6014 imp->delegate->src_iter_init (
6015 imp->delegate, iter, image, x, y, width, height, buffer, flags);
6018 #if defined(__GNUC__) && !defined(__x86_64__) && !defined(__amd64__)
6019 __attribute__((__force_align_arg_pointer__))
6021 pixman_implementation_t *
6022 _pixman_implementation_create_sse2 (pixman_implementation_t *fallback)
6024 pixman_implementation_t *imp = _pixman_implementation_create (fallback, sse2_fast_paths);
6026 /* SSE2 constants */
6027 mask_565_r = create_mask_2x32_128 (0x00f80000, 0x00f80000);
6028 mask_565_g1 = create_mask_2x32_128 (0x00070000, 0x00070000);
6029 mask_565_g2 = create_mask_2x32_128 (0x000000e0, 0x000000e0);
6030 mask_565_b = create_mask_2x32_128 (0x0000001f, 0x0000001f);
6031 mask_red = create_mask_2x32_128 (0x00f80000, 0x00f80000);
6032 mask_green = create_mask_2x32_128 (0x0000fc00, 0x0000fc00);
6033 mask_blue = create_mask_2x32_128 (0x000000f8, 0x000000f8);
6034 mask_565_fix_rb = create_mask_2x32_128 (0x00e000e0, 0x00e000e0);
6035 mask_565_fix_g = create_mask_2x32_128 (0x0000c000, 0x0000c000);
6036 mask_0080 = create_mask_16_128 (0x0080);
6037 mask_00ff = create_mask_16_128 (0x00ff);
6038 mask_0101 = create_mask_16_128 (0x0101);
6039 mask_ffff = create_mask_16_128 (0xffff);
6040 mask_ff000000 = create_mask_2x32_128 (0xff000000, 0xff000000);
6041 mask_alpha = create_mask_2x32_128 (0x00ff0000, 0x00000000);
6043 /* Set up function pointers */
6044 imp->combine_32[PIXMAN_OP_OVER] = sse2_combine_over_u;
6045 imp->combine_32[PIXMAN_OP_OVER_REVERSE] = sse2_combine_over_reverse_u;
6046 imp->combine_32[PIXMAN_OP_IN] = sse2_combine_in_u;
6047 imp->combine_32[PIXMAN_OP_IN_REVERSE] = sse2_combine_in_reverse_u;
6048 imp->combine_32[PIXMAN_OP_OUT] = sse2_combine_out_u;
6049 imp->combine_32[PIXMAN_OP_OUT_REVERSE] = sse2_combine_out_reverse_u;
6050 imp->combine_32[PIXMAN_OP_ATOP] = sse2_combine_atop_u;
6051 imp->combine_32[PIXMAN_OP_ATOP_REVERSE] = sse2_combine_atop_reverse_u;
6052 imp->combine_32[PIXMAN_OP_XOR] = sse2_combine_xor_u;
6053 imp->combine_32[PIXMAN_OP_ADD] = sse2_combine_add_u;
6055 imp->combine_32[PIXMAN_OP_SATURATE] = sse2_combine_saturate_u;
6057 imp->combine_32_ca[PIXMAN_OP_SRC] = sse2_combine_src_ca;
6058 imp->combine_32_ca[PIXMAN_OP_OVER] = sse2_combine_over_ca;
6059 imp->combine_32_ca[PIXMAN_OP_OVER_REVERSE] = sse2_combine_over_reverse_ca;
6060 imp->combine_32_ca[PIXMAN_OP_IN] = sse2_combine_in_ca;
6061 imp->combine_32_ca[PIXMAN_OP_IN_REVERSE] = sse2_combine_in_reverse_ca;
6062 imp->combine_32_ca[PIXMAN_OP_OUT] = sse2_combine_out_ca;
6063 imp->combine_32_ca[PIXMAN_OP_OUT_REVERSE] = sse2_combine_out_reverse_ca;
6064 imp->combine_32_ca[PIXMAN_OP_ATOP] = sse2_combine_atop_ca;
6065 imp->combine_32_ca[PIXMAN_OP_ATOP_REVERSE] = sse2_combine_atop_reverse_ca;
6066 imp->combine_32_ca[PIXMAN_OP_XOR] = sse2_combine_xor_ca;
6067 imp->combine_32_ca[PIXMAN_OP_ADD] = sse2_combine_add_ca;
6069 imp->blt = sse2_blt;
6070 imp->fill = sse2_fill;
6072 imp->src_iter_init = sse2_src_iter_init;