2 * composite_line_yuv_sse2_simple.c
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Maksym Veremeyenko <verem@m1stereo.tv>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 void composite_line_yuv_sse2_simple(uint8_t *dest, uint8_t *src, int width, uint8_t *alpha_b, uint8_t *alpha_a, int weight)
24 const static unsigned char const1[] =
26 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00
31 "pxor %%xmm0, %%xmm0 \n\t" /* clear zero register */
32 "movdqu (%4), %%xmm9 \n\t" /* load const1 */
33 "movd %0, %%xmm1 \n\t" /* load weight and decompose */
34 "movlhps %%xmm1, %%xmm1 \n\t"
35 "pshuflw $0, %%xmm1, %%xmm1 \n\t"
36 "pshufhw $0, %%xmm1, %%xmm1 \n\t"
41 00 W 00 W 00 W 00 W 00 W 00 W 00 W 00 W
44 "movq (%1), %%xmm2 \n\t" /* load source alpha */
45 "punpcklbw %%xmm0, %%xmm2 \n\t" /* unpack alpha 8 8-bits alphas to 8 16-bits values */
51 00 A8 00 A7 00 A6 00 A5 00 A4 00 A3 00 A2 00 A1
53 "pmullw %%xmm1, %%xmm2 \n\t" /* premultiply source alpha */
54 "psrlw $8, %%xmm2 \n\t"
59 00 A8 00 A7 00 A6 00 A5 00 A4 00 A3 00 A2 00 A1
64 DSTa = DSTa + (SRCa * (0xFF - DSTa)) >> 8
66 "movq (%5), %%xmm3 \n\t" /* load dst alpha */
67 "punpcklbw %%xmm0, %%xmm3 \n\t" /* unpack dst 8 8-bits alphas to 8 16-bits values */
68 "movdqa %%xmm9, %%xmm4 \n\t"
69 "psubw %%xmm3, %%xmm4 \n\t"
70 "pmullw %%xmm2, %%xmm4 \n\t"
71 "psrlw $8, %%xmm4 \n\t"
72 "paddw %%xmm4, %%xmm3 \n\t"
73 "packuswb %%xmm0, %%xmm3 \n\t"
74 "movq %%xmm3, (%5) \n\t" /* save dst alpha */
76 "movdqu (%2), %%xmm3 \n\t" /* load src */
77 "movdqu (%3), %%xmm4 \n\t" /* load dst */
78 "movdqa %%xmm3, %%xmm5 \n\t" /* dub src */
79 "movdqa %%xmm4, %%xmm6 \n\t" /* dub dst */
87 U8 V8 U7 V7 U6 V6 U5 V5 U4 V4 U3 V3 U2 V2 U1 V1
90 "punpcklbw %%xmm0, %%xmm5 \n\t" /* unpack src low */
91 "punpcklbw %%xmm0, %%xmm6 \n\t" /* unpack dst low */
92 "punpckhbw %%xmm0, %%xmm3 \n\t" /* unpack src high */
93 "punpckhbw %%xmm0, %%xmm4 \n\t" /* unpack dst high */
99 00 U4 00 V4 00 U3 00 V3 00 U2 00 V2 00 U1 00 V1
104 00 U8 00 V8 00 U7 00 V7 00 U6 00 V6 00 U5 00 V5
107 "movdqa %%xmm2, %%xmm7 \n\t" /* dub alpha */
108 "movdqa %%xmm2, %%xmm8 \n\t" /* dub alpha */
109 "movlhps %%xmm7, %%xmm7 \n\t" /* dub low */
110 "movhlps %%xmm8, %%xmm8 \n\t" /* dub high */
115 00 A4 00 A3 00 A2 00 A1 00 A4 00 A3 00 A2 00 A1
118 00 A8 00 A7 00 A6 00 A5 00 A8 00 A7 00 A6 00 A5
121 "pshuflw $0x50, %%xmm7, %%xmm7 \n\t"
122 "pshuflw $0x50, %%xmm8, %%xmm8 \n\t"
123 "pshufhw $0xFA, %%xmm7, %%xmm7 \n\t"
124 "pshufhw $0xFA, %%xmm8, %%xmm8 \n\t"
127 xmm7 (src alpha lower)
129 00 A4 00 A4 00 A3 00 A3 00 A2 00 A2 00 A1 00 A1
131 xmm8 (src alpha upper)
132 00 A8 00 A8 00 A7 00 A7 00 A6 00 A6 00 A5 00 A5
137 DST = SRC * ALPHA + DST * (0xFF - ALPHA)
138 SRC * ALPHA + DST * 0xFF - DST * ALPHA
139 (SRC - DST) * ALPHA + DST * 0xFF
142 "psubw %%xmm4, %%xmm3 \n\t" /* src = src - dst */
143 "psubw %%xmm6, %%xmm5 \n\t"
144 "pmullw %%xmm8, %%xmm3 \n\t" /* src = src * alpha */
145 "pmullw %%xmm7, %%xmm5 \n\t"
146 "pmullw %%xmm9, %%xmm4 \n\t" /* dst = dst * 0xFF */
147 "pmullw %%xmm9, %%xmm6 \n\t"
148 "paddw %%xmm3, %%xmm4 \n\t" /* dst = dst + src */
149 "paddw %%xmm5, %%xmm6 \n\t"
150 "psrlw $8, %%xmm4 \n\t" /* dst = dst >> 8 */
151 "psrlw $8, %%xmm6 \n\t"
152 // "pminsw %%xmm9, %%xmm4 \n\t" /* clamp values */
153 // "pminsw %%xmm9, %%xmm6 \n\t"
158 00 U4 00 V4 00 U3 00 V3 00 U2 00 V2 00 U1 00 V1
162 00 U8 00 V8 00 U7 00 V7 00 U6 00 V6 00 U5 00 V5
164 "packuswb %%xmm4, %%xmm6 \n\t"
169 U8 V8 U7 V7 U6 V6 U5 V5 U4 V4 U3 V3 U2 V2 U1 V1
171 "movdqu %%xmm6, (%3) \n\t" /* store dst */
182 "jnz loop_start \n\t"
185 : "r" (weight >> 8), "r" (alpha_b), "r" (src), "r" (dest), "r" (const1) , "r" (alpha_a), "r" (width / 8)
186 //: "xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7","xmm8","xmm9", "memory"