1 ;*****************************************************************************
2 ;* predict-a.asm: h264 encoder library
3 ;*****************************************************************************
4 ;* Copyright (C) 2005-2008 x264 project
6 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
8 ;* This program is free software; you can redistribute it and/or modify
9 ;* it under the terms of the GNU General Public License as published by
10 ;* the Free Software Foundation; either version 2 of the License, or
11 ;* (at your option) any later version.
13 ;* This program 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
16 ;* GNU General Public License for more details.
18 ;* You should have received a copy of the GNU General Public License
19 ;* along with this program; if not, write to the Free Software
20 ;* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 ;*****************************************************************************
26 movq [r0 + 0*FDEC_STRIDE], %1
27 movq [r0 + 1*FDEC_STRIDE], %1
28 movq [r0 + 2*FDEC_STRIDE], %1
29 movq [r0 + 3*FDEC_STRIDE], %1
30 movq [r0 + 4*FDEC_STRIDE], %2
31 movq [r0 + 5*FDEC_STRIDE], %2
32 movq [r0 + 6*FDEC_STRIDE], %2
33 movq [r0 + 7*FDEC_STRIDE], %2
39 movq [r0 + 0*FDEC_STRIDE], %1
40 movq [r0 + 1*FDEC_STRIDE], %1
41 movq [r0 + 2*FDEC_STRIDE], %1
42 movq [r0 + 3*FDEC_STRIDE], %1
43 movq [r0 + 0*FDEC_STRIDE + 8], %2
44 movq [r0 + 1*FDEC_STRIDE + 8], %2
45 movq [r0 + 2*FDEC_STRIDE + 8], %2
46 movq [r0 + 3*FDEC_STRIDE + 8], %2
52 %macro STORE16x16_SSE2 1
55 movdqa [r0 + 0*FDEC_STRIDE], %1
56 movdqa [r0 + 1*FDEC_STRIDE], %1
57 movdqa [r0 + 2*FDEC_STRIDE], %1
58 movdqa [r0 + 3*FDEC_STRIDE], %1
72 pw_3210: dw 0, 1, 2, 3, 4, 5, 6, 7
73 pb_00s_ff: times 8 db 0
74 pb_0s_ff: times 7 db 0
79 ; dest, left, right, src, tmp
80 ; output: %1 = (t[n-1] + t[n]*2 + t[n+1] + 2) >> 2
81 %macro PRED8x8_LOWPASS0 6
86 pand %3, [pb_1 GLOBAL]
90 %macro PRED8x8_LOWPASS 5
91 PRED8x8_LOWPASS0 %1, %2, %3, %4, %5, q
93 %macro PRED8x8_LOWPASS_XMM 5
94 PRED8x8_LOWPASS0 %1, %2, %3, %4, %5, dqa
98 ;-----------------------------------------------------------------------------
99 ; void predict_4x4_ddl_mmxext( uint8_t *src )
100 ;-----------------------------------------------------------------------------
101 cglobal predict_4x4_ddl_mmxext, 1,1,1
106 movq mm4, [pb_0s_ff GLOBAL]
111 PRED8x8_LOWPASS mm0, mm1, mm2, mm3, mm5
116 movd [r0+Y*FDEC_STRIDE], mm0
122 ;-----------------------------------------------------------------------------
123 ; void predict_4x4_vl_mmxext( uint8_t *src )
124 ;-----------------------------------------------------------------------------
125 cglobal predict_4x4_vl_mmxext, 1,1,1
126 movq mm1, [r0-FDEC_STRIDE]
134 PRED8x8_LOWPASS mm0, mm1, mm2, mm3, mm5
136 movd [r0+0*FDEC_STRIDE], mm4
137 movd [r0+1*FDEC_STRIDE], mm0
140 movd [r0+2*FDEC_STRIDE], mm4
141 movd [r0+3*FDEC_STRIDE], mm0
145 ;-----------------------------------------------------------------------------
146 ; void predict_8x8_v_mmxext( uint8_t *src, uint8_t *edge )
147 ;-----------------------------------------------------------------------------
148 cglobal predict_8x8_v_mmxext, 2,2
153 ;-----------------------------------------------------------------------------
154 ; void predict_8x8_dc_mmxext( uint8_t *src, uint8_t *edge );
155 ;-----------------------------------------------------------------------------
156 cglobal predict_8x8_dc_mmxext, 2,2,1
161 paddw mm0, [pw_8 GLOBAL]
169 ;-----------------------------------------------------------------------------
170 ; void predict_8x8_dc_top_mmxext( uint8_t *src, uint8_t *edge );
171 ;-----------------------------------------------------------------------------
176 paddw mm0, [pw_4 GLOBAL]
184 PRED8x8_DC predict_8x8_dc_top_mmxext, 16
185 PRED8x8_DC predict_8x8_dc_left_mmxext, 7
188 ; sse2 is faster even on amd, so there's no sense in spending exe size on these
189 ; functions if we know sse2 is available.
191 ;-----------------------------------------------------------------------------
192 ; void predict_8x8_ddl_mmxext( uint8_t *src, uint8_t *edge )
193 ;-----------------------------------------------------------------------------
194 cglobal predict_8x8_ddl_mmxext, 2,2,1
201 PRED8x8_LOWPASS mm0, mm1, mm2, mm5, mm7
202 PRED8x8_LOWPASS mm1, mm3, mm4, [r1+24], mm6
206 movq [r0+Y*FDEC_STRIDE], mm1
214 movq [r0+Y*FDEC_STRIDE], mm1
219 movq [r0+Y*FDEC_STRIDE], mm1
222 ;-----------------------------------------------------------------------------
223 ; void predict_8x8_ddr_mmxext( uint8_t *src, uint8_t *edge )
224 ;-----------------------------------------------------------------------------
225 cglobal predict_8x8_ddr_mmxext, 2,2,1
230 PRED8x8_LOWPASS mm0, mm1, mm2, [r1+8], mm7
231 PRED8x8_LOWPASS mm1, mm3, mm4, [r1+16], mm6
235 movq [r0+Y*FDEC_STRIDE], mm0
243 movq [r0+Y*FDEC_STRIDE], mm0
248 movq [r0+Y*FDEC_STRIDE], mm0
251 %endif ; !ARCH_X86_64
253 ;-----------------------------------------------------------------------------
254 ; void predict_8x8_ddl_sse2( uint8_t *src, uint8_t *edge )
255 ;-----------------------------------------------------------------------------
256 cglobal predict_8x8_ddl_sse2, 2,2,1
261 PRED8x8_LOWPASS_XMM xmm0, xmm1, xmm2, xmm3, xmm4
266 movq [r0+Y*FDEC_STRIDE], xmm0
271 ;-----------------------------------------------------------------------------
272 ; void predict_8x8_ddr_sse2( uint8_t *src, uint8_t *edge )
273 ;-----------------------------------------------------------------------------
274 cglobal predict_8x8_ddr_sse2, 2,2,1
279 PRED8x8_LOWPASS_XMM xmm0, xmm1, xmm2, xmm3, xmm4
285 movq [r0+Y*FDEC_STRIDE], xmm0
286 movq [r0+(Y-1)*FDEC_STRIDE], xmm1
291 movq [r0+1*FDEC_STRIDE], xmm0
292 movq [r0+0*FDEC_STRIDE], xmm1
296 ;-----------------------------------------------------------------------------
297 ; void predict_8x8_vl_sse2( uint8_t *src, uint8_t *edge )
298 ;-----------------------------------------------------------------------------
299 cglobal predict_8x8_vl_sse2, 2,2,1
307 PRED8x8_LOWPASS_XMM xmm0, xmm1, xmm2, xmm4, xmm5
308 ; xmm0: (t0 + 2*t1 + t2 + 2) >> 2
309 ; xmm3: (t0 + t1 + 1) >> 1
314 movq [r0+ Y *FDEC_STRIDE], xmm3
315 movq [r0+(Y+1)*FDEC_STRIDE], xmm0
320 movq [r0+ Y *FDEC_STRIDE], xmm3
321 movq [r0+(Y+1)*FDEC_STRIDE], xmm0
325 ;-----------------------------------------------------------------------------
326 ; void predict_8x8_vr_core_mmxext( uint8_t *src, uint8_t *edge )
327 ;-----------------------------------------------------------------------------
329 ; fills only some pixels:
340 cglobal predict_8x8_vr_core_mmxext, 2,2,1
346 PRED8x8_LOWPASS mm0, mm1, mm2, mm4, mm7
350 movq [r0+ Y *FDEC_STRIDE], mm3
351 movq [r0+(Y+1)*FDEC_STRIDE], mm0
356 movq [r0+ Y *FDEC_STRIDE], mm3
357 movq [r0+(Y+1)*FDEC_STRIDE], mm0
361 ;-----------------------------------------------------------------------------
362 ; void predict_8x8c_v_mmx( uint8_t *src )
363 ;-----------------------------------------------------------------------------
364 cglobal predict_8x8c_v_mmx, 1,1
365 movq mm0, [r0 - FDEC_STRIDE]
369 ;-----------------------------------------------------------------------------
370 ; void predict_8x8c_dc_core_mmxext( uint8_t *src, int s2, int s3 )
371 ;-----------------------------------------------------------------------------
372 cglobal predict_8x8c_dc_core_mmxext, 1,1,1
373 movq mm0, [r0 - FDEC_STRIDE]
391 paddw mm1, [pw_2 GLOBAL]
394 pshufw mm0, mm0, 0 ; dc0 (w)
396 psrlw mm3, 3 ; dc3 (w)
397 psrlw mm2, 2 ; dc2 (w)
398 psrlw mm1, 2 ; dc1 (w)
400 packuswb mm0, mm1 ; dc0,dc1 (b)
401 packuswb mm2, mm3 ; dc2,dc3 (b)
406 %macro LOAD_PLANE_ARGS 0
421 ;-----------------------------------------------------------------------------
422 ; void predict_8x8c_p_core_mmxext( uint8_t *src, int i00, int b, int c )
423 ;-----------------------------------------------------------------------------
424 cglobal predict_8x8c_p_core_mmxext, 1,2,1
427 pmullw mm2, [pw_3210 GLOBAL]
429 paddsw mm0, mm2 ; mm0 = {i+0*b, i+1*b, i+2*b, i+3*b}
430 paddsw mm1, mm0 ; mm1 = {i+4*b, i+5*b, i+6*b, i+7*b}
449 ;-----------------------------------------------------------------------------
450 ; void predict_16x16_p_core_mmxext( uint8_t *src, int i00, int b, int c )
451 ;-----------------------------------------------------------------------------
452 cglobal predict_16x16_p_core_mmxext, 1,2,1
456 pmullw mm5, [pw_3210 GLOBAL]
460 paddsw mm0, mm5 ; mm0 = {i+ 0*b, i+ 1*b, i+ 2*b, i+ 3*b}
461 paddsw mm1, mm0 ; mm1 = {i+ 4*b, i+ 5*b, i+ 6*b, i+ 7*b}
462 paddsw mm2, mm0 ; mm2 = {i+ 8*b, i+ 9*b, i+10*b, i+11*b}
463 paddsw mm3, mm1 ; mm3 = {i+12*b, i+13*b, i+14*b, i+15*b}
491 ;-----------------------------------------------------------------------------
492 ; void predict_16x16_p_core_sse2( uint8_t *src, int i00, int b, int c )
493 ;-----------------------------------------------------------------------------
494 cglobal predict_16x16_p_core_sse2, 1,2,1
498 pshuflw xmm0, xmm0, 0
499 pshuflw xmm1, xmm1, 0
500 pshuflw xmm2, xmm2, 0
501 punpcklqdq xmm0, xmm0
502 punpcklqdq xmm1, xmm1
503 punpcklqdq xmm2, xmm2
505 pmullw xmm3, [pw_76543210 GLOBAL]
507 paddsw xmm0, xmm3 ; xmm0 = {i+ 0*b, i+ 1*b, i+ 2*b, i+ 3*b, i+ 4*b, i+ 5*b, i+ 6*b, i+ 7*b}
508 paddsw xmm1, xmm0 ; xmm1 = {i+ 8*b, i+ 9*b, i+10*b, i+11*b, i+12*b, i+13*b, i+14*b, i+15*b}
527 ;-----------------------------------------------------------------------------
528 ; void predict_16x16_v_mmx( uint8_t *src )
529 ;-----------------------------------------------------------------------------
530 cglobal predict_16x16_v_mmx, 1,2
531 movq mm0, [r0 - FDEC_STRIDE]
532 movq mm1, [r0 - FDEC_STRIDE + 8]
536 ;-----------------------------------------------------------------------------
537 ; void predict_16x16_v_sse2( uint8_t *src )
538 ;-----------------------------------------------------------------------------
539 cglobal predict_16x16_v_sse2, 1,2
540 movdqa xmm0, [r0 - FDEC_STRIDE]
544 ;-----------------------------------------------------------------------------
545 ; void predict_16x16_dc_core_mmxext( uint8_t *src, int i_dc_left )
546 ;-----------------------------------------------------------------------------
548 %macro PRED16x16_DC 2
551 psadbw mm0, [r0 - FDEC_STRIDE]
552 psadbw mm1, [r0 - FDEC_STRIDE + 8]
557 packuswb mm0, mm0 ; dc in bytes
561 cglobal predict_16x16_dc_core_mmxext, 1,2
570 cglobal predict_16x16_dc_top_mmxext, 1,2,1
571 PRED16x16_DC [pw_8 GLOBAL], 4
574 ;-----------------------------------------------------------------------------
575 ; void predict_16x16_dc_core_sse2( uint8_t *src, int i_dc_left )
576 ;-----------------------------------------------------------------------------
578 %macro PRED16x16_DC_SSE2 2
580 psadbw xmm0, [r0 - FDEC_STRIDE]
585 pshuflw xmm0, xmm0, 0
586 punpcklqdq xmm0, xmm0
587 packuswb xmm0, xmm0 ; dc in bytes
591 cglobal predict_16x16_dc_core_sse2, 1,2
593 PRED16x16_DC_SSE2 xmm2, 5
596 cglobal predict_16x16_dc_top_sse2, 1,2,1
597 PRED16x16_DC_SSE2 [pw_8 GLOBAL], 4