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 Libav.
8 ;* Libav 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 ;* Libav 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 Libav; if not, write to the Free Software
20 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 ;******************************************************************************
24 %include "x86util.asm"
28 minshort: times 8 dw 0x8000
29 yuv2yuvX_16_start: times 4 dd 0x4000 - 0x40000000
30 yuv2yuvX_10_start: times 4 dd 0x10000
31 yuv2yuvX_9_start: times 4 dd 0x20000
32 yuv2yuvX_10_upper: times 8 dw 0x3ff
33 yuv2yuvX_9_upper: times 8 dw 0x1ff
35 pd_4min0x40000:times 4 dd 4 - (0x40000)
38 pw_512: times 8 dw 512
39 pw_1024: times 8 dw 1024
43 ;-----------------------------------------------------------------------------
44 ; vertical line scaling
46 ; void yuv2plane1_<output_size>_<opt>(const int16_t *src, uint8_t *dst, int dstW,
47 ; const uint8_t *dither, int offset)
49 ; void yuv2planeX_<output_size>_<opt>(const int16_t *filter, int filterSize,
50 ; const int16_t **src, uint8_t *dst, int dstW,
51 ; const uint8_t *dither, int offset)
53 ; Scale one or $filterSize lines of source data to generate one line of output
54 ; data. The input is 15-bit in int16_t if $output_size is [8,10] and 19-bit in
55 ; int32_t if $output_size is 16. $filter is 12-bits. $filterSize is a multiple
56 ; of 2. $offset is either 0 or 3. $dither holds 8 values.
57 ;-----------------------------------------------------------------------------
59 %macro yuv2planeX_fn 3
69 cglobal yuv2planeX_%1, %3, 7, %2
70 %if %1 == 8 || %1 == 9 || %1 == 10
76 %assign pad 0x2c - (stack_offset & 15)
83 ; create registers holding dither
84 movq m_dith, [r5] ; dither
88 punpcklqdq m_dith, m_dith
90 PALIGNR m_dith, m_dith, 3, m0
95 punpcklwd m8, m_dith, m6
98 punpcklwd m5, m_dith, m6
105 mova [rsp+16], m_dith
108 punpcklbw m5, m_dith, m6
112 punpcklwd m3, m_dith, m6
121 mova [rsp+24], m_dith
122 %endif ; mmsize == 8/16
129 ; the rep here is for the 8bit output mmx case, where dither covers
130 ; 8 pixels but we can only handle 2 pixels per register, and thus 4
131 ; pixels per iteration. In order to not have to keep track of where
132 ; we are w.r.t. dithering, we unroll the mmx/8bit loop x2.
139 mova m2, [rsp+mmsize*(0+%%i)]
140 mova m1, [rsp+mmsize*(1+%%i)]
145 %else ; %1 == 9/10/16
146 mova m1, [yuv2yuvX_%1_start]
148 %endif ; %1 == 8/9/10/16
152 mov r6, [r2+gprsize*cntr_reg-2*gprsize]
155 mova m5, [r6+r5*4+mmsize]
158 %endif ; %1 == 8/9/10/16
159 mov r6, [r2+gprsize*cntr_reg-gprsize]
162 mova m6, [r6+r5*4+mmsize]
165 %endif ; %1 == 8/9/10/16
168 movd m0, [r0+2*cntr_reg-4]; coeff[0], coeff[1]
170 pshuflw m7, m0, 0 ; coeff[0]
171 pshuflw m0, m0, 0x55 ; coeff[1]
172 pmovsxwd m7, m7 ; word -> dword
173 pmovsxwd m0, m0 ; word -> dword
194 %endif ; %1 == 8/9/10/16
197 jg .filterloop_ %+ %%i
205 %endif ; %1 == 8/9/10/16
211 %else ; %1 == 9/10/16
221 %endif ; mmx2/sse2/sse4/avx
222 pminsw m2, [yuv2yuvX_%1_upper]
223 %endif ; %1 == 9/10/16
225 %endif ; %1 == 8/9/10/16
242 %else ; %1 == 9/10/16
244 %endif ; %1 == 8/9/10/16
247 %define PALIGNR PALIGNR_MMX
250 yuv2planeX_fn 8, 0, 7
251 yuv2planeX_fn 9, 0, 5
252 yuv2planeX_fn 10, 0, 5
256 yuv2planeX_fn 8, 10, 7
257 yuv2planeX_fn 9, 7, 5
258 yuv2planeX_fn 10, 7, 5
260 %define PALIGNR PALIGNR_SSSE3
262 yuv2planeX_fn 8, 10, 7
263 yuv2planeX_fn 9, 7, 5
264 yuv2planeX_fn 10, 7, 5
265 yuv2planeX_fn 16, 8, 5
269 yuv2planeX_fn 8, 10, 7
270 yuv2planeX_fn 9, 7, 5
271 yuv2planeX_fn 10, 7, 5
274 ; %1=outout-bpc, %2=alignment (u/a)
275 %macro yuv2plane1_mainloop 2
278 paddsw m0, m2, [r0+r2*2+mmsize*0]
279 paddsw m1, m3, [r0+r2*2+mmsize*1]
285 paddd m0, m4, [r0+r2*4+mmsize*0]
286 paddd m1, m4, [r0+r2*4+mmsize*1]
287 paddd m2, m4, [r0+r2*4+mmsize*2]
288 paddd m3, m4, [r0+r2*4+mmsize*3]
293 %if cpuflag(sse4) ; avx/sse4
301 %endif ; mmx/sse2/sse4/avx
303 mov%2 [r1+r2*2+mmsize], m2
305 paddsw m0, m2, [r0+r2*2+mmsize*0]
306 paddsw m1, m2, [r0+r2*2+mmsize*1]
314 mov%2 [r1+r2*2+mmsize], m1
320 %macro yuv2plane1_fn 3
321 cglobal yuv2plane1_%1, %3, %3, %2
323 and r2, ~(mmsize - 1)
339 ; create registers holding dither
340 movq m3, [r3] ; dither
345 %endif ; mmsize == 16
346 PALIGNR_MMX m3, m3, 3, m2
350 punpckhbw m3, m4 ; byte->word
351 punpcklbw m2, m4 ; byte->word
365 %if cpuflag(sse4) ; sse4/avx
368 mova m4, [pd_4min0x40000]
370 %endif ; mmx/sse2/sse4/avx
373 ; actual pixel scaling
375 yuv2plane1_mainloop %1, a
379 yuv2plane1_mainloop %1, a
382 yuv2plane1_mainloop %1, u
383 %endif ; mmsize == 8/16
389 yuv2plane1_fn 8, 0, 5
390 yuv2plane1_fn 16, 0, 3
393 yuv2plane1_fn 9, 0, 3
394 yuv2plane1_fn 10, 0, 3
398 yuv2plane1_fn 8, 5, 5
399 yuv2plane1_fn 9, 5, 3
400 yuv2plane1_fn 10, 5, 3
401 yuv2plane1_fn 16, 6, 3
404 yuv2plane1_fn 16, 5, 3
408 yuv2plane1_fn 8, 5, 5
409 yuv2plane1_fn 9, 5, 3
410 yuv2plane1_fn 10, 5, 3
411 yuv2plane1_fn 16, 5, 3