]> git.sesse.net Git - ffmpeg/blob - libavfilter/x86/vf_blend.asm
Merge commit 'a0562e531723923b632684c7b51a9dd584bf534f'
[ffmpeg] / libavfilter / x86 / vf_blend.asm
1 ;*****************************************************************************
2 ;* x86-optimized functions for blend filter
3 ;*
4 ;* Copyright (C) 2015 Paul B Mahol
5 ;*
6 ;* This file is part of FFmpeg.
7 ;*
8 ;* FFmpeg is free software; you can redistribute it and/or
9 ;* modify it under the terms of the GNU Lesser General Public
10 ;* License as published by the Free Software Foundation; either
11 ;* version 2.1 of the License, or (at your option) any later version.
12 ;*
13 ;* FFmpeg is distributed in the hope that it will be useful,
14 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 ;* Lesser General Public License for more details.
17 ;*
18 ;* You should have received a copy of the GNU Lesser General Public
19 ;* License along with FFmpeg; if not, write to the Free Software
20 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 ;******************************************************************************
22
23 %include "libavutil/x86/x86util.asm"
24
25 %if ARCH_X86_64
26 SECTION_RODATA
27
28 pw_128: times 8 dw 128
29 pw_255: times 8 dw 255
30 pb_127: times 16 db 127
31 pb_128: times 16 db 128
32 pb_255: times 16 db 255
33
34 SECTION .text
35
36 INIT_XMM sse2
37 cglobal blend_xor, 9, 11, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
38     add      topq, widthq
39     add   bottomq, widthq
40     add      dstq, widthq
41     sub      endq, startq
42     neg    widthq
43 .nextrow:
44     mov       r10q, widthq
45     %define      x  r10q
46
47     .loop:
48         movu            m0, [topq + x]
49         movu            m1, [bottomq + x]
50         pxor            m0, m1
51         mova    [dstq + x], m0
52         add           r10q, mmsize
53     jl .loop
54
55     add          topq, top_linesizeq
56     add       bottomq, bottom_linesizeq
57     add          dstq, dst_linesizeq
58     sub          endd, 1
59     jg .nextrow
60 REP_RET
61
62 cglobal blend_or, 9, 11, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
63     add      topq, widthq
64     add   bottomq, widthq
65     add      dstq, widthq
66     sub      endq, startq
67     neg    widthq
68 .nextrow:
69     mov       r10q, widthq
70     %define      x  r10q
71
72     .loop:
73         movu            m0, [topq + x]
74         movu            m1, [bottomq + x]
75         por             m0, m1
76         mova    [dstq + x], m0
77         add           r10q, mmsize
78     jl .loop
79
80     add          topq, top_linesizeq
81     add       bottomq, bottom_linesizeq
82     add          dstq, dst_linesizeq
83     sub          endd, 1
84     jg .nextrow
85 REP_RET
86
87 cglobal blend_and, 9, 11, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
88     add      topq, widthq
89     add   bottomq, widthq
90     add      dstq, widthq
91     sub      endq, startq
92     neg    widthq
93 .nextrow:
94     mov       r10q, widthq
95     %define      x  r10q
96
97     .loop:
98         movu            m0, [topq + x]
99         movu            m1, [bottomq + x]
100         pand            m0, m1
101         mova    [dstq + x], m0
102         add           r10q, mmsize
103     jl .loop
104
105     add          topq, top_linesizeq
106     add       bottomq, bottom_linesizeq
107     add          dstq, dst_linesizeq
108     sub          endd, 1
109     jg .nextrow
110 REP_RET
111
112 cglobal blend_addition, 9, 11, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
113     add      topq, widthq
114     add   bottomq, widthq
115     add      dstq, widthq
116     sub      endq, startq
117     neg    widthq
118 .nextrow:
119     mov       r10q, widthq
120     %define      x  r10q
121
122     .loop:
123         movu            m0, [topq + x]
124         movu            m1, [bottomq + x]
125         paddusb         m0, m1
126         mova    [dstq + x], m0
127         add           r10q, mmsize
128     jl .loop
129
130     add          topq, top_linesizeq
131     add       bottomq, bottom_linesizeq
132     add          dstq, dst_linesizeq
133     sub          endd, 1
134     jg .nextrow
135 REP_RET
136
137 cglobal blend_subtract, 9, 11, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
138     add      topq, widthq
139     add   bottomq, widthq
140     add      dstq, widthq
141     sub      endq, startq
142     neg    widthq
143 .nextrow:
144     mov       r10q, widthq
145     %define      x  r10q
146
147     .loop:
148         movu            m0, [topq + x]
149         movu            m1, [bottomq + x]
150         psubusb         m0, m1
151         mova    [dstq + x], m0
152         add           r10q, mmsize
153     jl .loop
154
155     add          topq, top_linesizeq
156     add       bottomq, bottom_linesizeq
157     add          dstq, dst_linesizeq
158     sub          endd, 1
159     jg .nextrow
160 REP_RET
161
162 cglobal blend_difference128, 9, 11, 4, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
163     add      topq, widthq
164     add   bottomq, widthq
165     add      dstq, widthq
166     sub      endq, startq
167     pxor       m2, m2
168     mova       m3, [pw_128]
169     neg    widthq
170 .nextrow:
171     mov       r10q, widthq
172     %define      x  r10q
173
174     .loop:
175         movh            m0, [topq + x]
176         movh            m1, [bottomq + x]
177         punpcklbw       m0, m2
178         punpcklbw       m1, m2
179         paddw           m0, m3
180         psubw           m0, m1
181         packuswb        m0, m0
182         movh    [dstq + x], m0
183         add           r10q, mmsize / 2
184     jl .loop
185
186     add          topq, top_linesizeq
187     add       bottomq, bottom_linesizeq
188     add          dstq, dst_linesizeq
189     sub          endd, 1
190     jg .nextrow
191 REP_RET
192
193 cglobal blend_average, 9, 11, 3, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
194     add      topq, widthq
195     add   bottomq, widthq
196     add      dstq, widthq
197     sub      endq, startq
198     pxor       m2, m2
199     neg    widthq
200 .nextrow:
201     mov       r10q, widthq
202     %define      x  r10q
203
204     .loop:
205         movh            m0, [topq + x]
206         movh            m1, [bottomq + x]
207         punpcklbw       m0, m2
208         punpcklbw       m1, m2
209         paddw           m0, m1
210         psrlw           m0, 1
211         packuswb        m0, m0
212         movh    [dstq + x], m0
213         add           r10q, mmsize / 2
214     jl .loop
215
216     add          topq, top_linesizeq
217     add       bottomq, bottom_linesizeq
218     add          dstq, dst_linesizeq
219     sub          endd, 1
220     jg .nextrow
221 REP_RET
222
223 cglobal blend_addition128, 9, 11, 4, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
224     add      topq, widthq
225     add   bottomq, widthq
226     add      dstq, widthq
227     sub      endq, startq
228     pxor       m2, m2
229     mova       m3, [pw_128]
230     neg    widthq
231 .nextrow:
232     mov       r10q, widthq
233     %define      x  r10q
234
235     .loop:
236         movh            m0, [topq + x]
237         movh            m1, [bottomq + x]
238         punpcklbw       m0, m2
239         punpcklbw       m1, m2
240         paddw           m0, m1
241         psubw           m0, m3
242         packuswb        m0, m0
243         movh    [dstq + x], m0
244         add           r10q, mmsize / 2
245     jl .loop
246
247     add          topq, top_linesizeq
248     add       bottomq, bottom_linesizeq
249     add          dstq, dst_linesizeq
250     sub          endd, 1
251     jg .nextrow
252 REP_RET
253
254 cglobal blend_darken, 9, 11, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
255     add      topq, widthq
256     add   bottomq, widthq
257     add      dstq, widthq
258     sub      endq, startq
259     neg    widthq
260 .nextrow:
261     mov       r10q, widthq
262     %define      x  r10q
263
264     .loop:
265         movu            m0, [topq + x]
266         movu            m1, [bottomq + x]
267         pminub          m0, m1
268         mova    [dstq + x], m0
269         add           r10q, mmsize
270     jl .loop
271
272     add          topq, top_linesizeq
273     add       bottomq, bottom_linesizeq
274     add          dstq, dst_linesizeq
275     sub          endd, 1
276     jg .nextrow
277 REP_RET
278
279 cglobal blend_hardmix, 9, 11, 5, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
280     add      topq, widthq
281     add   bottomq, widthq
282     add      dstq, widthq
283     sub      endq, startq
284     mova       m2, [pb_255]
285     mova       m3, [pb_128]
286     mova       m4, [pb_127]
287     neg    widthq
288 .nextrow:
289     mov       r10q, widthq
290     %define      x  r10q
291
292     .loop:
293         movu            m0, [topq + x]
294         movu            m1, [bottomq + x]
295         pxor            m1, m4
296         pxor            m0, m3
297         pcmpgtb         m1, m0
298         pxor            m1, m2
299         mova    [dstq + x], m1
300         add           r10q, mmsize
301     jl .loop
302
303     add          topq, top_linesizeq
304     add       bottomq, bottom_linesizeq
305     add          dstq, dst_linesizeq
306     sub          endd, 1
307     jg .nextrow
308 REP_RET
309
310 cglobal blend_lighten, 9, 11, 2, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
311     add      topq, widthq
312     add   bottomq, widthq
313     add      dstq, widthq
314     sub      endq, startq
315     neg    widthq
316 .nextrow:
317     mov       r10q, widthq
318     %define      x  r10q
319
320     .loop:
321         movu            m0, [topq + x]
322         movu            m1, [bottomq + x]
323         pmaxub          m0, m1
324         mova    [dstq + x], m0
325         add           r10q, mmsize
326     jl .loop
327
328     add          topq, top_linesizeq
329     add       bottomq, bottom_linesizeq
330     add          dstq, dst_linesizeq
331     sub          endd, 1
332     jg .nextrow
333 REP_RET
334
335 cglobal blend_phoenix, 9, 11, 4, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
336     add      topq, widthq
337     add   bottomq, widthq
338     add      dstq, widthq
339     sub      endq, startq
340     mova       m3, [pb_255]
341     neg    widthq
342 .nextrow:
343     mov       r10q, widthq
344     %define      x  r10q
345
346     .loop:
347         movu            m0, [topq + x]
348         movu            m1, [bottomq + x]
349         mova            m2, m0
350         pminub          m0, m1
351         pmaxub          m1, m2
352         mova            m2, m3
353         psubusb         m2, m1
354         paddusb         m2, m0
355         mova    [dstq + x], m2
356         add           r10q, mmsize
357     jl .loop
358
359     add          topq, top_linesizeq
360     add       bottomq, bottom_linesizeq
361     add          dstq, dst_linesizeq
362     sub          endd, 1
363     jg .nextrow
364 REP_RET
365
366 INIT_XMM ssse3
367 cglobal blend_difference, 9, 11, 3, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
368     add      topq, widthq
369     add   bottomq, widthq
370     add      dstq, widthq
371     sub      endq, startq
372     pxor       m2, m2
373     neg    widthq
374 .nextrow:
375     mov       r10q, widthq
376     %define      x  r10q
377
378     .loop:
379         movh            m0, [topq + x]
380         movh            m1, [bottomq + x]
381         punpcklbw       m0, m2
382         punpcklbw       m1, m2
383         psubw           m0, m1
384         pabsw           m0, m0
385         packuswb        m0, m0
386         movh    [dstq + x], m0
387         add           r10q, mmsize / 2
388     jl .loop
389
390     add          topq, top_linesizeq
391     add       bottomq, bottom_linesizeq
392     add          dstq, dst_linesizeq
393     sub          endd, 1
394     jg .nextrow
395 REP_RET
396
397 cglobal blend_negation, 9, 11, 5, 0, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, start, end
398     add      topq, widthq
399     add   bottomq, widthq
400     add      dstq, widthq
401     sub      endq, startq
402     pxor       m2, m2
403     mova       m4, [pw_255]
404     neg    widthq
405 .nextrow:
406     mov       r10q, widthq
407     %define      x  r10q
408
409     .loop:
410         movh            m0, [topq + x]
411         movh            m1, [bottomq + x]
412         punpcklbw       m0, m2
413         punpcklbw       m1, m2
414         mova            m3, m4
415         psubw           m3, m0
416         psubw           m3, m1
417         pabsw           m3, m3
418         mova            m0, m4
419         psubw           m0, m3
420         packuswb        m0, m0
421         movh    [dstq + x], m0
422         add           r10q, mmsize / 2
423     jl .loop
424
425     add          topq, top_linesizeq
426     add       bottomq, bottom_linesizeq
427     add          dstq, dst_linesizeq
428     sub          endd, 1
429     jg .nextrow
430 REP_RET
431
432 %endif