]> git.sesse.net Git - mlt/blob - src/modules/core/composite_line_yuv_sse2_simple.c
Merge branch 'frei0r-metadata'
[mlt] / src / modules / core / composite_line_yuv_sse2_simple.c
1 /*
2  * composite_line_yuv_sse2_simple.c
3  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4  * Author: Maksym Veremeyenko <verem@m1stereo.tv>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <inttypes.h>
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)
23 {
24     const static unsigned char const1[] =
25     {
26         0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00
27     };
28
29     __asm__ volatile
30     (
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"
37
38         /*
39             xmm1 (weight)
40
41                     00  W 00  W 00  W 00  W 00  W 00  W 00  W 00  W
42         */
43         "loop_start:                            \n\t"
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 */
46
47         /*
48             xmm2 (src alpha)
49             xmm3 (dst alpha)
50
51                     00 A8 00 A7 00 A6 00 A5 00 A4 00 A3 00 A2 00 A1
52         */
53         "pmullw         %%xmm1, %%xmm2          \n\t"   /* premultiply source alpha */
54         "psrlw          $8, %%xmm2              \n\t"
55
56         /*
57             xmm2 (premultiplied)
58
59                     00 A8 00 A7 00 A6 00 A5 00 A4 00 A3 00 A2 00 A1
60         */
61
62
63         /*
64             DSTa = DSTa + (SRCa * (0xFF - DSTa)) >> 8
65         */
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 */
75
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 */
80
81         /*
82             xmm3 (src)
83             xmm4 (dst)
84             xmm5 (src)
85             xmm6 (dst)
86
87                     U8 V8 U7 V7 U6 V6 U5 V5 U4 V4 U3 V3 U2 V2 U1 V1
88         */
89
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 */
94
95         /*
96             xmm5 (src_l)
97             xmm6 (dst_l)
98
99                     00 U4 00 V4 00 U3 00 V3 00 U2 00 V2 00 U1 00 V1
100
101             xmm3 (src_u)
102             xmm4 (dst_u)
103
104                     00 U8 00 V8 00 U7 00 V7 00 U6 00 V6 00 U5 00 V5
105         */
106
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 */
111
112         /*
113             xmm7 (src alpha)
114
115                     00 A4 00 A3 00 A2 00 A1 00 A4 00 A3 00 A2 00 A1
116             xmm8 (src alpha)
117
118                     00 A8 00 A7 00 A6 00 A5 00 A8 00 A7 00 A6 00 A5
119         */
120
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"
125
126         /*
127             xmm7 (src alpha lower)
128
129                     00 A4 00 A4 00 A3 00 A3 00 A2 00 A2 00 A1 00 A1
130
131             xmm8 (src alpha upper)
132                     00 A8 00 A8 00 A7 00 A7 00 A6 00 A6 00 A5 00 A5
133         */
134
135
136         /*
137             DST = SRC * ALPHA + DST * (0xFF - ALPHA)
138                 SRC * ALPHA + DST * 0xFF - DST * ALPHA
139                 (SRC - DST) * ALPHA + DST * 0xFF
140
141         */
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"
154
155         /*
156             xmm6 (dst_l)
157
158                     00 U4 00 V4 00 U3 00 V3 00 U2 00 V2 00 U1 00 V1
159
160             xmm4 (dst_u)
161
162                     00 U8 00 V8 00 U7 00 V7 00 U6 00 V6 00 U5 00 V5
163         */
164         "packuswb       %%xmm4, %%xmm6          \n\t"
165
166         /*
167             xmm6 (dst)
168
169                     U8 V8 U7 V7 U6 V6 U5 V5 U4 V4 U3 V3 U2 V2 U1 V1
170         */
171         "movdqu         %%xmm6, (%3)            \n\t"   /* store dst */
172
173         /*
174             increment pointers
175         */
176         "add            $0x08, %1               \n\t"
177         "add            $0x08, %5               \n\t"
178         "add            $0x10, %2               \n\t"
179         "add            $0x10, %3               \n\t"
180
181         "dec            %6                      \n\t"
182         "jnz            loop_start              \n\t"
183
184         :
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"
187     );
188 };