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
62 %define cntr_reg fltsizeq
69 cglobal yuv2planeX_%1, %3, 7, %2, filter, fltsize, src, dst, w, dither, offset
70 %if %1 == 8 || %1 == 9 || %1 == 10
76 %assign pad 0x2c - (stack_offset & 15)
83 ; create registers holding dither
84 movq m_dith, [ditherq] ; 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.
134 %assign %%repcnt 16/mmsize
143 mova m2, [rsp+mmsize*(0+%%i)]
144 mova m1, [rsp+mmsize*(1+%%i)]
149 %else ; %1 == 9/10/16
150 mova m1, [yuv2yuvX_%1_start]
152 %endif ; %1 == 8/9/10/16
153 movsx cntr_reg, fltsizem
156 mov r6, [srcq+gprsize*cntr_reg-2*gprsize]
159 mova m5, [r6+r5*4+mmsize]
162 %endif ; %1 == 8/9/10/16
163 mov r6, [srcq+gprsize*cntr_reg-gprsize]
166 mova m6, [r6+r5*4+mmsize]
169 %endif ; %1 == 8/9/10/16
172 movd m0, [filterq+2*cntr_reg-4] ; coeff[0], coeff[1]
174 pshuflw m7, m0, 0 ; coeff[0]
175 pshuflw m0, m0, 0x55 ; coeff[1]
176 pmovsxwd m7, m7 ; word -> dword
177 pmovsxwd m0, m0 ; word -> dword
198 %endif ; %1 == 8/9/10/16
201 jg .filterloop_ %+ %%i
209 %endif ; %1 == 8/9/10/16
215 %else ; %1 == 9/10/16
225 %endif ; mmx2/sse2/sse4/avx
226 pminsw m2, [yuv2yuvX_%1_upper]
227 %endif ; %1 == 9/10/16
229 %endif ; %1 == 8/9/10/16
245 %else ; %1 == 9/10/16
247 %endif ; %1 == 8/9/10/16
250 %define PALIGNR PALIGNR_MMX
253 yuv2planeX_fn 8, 0, 7
254 yuv2planeX_fn 9, 0, 5
255 yuv2planeX_fn 10, 0, 5
259 yuv2planeX_fn 8, 10, 7
260 yuv2planeX_fn 9, 7, 5
261 yuv2planeX_fn 10, 7, 5
263 %define PALIGNR PALIGNR_SSSE3
265 yuv2planeX_fn 8, 10, 7
266 yuv2planeX_fn 9, 7, 5
267 yuv2planeX_fn 10, 7, 5
268 yuv2planeX_fn 16, 8, 5
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_MMX 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
412 yuv2plane1_fn 8, 5, 5
413 yuv2plane1_fn 9, 5, 3
414 yuv2plane1_fn 10, 5, 3
415 yuv2plane1_fn 16, 5, 3