1 ;******************************************************************************
2 ;* x86-optimized vertical line scaling functions
3 ;* Copyright (c) 2011 Ronald S. Bultje <rsbultje@gmail.com>
4 ;* Kieran Kunhya <kieran@kunhya.com>
6 ;* This file is part of FFmpeg.
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.
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.
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 ;******************************************************************************
23 %include "libavutil/x86/x86util.asm"
27 minshort: times 8 dw 0x8000
28 yuv2yuvX_16_start: times 4 dd 0x4000 - 0x40000000
29 yuv2yuvX_10_start: times 4 dd 0x10000
30 yuv2yuvX_9_start: times 4 dd 0x20000
31 yuv2yuvX_10_upper: times 8 dw 0x3ff
32 yuv2yuvX_9_upper: times 8 dw 0x1ff
34 pd_4min0x40000:times 4 dd 4 - (0x40000)
37 pw_512: times 8 dw 512
38 pw_1024: times 8 dw 1024
42 ;-----------------------------------------------------------------------------
43 ; vertical line scaling
45 ; void yuv2plane1_<output_size>_<opt>(const int16_t *src, uint8_t *dst, int dstW,
46 ; const uint8_t *dither, int offset)
48 ; void yuv2planeX_<output_size>_<opt>(const int16_t *filter, int filterSize,
49 ; const int16_t **src, uint8_t *dst, int dstW,
50 ; const uint8_t *dither, int offset)
52 ; Scale one or $filterSize lines of source data to generate one line of output
53 ; data. The input is 15-bit in int16_t if $output_size is [8,10] and 19-bit in
54 ; int32_t if $output_size is 16. $filter is 12-bits. $filterSize is a multiple
55 ; of 2. $offset is either 0 or 3. $dither holds 8 values.
56 ;-----------------------------------------------------------------------------
57 %macro yuv2planeX_mainloop 1
60 ; the rep here is for the 8bit output mmx case, where dither covers
61 ; 8 pixels but we can only handle 2 pixels per register, and thus 4
62 ; pixels per iteration. In order to not have to keep track of where
63 ; we are w.r.t. dithering, we unroll the mmx/8bit loop x2.
65 %assign %%repcnt 16/mmsize
74 mova m2, [rsp+mmsize*(0+%%i)]
75 mova m1, [rsp+mmsize*(1+%%i)]
81 mova m1, [yuv2yuvX_%1_start]
83 %endif ; %1 == 8/9/10/16
84 movsx cntr_reg, fltsizem
87 mov r6, [srcq+gprsize*cntr_reg-2*gprsize]
90 mova m5, [r6+r5*4+mmsize]
93 %endif ; %1 == 8/9/10/16
94 mov r6, [srcq+gprsize*cntr_reg-gprsize]
97 mova m6, [r6+r5*4+mmsize]
100 %endif ; %1 == 8/9/10/16
103 movd m0, [filterq+2*cntr_reg-4] ; coeff[0], coeff[1]
105 pshuflw m7, m0, 0 ; coeff[0]
106 pshuflw m0, m0, 0x55 ; coeff[1]
107 pmovsxwd m7, m7 ; word -> dword
108 pmovsxwd m0, m0 ; word -> dword
129 %endif ; %1 == 8/9/10/16
132 jg .filterloop_ %+ %%i
140 %endif ; %1 == 8/9/10/16
146 %else ; %1 == 9/10/16
156 %endif ; mmxext/sse2/sse4/avx
157 pminsw m2, [yuv2yuvX_%1_upper]
158 %endif ; %1 == 9/10/16
160 %endif ; %1 == 8/9/10/16
170 %macro yuv2planeX_fn 3
173 %define cntr_reg fltsizeq
180 cglobal yuv2planeX_%1, %3, 8, %2, filter, fltsize, src, dst, w, dither, offset
181 %if %1 == 8 || %1 == 9 || %1 == 10
183 %endif ; %1 == 8/9/10
187 %assign pad 0x2c - (stack_offset & 15)
194 ; create registers holding dither
195 movq m_dith, [ditherq] ; dither
196 test offsetd, offsetd
199 punpcklqdq m_dith, m_dith
200 %endif ; mmsize == 16
201 PALIGNR m_dith, m_dith, 3, m0
206 punpcklwd m8, m_dith, m6
209 punpcklwd m5, m_dith, m6
216 mova [rsp+16], m_dith
219 punpcklbw m5, m_dith, m6
223 punpcklwd m3, m_dith, m6
232 mova [rsp+24], m_dith
233 %endif ; mmsize == 8/16
238 yuv2planeX_mainloop %1
247 %else ; %1 == 9/10/16
249 %endif ; %1 == 8/9/10/16
254 yuv2planeX_fn 8, 0, 7
255 yuv2planeX_fn 9, 0, 5
256 yuv2planeX_fn 10, 0, 5
260 yuv2planeX_fn 8, 10, 7
261 yuv2planeX_fn 9, 7, 5
262 yuv2planeX_fn 10, 7, 5
265 yuv2planeX_fn 8, 10, 7
266 yuv2planeX_fn 9, 7, 5
267 yuv2planeX_fn 10, 7, 5
268 yuv2planeX_fn 16, 8, 5
270 %if HAVE_AVX_EXTERNAL
272 yuv2planeX_fn 8, 10, 7
273 yuv2planeX_fn 9, 7, 5
274 yuv2planeX_fn 10, 7, 5
277 ; %1=outout-bpc, %2=alignment (u/a)
278 %macro yuv2plane1_mainloop 2
281 paddsw m0, m2, [srcq+wq*2+mmsize*0]
282 paddsw m1, m3, [srcq+wq*2+mmsize*1]
288 paddd m0, m4, [srcq+wq*4+mmsize*0]
289 paddd m1, m4, [srcq+wq*4+mmsize*1]
290 paddd m2, m4, [srcq+wq*4+mmsize*2]
291 paddd m3, m4, [srcq+wq*4+mmsize*3]
296 %if cpuflag(sse4) ; avx/sse4
304 %endif ; mmx/sse2/sse4/avx
305 mov%2 [dstq+wq*2+mmsize*0], m0
306 mov%2 [dstq+wq*2+mmsize*1], m2
308 paddsw m0, m2, [srcq+wq*2+mmsize*0]
309 paddsw m1, m2, [srcq+wq*2+mmsize*1]
316 mov%2 [dstq+wq*2+mmsize*0], m0
317 mov%2 [dstq+wq*2+mmsize*1], m1
323 %macro yuv2plane1_fn 3
324 cglobal yuv2plane1_%1, %3, %3, %2, src, dst, w, dither, offset
327 and wq, ~(mmsize - 1)
331 lea dstq, [dstq+wq*2]
334 lea srcq, [srcq+wq*4]
336 lea srcq, [srcq+wq*2]
343 ; create registers holding dither
344 movq m3, [ditherq] ; dither
345 test offsetd, offsetd
349 %endif ; mmsize == 16
350 PALIGNR m3, m3, 3, m2
354 punpckhbw m3, m4 ; byte->word
355 punpcklbw m2, m4 ; byte->word
369 %if cpuflag(sse4) ; sse4/avx
372 mova m4, [pd_4min0x40000]
374 %endif ; mmx/sse2/sse4/avx
377 ; actual pixel scaling
379 yuv2plane1_mainloop %1, a
383 yuv2plane1_mainloop %1, a
386 yuv2plane1_mainloop %1, u
387 %endif ; mmsize == 8/16
393 yuv2plane1_fn 8, 0, 5
394 yuv2plane1_fn 16, 0, 3
397 yuv2plane1_fn 9, 0, 3
398 yuv2plane1_fn 10, 0, 3
402 yuv2plane1_fn 8, 5, 5
403 yuv2plane1_fn 9, 5, 3
404 yuv2plane1_fn 10, 5, 3
405 yuv2plane1_fn 16, 6, 3
408 yuv2plane1_fn 16, 5, 3
410 %if HAVE_AVX_EXTERNAL
412 yuv2plane1_fn 8, 5, 5
413 yuv2plane1_fn 9, 5, 3
414 yuv2plane1_fn 10, 5, 3
415 yuv2plane1_fn 16, 5, 3