1 ;******************************************************************************
2 ;* MMX/SSE2-optimized functions for the RV40 decoder
3 ;* Copyright (c) 2010 Ronald S. Bultje <rsbultje@gmail.com>
4 ;* Copyright (c) 2010 Jason Garrett-Glaser <darkshikari@gmail.com>
5 ;* Copyright (C) 2012 Christophe Gisquet <christophe.gisquet@gmail.com>
7 ;* This file is part of Libav.
9 ;* Libav is free software; you can redistribute it and/or
10 ;* modify it under the terms of the GNU Lesser General Public
11 ;* License as published by the Free Software Foundation; either
12 ;* version 2.1 of the License, or (at your option) any later version.
14 ;* Libav is distributed in the hope that it will be useful,
15 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;* Lesser General Public License for more details.
19 ;* You should have received a copy of the GNU Lesser General Public
20 ;* License along with Libav; if not, write to the Free Software
21 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 ;******************************************************************************
25 %include "x86util.asm"
30 pw_1024: times 8 dw 1 << (16 - 6) ; pw_1024
32 sixtap_filter_hb_m: times 8 db 1, -5
34 ; multiplied by 2 to have the same shift
41 sixtap_filter_v_m: times 8 dw 1
45 ; multiplied by 2 to have the same shift
57 %define sixtap_filter_hw picregq
58 %define sixtap_filter_hb picregq
59 %define sixtap_filter_v picregq
62 %define sixtap_filter_hw sixtap_filter_hw_m
63 %define sixtap_filter_hb sixtap_filter_hb_m
64 %define sixtap_filter_v sixtap_filter_v_m
68 filter_h6_shuf1: db 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8
69 filter_h6_shuf2: db 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10
70 filter_h6_shuf3: db 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11
78 ;-----------------------------------------------------------------------------
79 ; subpel MC functions:
81 ; void [put|rv40]_rv40_qpel_[h|v]_<opt>(uint8_t *dst, int deststride,
82 ; uint8_t *src, int srcstride,
84 ;----------------------------------------------------------------------
112 cglobal %1_rv40_qpel_v, 6,6+npicregs,12, dst, dststride, src, srcstride, height, my, picreg
114 lea picregq, [sixtap_filter_v_m]
117 LOAD my, sixtap_filter_v
123 movh m1, [srcq+srcstrideq]
124 movh m2, [srcq+srcstrideq*2]
125 lea srcq, [srcq+srcstrideq*2]
128 movh m4, [srcq+srcstrideq]
145 %define COEFF05 [myq+ 0]
146 %define COEFF14 [myq+16]
147 %define COEFF2 [myq+32]
148 %define COEFF3 [myq+48]
152 movh m5, [srcq+2*srcstrideq] ; read new row
177 dec heightd ; next row
183 cglobal %1_rv40_qpel_h, 6, 6+npicregs, 12, dst, dststride, src, srcstride, height, mx, picreg
185 lea picregq, [sixtap_filter_v_m]
188 LOAD mx, sixtap_filter_v
200 %define COEFF05 [mxq+ 0]
201 %define COEFF14 [mxq+16]
202 %define COEFF2 [mxq+32]
203 %define COEFF3 [mxq+48]
234 dec heightd ; next row
259 %macro FILTER_SSSE3 1
260 cglobal %1_rv40_qpel_v, 6,6+npicregs,8, dst, dststride, src, srcstride, height, my, picreg
262 lea picregq, [sixtap_filter_hb_m]
267 LOAD my, sixtap_filter_hb
270 movh m1, [srcq+srcstrideq]
271 movh m2, [srcq+srcstrideq*2]
272 lea srcq, [srcq+srcstrideq*2]
276 movh m4, [srcq+srcstrideq]
277 lea srcq, [srcq+2*srcstrideq]
284 pmaddubsw m6, [myq+16]
285 movh m7, [srcq] ; read new row
295 pmulhrsw m6, [pw_512]
301 dec heightd ; next row
305 cglobal %1_rv40_qpel_h, 6,6+npicregs,8, dst, dststride, src, srcstride, height, mx, picreg
307 lea picregq, [sixtap_filter_hb_m]
309 mova m3, [filter_h6_shuf2]
310 mova m4, [filter_h6_shuf3]
311 LOAD mx, sixtap_filter_hb
312 mova m5, [mxq] ; set up 6tap filter in bytes
314 mova m7, [filter_h6_shuf1]
328 pmulhrsw m0, [pw_512]
334 dec heightd ; next row
343 ; %1=5bits weights?, %2=dst %3=src1 %4=src3 %5=stride if sse2
344 %macro RV40_WCORE 4-5
345 movh m4, [%3 + r6 + 0]
346 movh m5, [%4 + r6 + 0]
348 %define OFFSET r6 + mmsize / 2
350 ; 8x8 block and sse2, stride was provided
354 movh m6, [%3 + OFFSET]
355 movh m7, [%4 + OFFSET]
399 ; bias and shift down
412 ; Only called for 8x8 blocks and sse2
425 RV40_WCORE %2, r0, r1, r2
427 RV40_WCORE %2, r0 + 8, r1 + 8, r2 + 8
430 ; Prepare for next loop
434 RV40_WCORE %2, r0, r1, r2, r5
435 ; Prepare 2 next lines
438 RV40_WCORE %2, r0, r1, r2
439 ; Prepare single next line
446 ; rv40_weight_func_%1(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w1, int w2, int stride)
447 ; %1=size %2=num of xmm regs
448 ; The weights are FP0.14 notation of fractions depending on pts.
449 ; For timebases without rounding error (i.e. PAL), the fractions
450 ; can be simplified, and several operations can be avoided.
451 ; Therefore, we check here whether they are multiples of 2^9 for
452 ; those simplifications to occur.
454 cglobal rv40_weight_func_%1_%2, 6, 7, 8
461 ; Set loop counter and increments
491 RV40_WEIGHT rnd, 8, 3
492 RV40_WEIGHT rnd, 16, 4
493 RV40_WEIGHT nornd, 8, 3
494 RV40_WEIGHT nornd, 16, 4
497 RV40_WEIGHT rnd, 8, 3
498 RV40_WEIGHT rnd, 16, 4
499 RV40_WEIGHT nornd, 8, 3
500 RV40_WEIGHT nornd, 16, 4
503 RV40_WEIGHT rnd, 8, 3
504 RV40_WEIGHT rnd, 16, 4
505 RV40_WEIGHT nornd, 8, 3
506 RV40_WEIGHT nornd, 16, 4