1 ;******************************************************************************
2 ;* VP8 MMXEXT optimizations
3 ;* Copyright (c) 2010 Ronald S. Bultje <rsbultje@gmail.com>
4 ;* Copyright (c) 2010 Jason Garrett-Glaser <darkshikari@gmail.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 fourtap_filter_hw_m: times 4 dw -6, 123
36 sixtap_filter_hw_m: times 4 dw 2, -11
46 fourtap_filter_hb_m: times 8 db -6, 123
55 sixtap_filter_hb_m: times 8 db 2, 1
65 fourtap_filter_v_m: times 8 dw -6
82 sixtap_filter_v_m: times 8 dw 2
101 bilinear_filter_vw_m: times 8 dw 1
109 bilinear_filter_vb_m: times 8 db 7, 1
118 %define fourtap_filter_hw picregq
119 %define sixtap_filter_hw picregq
120 %define fourtap_filter_hb picregq
121 %define sixtap_filter_hb picregq
122 %define fourtap_filter_v picregq
123 %define sixtap_filter_v picregq
124 %define bilinear_filter_vw picregq
125 %define bilinear_filter_vb picregq
128 %define fourtap_filter_hw fourtap_filter_hw_m
129 %define sixtap_filter_hw sixtap_filter_hw_m
130 %define fourtap_filter_hb fourtap_filter_hb_m
131 %define sixtap_filter_hb sixtap_filter_hb_m
132 %define fourtap_filter_v fourtap_filter_v_m
133 %define sixtap_filter_v sixtap_filter_v_m
134 %define bilinear_filter_vw bilinear_filter_vw_m
135 %define bilinear_filter_vb bilinear_filter_vb_m
139 filter_h2_shuf: db 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8
140 filter_h4_shuf: db 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10
142 filter_h6_shuf1: db 0, 5, 1, 6, 2, 7, 3, 8, 4, 9, 5, 10, 6, 11, 7, 12
143 filter_h6_shuf2: db 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9
144 filter_h6_shuf3: db 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11
148 pw_256: times 8 dw 256
149 pw_20091: times 4 dw 20091
150 pw_17734: times 4 dw 17734
153 pb_F8: times 16 db 0xF8
154 pb_FE: times 16 db 0xFE
155 pb_27_63: times 8 db 27, 63
156 pb_18_63: times 8 db 18, 63
157 pb_9_63: times 8 db 9, 63
170 ;-----------------------------------------------------------------------------
171 ; subpel MC functions:
173 ; void put_vp8_epel<size>_h<htap>v<vtap>_<opt>(uint8_t *dst, int deststride,
174 ; uint8_t *src, int srcstride,
175 ; int height, int mx, int my);
176 ;-----------------------------------------------------------------------------
178 %macro FILTER_SSSE3 1
179 cglobal put_vp8_epel%1_h6, 6, 6 + npicregs, 8, dst, dststride, src, srcstride, height, mx, picreg
181 mova m3, [filter_h6_shuf2]
182 mova m4, [filter_h6_shuf3]
184 lea picregq, [sixtap_filter_hb_m]
186 mova m5, [sixtap_filter_hb+mxq*8-48] ; set up 6tap filter in bytes
187 mova m6, [sixtap_filter_hb+mxq*8-32]
188 mova m7, [sixtap_filter_hb+mxq*8-16]
195 ; For epel4, we need 9 bytes, but only 8 get loaded; to compensate, do the
196 ; shuffle with a memory operand
197 punpcklbw m0, [srcq+3]
199 pshufb m0, [filter_h6_shuf1]
208 pmulhrsw m0, [pw_256]
210 movh [dstq], m0 ; store
215 dec heightd ; next row
219 cglobal put_vp8_epel%1_h4, 6, 6 + npicregs, 7, dst, dststride, src, srcstride, height, mx, picreg
222 mova m3, [filter_h2_shuf]
223 mova m4, [filter_h4_shuf]
225 lea picregq, [fourtap_filter_hb_m]
227 mova m5, [fourtap_filter_hb+mxq-16] ; set up 4tap filter in bytes
228 mova m6, [fourtap_filter_hb+mxq]
240 movh [dstq], m0 ; store
245 dec heightd ; next row
249 cglobal put_vp8_epel%1_v4, 7, 7, 8, dst, dststride, src, srcstride, height, picreg, my
252 lea picregq, [fourtap_filter_hb_m]
254 mova m5, [fourtap_filter_hb+myq-16]
255 mova m6, [fourtap_filter_hb+myq]
261 movh m1, [srcq+ srcstrideq]
262 movh m2, [srcq+2*srcstrideq]
266 movh m3, [srcq+2*srcstrideq] ; read new row
283 dec heightd ; next row
287 cglobal put_vp8_epel%1_v6, 7, 7, 8, dst, dststride, src, srcstride, height, picreg, my
290 lea picregq, [sixtap_filter_hb_m]
292 lea myq, [sixtap_filter_hb+myq*8]
298 movh m1, [srcq+srcstrideq]
299 movh m2, [srcq+srcstrideq*2]
300 lea srcq, [srcq+srcstrideq*2]
303 movh m4, [srcq+srcstrideq]
306 movh m5, [srcq+2*srcstrideq] ; read new row
313 pmaddubsw m6, [myq-48]
314 pmaddubsw m1, [myq-32]
315 pmaddubsw m7, [myq-16]
320 pmulhrsw m6, [pw_256]
329 dec heightd ; next row
339 ; 4x4 block, H-only 4-tap filter
341 cglobal put_vp8_epel4_h4, 6, 6 + npicregs, 0, dst, dststride, src, srcstride, height, mx, picreg
344 lea picregq, [fourtap_filter_hw_m]
346 movq mm4, [fourtap_filter_hw+mxq-16] ; set up 4tap filter in words
347 movq mm5, [fourtap_filter_hw+mxq]
352 movq mm1, [srcq-1] ; (ABCDEFGH) load 8 horizontal pixels
354 ; first set of 2 pixels
355 movq mm2, mm1 ; byte ABCD..
356 punpcklbw mm1, mm6 ; byte->word ABCD
357 pshufw mm0, mm2, 9 ; byte CDEF..
358 punpcklbw mm0, mm6 ; byte->word CDEF
359 pshufw mm3, mm1, 0x94 ; word ABBC
360 pshufw mm1, mm0, 0x94 ; word CDDE
361 pmaddwd mm3, mm4 ; multiply 2px with F0/F1
362 movq mm0, mm1 ; backup for second set of pixels
363 pmaddwd mm1, mm5 ; multiply 2px with F2/F3
364 paddd mm3, mm1 ; finish 1st 2px
366 ; second set of 2 pixels, use backup of above
367 punpckhbw mm2, mm6 ; byte->word EFGH
368 pmaddwd mm0, mm4 ; multiply backed up 2px with F0/F1
369 pshufw mm1, mm2, 0x94 ; word EFFG
370 pmaddwd mm1, mm5 ; multiply 2px with F2/F3
371 paddd mm0, mm1 ; finish 2nd 2px
373 ; merge two sets of 2 pixels into one set of 4, round/clip/store
374 packssdw mm3, mm0 ; merge dword->word (4px)
375 paddsw mm3, mm7 ; rounding
377 packuswb mm3, mm6 ; clip and word->bytes
378 movd [dstq], mm3 ; store
383 dec heightd ; next row
387 ; 4x4 block, H-only 6-tap filter
389 cglobal put_vp8_epel4_h6, 6, 6 + npicregs, 0, dst, dststride, src, srcstride, height, mx, picreg
392 lea picregq, [sixtap_filter_hw_m]
394 movq mm4, [sixtap_filter_hw+mxq*8-48] ; set up 4tap filter in words
395 movq mm5, [sixtap_filter_hw+mxq*8-32]
396 movq mm6, [sixtap_filter_hw+mxq*8-16]
401 movq mm1, [srcq-2] ; (ABCDEFGH) load 8 horizontal pixels
403 ; first set of 2 pixels
404 movq mm2, mm1 ; byte ABCD..
405 punpcklbw mm1, mm3 ; byte->word ABCD
406 pshufw mm0, mm2, 0x9 ; byte CDEF..
407 punpckhbw mm2, mm3 ; byte->word EFGH
408 punpcklbw mm0, mm3 ; byte->word CDEF
409 pshufw mm1, mm1, 0x94 ; word ABBC
410 pshufw mm2, mm2, 0x94 ; word EFFG
411 pmaddwd mm1, mm4 ; multiply 2px with F0/F1
412 pshufw mm3, mm0, 0x94 ; word CDDE
413 movq mm0, mm3 ; backup for second set of pixels
414 pmaddwd mm3, mm5 ; multiply 2px with F2/F3
415 paddd mm1, mm3 ; add to 1st 2px cache
416 movq mm3, mm2 ; backup for second set of pixels
417 pmaddwd mm2, mm6 ; multiply 2px with F4/F5
418 paddd mm1, mm2 ; finish 1st 2px
420 ; second set of 2 pixels, use backup of above
421 movd mm2, [srcq+3] ; byte FGHI (prevent overreads)
422 pmaddwd mm0, mm4 ; multiply 1st backed up 2px with F0/F1
423 pmaddwd mm3, mm5 ; multiply 2nd backed up 2px with F2/F3
424 paddd mm0, mm3 ; add to 2nd 2px cache
426 punpcklbw mm2, mm3 ; byte->word FGHI
427 pshufw mm2, mm2, 0xE9 ; word GHHI
428 pmaddwd mm2, mm6 ; multiply 2px with F4/F5
429 paddd mm0, mm2 ; finish 2nd 2px
431 ; merge two sets of 2 pixels into one set of 4, round/clip/store
432 packssdw mm1, mm0 ; merge dword->word (4px)
433 paddsw mm1, mm7 ; rounding
435 packuswb mm1, mm3 ; clip and word->bytes
436 movd [dstq], mm1 ; store
441 dec heightd ; next row
446 cglobal put_vp8_epel8_h4, 6, 6 + npicregs, 10, dst, dststride, src, srcstride, height, mx, picreg
449 lea picregq, [fourtap_filter_v_m]
451 lea mxq, [fourtap_filter_v+mxq-32]
484 movh [dstq], m0 ; store
489 dec heightd ; next row
494 cglobal put_vp8_epel8_h6, 6, 6 + npicregs, 14, dst, dststride, src, srcstride, height, mx, picreg
498 lea picregq, [sixtap_filter_v_m]
500 lea mxq, [sixtap_filter_v+mxq-96]
547 movh [dstq], m0 ; store
552 dec heightd ; next row
557 ; 4x4 block, V-only 4-tap filter
558 cglobal put_vp8_epel%1_v4, 7, 7, 8, dst, dststride, src, srcstride, height, picreg, my
561 lea picregq, [fourtap_filter_v_m]
563 lea myq, [fourtap_filter_v+myq-32]
571 movh m1, [srcq+ srcstrideq]
572 movh m2, [srcq+2*srcstrideq]
579 ; first calculate negative taps (to prevent losing positive overflows)
580 movh m4, [srcq+2*srcstrideq] ; read new row
587 ; then calculate positive taps
605 dec heightd ; next row
610 ; 4x4 block, V-only 6-tap filter
611 cglobal put_vp8_epel%1_v6, 7, 7, 8, dst, dststride, src, srcstride, height, picreg, my
615 lea picregq, [sixtap_filter_v_m]
617 lea myq, [sixtap_filter_v+myq-96]
624 movh m1, [srcq+srcstrideq]
625 movh m2, [srcq+srcstrideq*2]
626 lea srcq, [srcq+srcstrideq*2]
629 movh m4, [srcq+srcstrideq]
637 ; first calculate negative taps (to prevent losing positive overflows)
644 ; then calculate positive taps
645 movh m5, [srcq+2*srcstrideq] ; read new row
670 dec heightd ; next row
680 %macro FILTER_BILINEAR 1
681 cglobal put_vp8_bilinear%1_v, 7, 7, 7, dst, dststride, src, srcstride, height, picreg, my
684 lea picregq, [bilinear_filter_vw_m]
687 mova m5, [bilinear_filter_vw+myq-1*16]
689 mova m4, [bilinear_filter_vw+myq+7*16]
691 movh m0, [srcq+srcstrideq*0]
692 movh m1, [srcq+srcstrideq*1]
693 movh m3, [srcq+srcstrideq*2]
711 movh [dstq+dststrideq*0], m0
712 movh [dstq+dststrideq*1], m2
715 movh [dstq+dststrideq*0], m0
716 movhps [dstq+dststrideq*1], m0
719 lea dstq, [dstq+dststrideq*2]
720 lea srcq, [srcq+srcstrideq*2]
725 cglobal put_vp8_bilinear%1_h, 6, 6 + npicregs, 7, dst, dststride, src, srcstride, height, mx, picreg
728 lea picregq, [bilinear_filter_vw_m]
731 mova m5, [bilinear_filter_vw+mxq-1*16]
733 mova m4, [bilinear_filter_vw+mxq+7*16]
735 movh m0, [srcq+srcstrideq*0+0]
736 movh m1, [srcq+srcstrideq*0+1]
737 movh m2, [srcq+srcstrideq*1+0]
738 movh m3, [srcq+srcstrideq*1+1]
756 movh [dstq+dststrideq*0], m0
757 movh [dstq+dststrideq*1], m2
760 movh [dstq+dststrideq*0], m0
761 movhps [dstq+dststrideq*1], m0
764 lea dstq, [dstq+dststrideq*2]
765 lea srcq, [srcq+srcstrideq*2]
776 %macro FILTER_BILINEAR_SSSE3 1
777 cglobal put_vp8_bilinear%1_v, 7, 7, 5, dst, dststride, src, srcstride, height, picreg, my
780 lea picregq, [bilinear_filter_vb_m]
783 mova m3, [bilinear_filter_vb+myq-16]
785 movh m0, [srcq+srcstrideq*0]
786 movh m1, [srcq+srcstrideq*1]
787 movh m2, [srcq+srcstrideq*2]
799 movh [dstq+dststrideq*0], m0
800 movh [dstq+dststrideq*1], m1
803 movh [dstq+dststrideq*0], m0
804 movhps [dstq+dststrideq*1], m0
807 lea dstq, [dstq+dststrideq*2]
808 lea srcq, [srcq+srcstrideq*2]
813 cglobal put_vp8_bilinear%1_h, 6, 6 + npicregs, 5, dst, dststride, src, srcstride, height, mx, picreg
816 lea picregq, [bilinear_filter_vb_m]
819 mova m2, [filter_h2_shuf]
820 mova m3, [bilinear_filter_vb+mxq-16]
822 movu m0, [srcq+srcstrideq*0]
823 movu m1, [srcq+srcstrideq*1]
835 movh [dstq+dststrideq*0], m0
836 movh [dstq+dststrideq*1], m1
839 movh [dstq+dststrideq*0], m0
840 movhps [dstq+dststrideq*1], m0
843 lea dstq, [dstq+dststrideq*2]
844 lea srcq, [srcq+srcstrideq*2]
851 FILTER_BILINEAR_SSSE3 4
853 FILTER_BILINEAR_SSSE3 8
856 cglobal put_vp8_pixels8, 5, 5, 0, dst, dststride, src, srcstride, height
858 movq mm0, [srcq+srcstrideq*0]
859 movq mm1, [srcq+srcstrideq*1]
860 lea srcq, [srcq+srcstrideq*2]
861 movq [dstq+dststrideq*0], mm0
862 movq [dstq+dststrideq*1], mm1
863 lea dstq, [dstq+dststrideq*2]
870 cglobal put_vp8_pixels16, 5, 5, 0, dst, dststride, src, srcstride, height
872 movq mm0, [srcq+srcstrideq*0+0]
873 movq mm1, [srcq+srcstrideq*0+8]
874 movq mm2, [srcq+srcstrideq*1+0]
875 movq mm3, [srcq+srcstrideq*1+8]
876 lea srcq, [srcq+srcstrideq*2]
877 movq [dstq+dststrideq*0+0], mm0
878 movq [dstq+dststrideq*0+8], mm1
879 movq [dstq+dststrideq*1+0], mm2
880 movq [dstq+dststrideq*1+8], mm3
881 lea dstq, [dstq+dststrideq*2]
888 cglobal put_vp8_pixels16, 5, 5, 2, dst, dststride, src, srcstride, height
890 movups xmm0, [srcq+srcstrideq*0]
891 movups xmm1, [srcq+srcstrideq*1]
892 lea srcq, [srcq+srcstrideq*2]
893 movaps [dstq+dststrideq*0], xmm0
894 movaps [dstq+dststrideq*1], xmm1
895 lea dstq, [dstq+dststrideq*2]
900 ;-----------------------------------------------------------------------------
901 ; void vp8_idct_dc_add_<opt>(uint8_t *dst, int16_t block[16], int stride);
902 ;-----------------------------------------------------------------------------
906 %4 m3, [dst1q+strideq+%3]
908 %4 m5, [dst2q+strideq+%3]
918 %4 [dst1q+strideq+%3], m3
920 %4 [dst2q+strideq+%3], m5
924 cglobal vp8_idct_dc_add, 3, 3, 0, dst, block, stride
942 DEFINE_ARGS dst1, dst2, stride
943 lea dst2q, [dst1q+strideq*2]
944 ADD_DC m0, m1, 0, movh
948 cglobal vp8_idct_dc_add, 3, 3, 6, dst, block, stride
956 DEFINE_ARGS dst1, dst2, stride
957 lea dst2q, [dst1q+strideq*2]
959 movd m3, [dst1q+strideq]
961 movd m5, [dst2q+strideq]
973 pextrd [dst1q+strideq], m2, 1
974 pextrd [dst2q], m2, 2
975 pextrd [dst2q+strideq], m2, 3
978 ;-----------------------------------------------------------------------------
979 ; void vp8_idct_dc_add4y_<opt>(uint8_t *dst, int16_t block[4][16], int stride);
980 ;-----------------------------------------------------------------------------
984 cglobal vp8_idct_dc_add4y, 3, 3, 0, dst, block, stride
986 movd m0, [blockq+32*0] ; A
987 movd m1, [blockq+32*2] ; C
988 punpcklwd m0, [blockq+32*1] ; A B
989 punpcklwd m1, [blockq+32*3] ; C D
990 punpckldq m0, m1 ; A B C D
995 movd [blockq+32*0], m6
996 movd [blockq+32*1], m6
997 movd [blockq+32*2], m6
998 movd [blockq+32*3], m6
1003 punpcklbw m0, m0 ; AABBCCDD
1004 punpcklbw m6, m6 ; AABBCCDD
1007 punpcklbw m0, m0 ; AAAABBBB
1008 punpckhbw m1, m1 ; CCCCDDDD
1009 punpcklbw m6, m6 ; AAAABBBB
1010 punpckhbw m7, m7 ; CCCCDDDD
1013 DEFINE_ARGS dst1, dst2, stride
1014 lea dst2q, [dst1q+strideq*2]
1015 ADD_DC m0, m6, 0, mova
1016 ADD_DC m1, m7, 8, mova
1021 cglobal vp8_idct_dc_add4y, 3, 3, 6, dst, block, stride
1023 movd m0, [blockq+32*0] ; A
1024 movd m1, [blockq+32*2] ; C
1025 punpcklwd m0, [blockq+32*1] ; A B
1026 punpcklwd m1, [blockq+32*3] ; C D
1027 punpckldq m0, m1 ; A B C D
1032 movd [blockq+32*0], m1
1033 movd [blockq+32*1], m1
1034 movd [blockq+32*2], m1
1035 movd [blockq+32*3], m1
1046 DEFINE_ARGS dst1, dst2, stride
1047 lea dst2q, [dst1q+strideq*2]
1048 ADD_DC m0, m1, 0, mova
1051 ;-----------------------------------------------------------------------------
1052 ; void vp8_idct_dc_add4uv_<opt>(uint8_t *dst, int16_t block[4][16], int stride);
1053 ;-----------------------------------------------------------------------------
1056 cglobal vp8_idct_dc_add4uv, 3, 3, 0, dst, block, stride
1058 movd m0, [blockq+32*0] ; A
1059 movd m1, [blockq+32*2] ; C
1060 punpcklwd m0, [blockq+32*1] ; A B
1061 punpcklwd m1, [blockq+32*3] ; C D
1062 punpckldq m0, m1 ; A B C D
1067 movd [blockq+32*0], m6
1068 movd [blockq+32*1], m6
1069 movd [blockq+32*2], m6
1070 movd [blockq+32*3], m6
1075 punpcklbw m0, m0 ; AABBCCDD
1076 punpcklbw m6, m6 ; AABBCCDD
1079 punpcklbw m0, m0 ; AAAABBBB
1080 punpckhbw m1, m1 ; CCCCDDDD
1081 punpcklbw m6, m6 ; AAAABBBB
1082 punpckhbw m7, m7 ; CCCCDDDD
1085 DEFINE_ARGS dst1, dst2, stride
1086 lea dst2q, [dst1q+strideq*2]
1087 ADD_DC m0, m6, 0, mova
1088 lea dst1q, [dst1q+strideq*4]
1089 lea dst2q, [dst2q+strideq*4]
1090 ADD_DC m1, m7, 0, mova
1093 ;-----------------------------------------------------------------------------
1094 ; void vp8_idct_add_<opt>(uint8_t *dst, int16_t block[16], int stride);
1095 ;-----------------------------------------------------------------------------
1097 ; calculate %1=mul_35468(%1)-mul_20091(%2); %2=mul_20091(%1)+mul_35468(%2)
1098 ; this macro assumes that m6/m7 have words for 20091/17734 loaded
1099 %macro VP8_MULTIPLY_SUMSUB 4
1102 pmulhw %3, m6 ;20091(1)
1103 pmulhw %4, m6 ;20091(2)
1108 pmulhw %1, m7 ;35468(1)
1109 pmulhw %2, m7 ;35468(2)
1114 ; calculate x0=%1+%3; x1=%1-%3
1115 ; x2=mul_35468(%2)-mul_20091(%4); x3=mul_20091(%2)+mul_35468(%4)
1116 ; %1=x0+x3 (tmp0); %2=x1+x2 (tmp1); %3=x1-x2 (tmp2); %4=x0-x3 (tmp3)
1117 ; %5/%6 are temporary registers
1118 ; we assume m6/m7 have constant words 20091/17734 loaded in them
1119 %macro VP8_IDCT_TRANSFORM4x4_1D 6
1120 SUMSUB_BA w, %3, %1, %5 ;t0, t1
1121 VP8_MULTIPLY_SUMSUB m%2, m%4, m%5,m%6 ;t2, t3
1122 SUMSUB_BA w, %4, %3, %5 ;tmp0, tmp3
1123 SUMSUB_BA w, %2, %1, %5 ;tmp1, tmp2
1128 %macro VP8_IDCT_ADD 0
1129 cglobal vp8_idct_add, 3, 3, 0, dst, block, stride
1131 movq m0, [blockq+ 0]
1132 movq m1, [blockq+ 8]
1133 movq m2, [blockq+16]
1134 movq m3, [blockq+24]
1139 movaps [blockq+ 0], xmm0
1140 movaps [blockq+16], xmm0
1143 movq [blockq+ 0], m4
1144 movq [blockq+ 8], m4
1145 movq [blockq+16], m4
1146 movq [blockq+24], m4
1150 VP8_IDCT_TRANSFORM4x4_1D 0, 1, 2, 3, 4, 5
1151 TRANSPOSE4x4W 0, 1, 2, 3, 4
1153 VP8_IDCT_TRANSFORM4x4_1D 0, 1, 2, 3, 4, 5
1154 TRANSPOSE4x4W 0, 1, 2, 3, 4
1158 DEFINE_ARGS dst1, dst2, stride
1159 lea dst2q, [dst1q+2*strideq]
1160 STORE_DIFFx2 m0, m1, m6, m7, m4, 3, dst1q, strideq
1161 STORE_DIFFx2 m2, m3, m6, m7, m4, 3, dst2q, strideq
1173 ;-----------------------------------------------------------------------------
1174 ; void vp8_luma_dc_wht_mmxext(int16_t block[4][4][16], int16_t dc[16])
1175 ;-----------------------------------------------------------------------------
1177 %macro SCATTER_WHT 3
1180 mov [blockq+2*16*(0+%3)], dc1w
1181 mov [blockq+2*16*(1+%3)], dc2w
1186 mov [blockq+2*16*(4+%3)], dc1w
1187 mov [blockq+2*16*(5+%3)], dc2w
1190 mov [blockq+2*16*(8+%3)], dc1w
1191 mov [blockq+2*16*(9+%3)], dc2w
1194 mov [blockq+2*16*(12+%3)], dc1w
1195 mov [blockq+2*16*(13+%3)], dc2w
1198 %macro HADAMARD4_1D 4
1199 SUMSUB_BADC w, %2, %1, %4, %3
1200 SUMSUB_BADC w, %4, %2, %3, %1
1205 cglobal vp8_luma_dc_wht, 2, 3, 0, block, dc1, dc2
1212 movaps [dc1q+ 0], xmm0
1213 movaps [dc1q+16], xmm0
1221 HADAMARD4_1D 0, 1, 2, 3
1222 TRANSPOSE4x4W 0, 1, 2, 3, 4
1224 HADAMARD4_1D 0, 1, 2, 3
1241 ;-----------------------------------------------------------------------------
1242 ; void vp8_h/v_loop_filter_simple_<opt>(uint8_t *dst, int stride, int flim);
1243 ;-----------------------------------------------------------------------------
1245 ; macro called with 7 mm register indexes as argument, and 4 regular registers
1247 ; first 4 mm registers will carry the transposed pixel data
1248 ; the other three are scratchspace (one would be sufficient, but this allows
1249 ; for more spreading/pipelining and thus faster execution on OOE CPUs)
1251 ; first two regular registers are buf+4*stride and buf+5*stride
1252 ; third is -stride, fourth is +stride
1253 %macro READ_8x4_INTERLEAVED 11
1254 ; interleave 8 (A-H) rows of 4 pixels each
1255 movd m%1, [%8+%10*4] ; A0-3
1256 movd m%5, [%9+%10*4] ; B0-3
1257 movd m%2, [%8+%10*2] ; C0-3
1258 movd m%6, [%8+%10] ; D0-3
1259 movd m%3, [%8] ; E0-3
1260 movd m%7, [%9] ; F0-3
1261 movd m%4, [%9+%11] ; G0-3
1262 punpcklbw m%1, m%5 ; A/B interleaved
1263 movd m%5, [%9+%11*2] ; H0-3
1264 punpcklbw m%2, m%6 ; C/D interleaved
1265 punpcklbw m%3, m%7 ; E/F interleaved
1266 punpcklbw m%4, m%5 ; G/H interleaved
1269 ; macro called with 7 mm register indexes as argument, and 5 regular registers
1270 ; first 11 mean the same as READ_8x4_TRANSPOSED above
1271 ; fifth regular register is scratchspace to reach the bottom 8 rows, it
1272 ; will be set to second regular register + 8*stride at the end
1273 %macro READ_16x4_INTERLEAVED 12
1274 ; transpose 16 (A-P) rows of 4 pixels each
1277 ; read (and interleave) those addressable by %8 (=r0), A/C/D/E/I/K/L/M
1278 movd m%1, [%8+%10*4] ; A0-3
1279 movd m%3, [%12+%10*4] ; I0-3
1280 movd m%2, [%8+%10*2] ; C0-3
1281 movd m%4, [%12+%10*2] ; K0-3
1282 movd m%6, [%8+%10] ; D0-3
1283 movd m%5, [%12+%10] ; L0-3
1284 movd m%7, [%12] ; M0-3
1286 punpcklbw m%1, m%3 ; A/I
1287 movd m%3, [%8] ; E0-3
1288 punpcklbw m%2, m%4 ; C/K
1289 punpcklbw m%6, m%5 ; D/L
1290 punpcklbw m%3, m%7 ; E/M
1291 punpcklbw m%2, m%6 ; C/D/K/L interleaved
1293 ; read (and interleave) those addressable by %9 (=r4), B/F/G/H/J/N/O/P
1294 movd m%5, [%9+%10*4] ; B0-3
1295 movd m%4, [%12+%10*4] ; J0-3
1296 movd m%7, [%9] ; F0-3
1297 movd m%6, [%12] ; N0-3
1298 punpcklbw m%5, m%4 ; B/J
1299 punpcklbw m%7, m%6 ; F/N
1300 punpcklbw m%1, m%5 ; A/B/I/J interleaved
1301 punpcklbw m%3, m%7 ; E/F/M/N interleaved
1302 movd m%4, [%9+%11] ; G0-3
1303 movd m%6, [%12+%11] ; O0-3
1304 movd m%5, [%9+%11*2] ; H0-3
1305 movd m%7, [%12+%11*2] ; P0-3
1306 punpcklbw m%4, m%6 ; G/O
1307 punpcklbw m%5, m%7 ; H/P
1308 punpcklbw m%4, m%5 ; G/H/O/P interleaved
1311 ; write 4 mm registers of 2 dwords each
1312 ; first four arguments are mm register indexes containing source data
1313 ; last four are registers containing buf+4*stride, buf+5*stride,
1314 ; -stride and +stride
1316 ; write out (2 dwords per register)
1331 ; write 4 xmm registers of 4 dwords each
1332 ; arguments same as WRITE_2x4D, but with an extra register, so that the 5 regular
1333 ; registers contain buf+4*stride, buf+5*stride, buf+12*stride, -stride and +stride
1334 ; we add 1*stride to the third regular registry in the process
1335 ; the 10th argument is 16 if it's a Y filter (i.e. all regular registers cover the
1336 ; same memory region), or 8 if they cover two separate buffers (third one points to
1337 ; a different memory region than the first two), allowing for more optimal code for
1339 %macro WRITE_4x4D 10
1340 ; write out (4 dwords per register), start with dwords zero
1391 ; write 4 or 8 words in the mmx/xmm registers as 8 lines
1392 ; 1 and 2 are the registers to write, this can be the same (for SSE2)
1394 ; 3 is a general-purpose register that we will clobber
1396 ; 3 is a pointer to the destination's 5th line
1397 ; 4 is a pointer to the destination's 4th line
1398 ; 5/6 is -stride and +stride
1429 pextrw [%3+%4*4], %1, 0
1430 pextrw [%2+%4*4], %1, 1
1431 pextrw [%3+%4*2], %1, 2
1432 pextrw [%3+%4 ], %1, 3
1435 pextrw [%2+%5 ], %1, 6
1436 pextrw [%2+%5*2], %1, 7
1466 %macro SIMPLE_LOOPFILTER 2
1467 cglobal vp8_%1_loop_filter_simple, 3, %2, 8, dst, stride, flim, cntr
1468 %if mmsize == 8 ; mmx/mmxext
1474 SPLATB_REG m7, flim, m0 ; splat "flim" into register
1476 ; set up indexes to address 4 rows
1478 DEFINE_ARGS dst1, mstride, stride, cntr, dst2
1480 DEFINE_ARGS dst1, mstride, stride, dst3, dst2
1482 mov strideq, mstrideq
1485 lea dst1q, [dst1q+4*strideq-2]
1488 %if mmsize == 8 ; mmx / mmxext
1492 ; read 4 half/full rows of pixels
1493 mova m0, [dst1q+mstrideq*2] ; p1
1494 mova m1, [dst1q+mstrideq] ; p0
1495 mova m2, [dst1q] ; q0
1496 mova m3, [dst1q+ strideq] ; q1
1498 lea dst2q, [dst1q+ strideq]
1500 %if mmsize == 8 ; mmx/mmxext
1501 READ_8x4_INTERLEAVED 0, 1, 2, 3, 4, 5, 6, dst1q, dst2q, mstrideq, strideq
1503 READ_16x4_INTERLEAVED 0, 1, 2, 3, 4, 5, 6, dst1q, dst2q, mstrideq, strideq, dst3q
1505 TRANSPOSE4x4W 0, 1, 2, 3, 4
1509 mova m5, m2 ; m5=backup of q0
1510 mova m6, m1 ; m6=backup of p0
1511 psubusb m1, m2 ; p0-q0
1512 psubusb m2, m6 ; q0-p0
1513 por m1, m2 ; FFABS(p0-q0)
1514 paddusb m1, m1 ; m1=FFABS(p0-q0)*2
1518 psubusb m3, m0 ; q1-p1
1519 psubusb m0, m4 ; p1-q1
1520 por m3, m0 ; FFABS(p1-q1)
1524 psubsb m2, m4 ; m2=p1-q1 (signed) backup for below
1526 psrlq m3, 1 ; m3=FFABS(p1-q1)/2, this can be used signed
1530 pcmpeqb m3, m1 ; abs(p0-q0)*2+abs(p1-q1)/2<=flim mask(0xff/0x0)
1532 ; filter_common (use m2/p1-q1, m4=q0, m6=p0, m5/q0-p0 and m3/mask)
1536 psubsb m5, m0 ; q0-p0 (signed)
1539 paddsb m2, m5 ; a=(p1-q1) + 3*(q0-p0)
1540 pand m2, m3 ; apply filter mask (m3)
1544 paddsb m2, [pb_4] ; f1<<3=a+4
1545 paddsb m1, [pb_3] ; f2<<3=a+3
1547 pand m1, m3 ; cache f2<<3
1551 pcmpgtb m0, m2 ; which values are <0?
1552 psubb m3, m2 ; -f1<<3
1558 paddusb m4, m3 ; q0-f1
1562 pcmpgtb m0, m1 ; which values are <0?
1563 psubb m3, m1 ; -f2<<3
1569 psubusb m6, m3 ; p0+f2
1574 mova [dst1q+mstrideq], m6
1577 SBUTTERFLY bw, 6, 4, 0
1579 %if mmsize == 16 ; sse2
1583 WRITE_8W m6, dst2q, dst1q, mstrideq, strideq
1584 lea dst2q, [dst3q+mstrideq+1]
1588 WRITE_8W m4, dst3q, dst2q, mstrideq, strideq
1590 WRITE_2x4W m6, m4, dst2q, dst1q, mstrideq, strideq
1594 %if mmsize == 8 ; mmx/mmxext
1597 add dst1q, 8 ; advance 8 cols = pixels
1599 lea dst1q, [dst1q+strideq*8-1] ; advance 8 rows = lines
1611 SIMPLE_LOOPFILTER v, 4
1612 SIMPLE_LOOPFILTER h, 5
1614 SIMPLE_LOOPFILTER v, 4
1615 SIMPLE_LOOPFILTER h, 5
1619 SIMPLE_LOOPFILTER v, 3
1620 SIMPLE_LOOPFILTER h, 5
1622 SIMPLE_LOOPFILTER v, 3
1623 SIMPLE_LOOPFILTER h, 5
1625 SIMPLE_LOOPFILTER h, 5
1627 ;-----------------------------------------------------------------------------
1628 ; void vp8_h/v_loop_filter<size>_inner_<opt>(uint8_t *dst, [uint8_t *v,] int stride,
1629 ; int flimE, int flimI, int hev_thr);
1630 ;-----------------------------------------------------------------------------
1632 %macro INNER_LOOPFILTER 2
1633 %define stack_size 0
1634 %ifndef m8 ; stack layout: [0]=E, [1]=I, [2]=hev_thr
1635 %ifidn %1, v ; [3]=hev() result
1636 %define stack_size mmsize * -4
1637 %else ; h ; extra storage space for transposes
1638 %define stack_size mmsize * -5
1642 %if %2 == 8 ; chroma
1643 cglobal vp8_%1_loop_filter8uv_inner, 6, 6, 13, stack_size, dst, dst8, stride, flimE, flimI, hevthr
1645 cglobal vp8_%1_loop_filter16y_inner, 5, 5, 13, stack_size, dst, stride, flimE, flimI, hevthr
1653 ; splat function arguments
1654 SPLATB_REG m0, flimEq, m7 ; E
1655 SPLATB_REG m1, flimIq, m7 ; I
1656 SPLATB_REG m2, hevthrq, m7 ; hev_thresh
1658 %define m_flimE [rsp]
1659 %define m_flimI [rsp+mmsize]
1660 %define m_hevthr [rsp+mmsize*2]
1661 %define m_maskres [rsp+mmsize*3]
1662 %define m_p0backup [rsp+mmsize*3]
1663 %define m_q0backup [rsp+mmsize*4]
1671 %define m_hevthr m11
1672 %define m_maskres m12
1673 %define m_p0backup m12
1674 %define m_q0backup m8
1676 ; splat function arguments
1677 SPLATB_REG m_flimE, flimEq, m7 ; E
1678 SPLATB_REG m_flimI, flimIq, m7 ; I
1679 SPLATB_REG m_hevthr, hevthrq, m7 ; hev_thresh
1682 %if %2 == 8 ; chroma
1683 DEFINE_ARGS dst1, dst8, mstride, stride, dst2
1685 DEFINE_ARGS dst1, mstride, stride, dst2, cntr
1688 DEFINE_ARGS dst1, mstride, stride, dst2, dst8
1690 mov strideq, mstrideq
1693 lea dst1q, [dst1q+strideq*4-4]
1694 %if %2 == 8 ; chroma
1695 lea dst8q, [dst8q+strideq*4-4]
1703 lea dst2q, [dst1q+strideq]
1705 %if %2 == 8 && mmsize == 16
1710 movrow m0, [dst1q+mstrideq*4] ; p3
1711 movrow m1, [dst2q+mstrideq*4] ; p2
1712 movrow m2, [dst1q+mstrideq*2] ; p1
1713 movrow m5, [dst2q] ; q1
1714 movrow m6, [dst2q+ strideq*1] ; q2
1715 movrow m7, [dst2q+ strideq*2] ; q3
1716 %if mmsize == 16 && %2 == 8
1717 movhps m0, [dst8q+mstrideq*4]
1718 movhps m2, [dst8q+mstrideq*2]
1720 movhps m1, [dst8q+mstrideq*4]
1722 movhps m6, [dst8q+ strideq ]
1723 movhps m7, [dst8q+ strideq*2]
1726 %elif mmsize == 8 ; mmx/mmxext (h)
1727 ; read 8 rows of 8px each
1728 movu m0, [dst1q+mstrideq*4]
1729 movu m1, [dst2q+mstrideq*4]
1730 movu m2, [dst1q+mstrideq*2]
1731 movu m3, [dst1q+mstrideq ]
1734 movu m6, [dst2q+ strideq ]
1737 TRANSPOSE4x4B 0, 1, 2, 3, 7
1739 movu m7, [dst2q+ strideq*2]
1740 TRANSPOSE4x4B 4, 5, 6, 7, 1
1741 SBUTTERFLY dq, 0, 4, 1 ; p3/p2
1742 SBUTTERFLY dq, 2, 6, 1 ; q0/q1
1743 SBUTTERFLY dq, 3, 7, 1 ; q2/q3
1745 mova m_q0backup, m2 ; store q0
1746 SBUTTERFLY dq, 1, 5, 2 ; p1/p0
1747 mova m_p0backup, m5 ; store p0
1754 lea dst8q, [dst1q+ strideq*8]
1757 ; read 16 rows of 8px each, interleave
1758 movh m0, [dst1q+mstrideq*4]
1759 movh m1, [dst8q+mstrideq*4]
1760 movh m2, [dst1q+mstrideq*2]
1761 movh m5, [dst8q+mstrideq*2]
1762 movh m3, [dst1q+mstrideq ]
1763 movh m6, [dst8q+mstrideq ]
1766 punpcklbw m0, m1 ; A/I
1767 punpcklbw m2, m5 ; C/K
1768 punpcklbw m3, m6 ; D/L
1769 punpcklbw m4, m7 ; E/M
1772 movh m1, [dst2q+mstrideq*4]
1773 movh m6, [dst8q+mstrideq*4]
1776 punpcklbw m1, m6 ; B/J
1777 punpcklbw m5, m7 ; F/N
1778 movh m6, [dst2q+ strideq ]
1779 movh m7, [dst8q+ strideq ]
1780 punpcklbw m6, m7 ; G/O
1783 TRANSPOSE4x4B 0, 1, 2, 3, 7
1789 movh m7, [dst2q+ strideq*2]
1790 movh m1, [dst8q+ strideq*2]
1791 punpcklbw m7, m1 ; H/P
1792 TRANSPOSE4x4B 4, 5, 6, 7, 1
1793 SBUTTERFLY dq, 0, 4, 1 ; p3/p2
1794 SBUTTERFLY dq, 2, 6, 1 ; q0/q1
1795 SBUTTERFLY dq, 3, 7, 1 ; q2/q3
1801 mova m_q0backup, m2 ; store q0
1803 SBUTTERFLY dq, 1, 5, 2 ; p1/p0
1807 mova m_p0backup, m5 ; store p0
1815 ; normal_limit for p3-p2, p2-p1, q3-q2 and q2-q1
1818 psubusb m4, m0 ; p2-p3
1819 psubusb m0, m1 ; p3-p2
1820 por m0, m4 ; abs(p3-p2)
1824 psubusb m4, m1 ; p1-p2
1825 psubusb m1, m2 ; p2-p1
1826 por m1, m4 ; abs(p2-p1)
1830 psubusb m4, m7 ; q2-q3
1831 psubusb m7, m6 ; q3-q2
1832 por m7, m4 ; abs(q3-q2)
1836 psubusb m4, m6 ; q1-q2
1837 psubusb m6, m5 ; q2-q1
1838 por m6, m4 ; abs(q2-q1)
1840 %if notcpuflag(mmxext)
1847 pcmpeqb m0, m3 ; abs(p3-p2) <= I
1848 pcmpeqb m1, m3 ; abs(p2-p1) <= I
1849 pcmpeqb m7, m3 ; abs(q3-q2) <= I
1850 pcmpeqb m6, m3 ; abs(q2-q1) <= I
1860 ; normal_limit and high_edge_variance for p1-p0, q1-q0
1861 SWAP 7, 3 ; now m7 is zero
1863 movrow m3, [dst1q+mstrideq ] ; p0
1864 %if mmsize == 16 && %2 == 8
1865 movhps m3, [dst8q+mstrideq ]
1877 psubusb m1, m3 ; p1-p0
1878 psubusb m6, m2 ; p0-p1
1879 por m1, m6 ; abs(p1-p0)
1880 %if notcpuflag(mmxext)
1883 psubusb m6, m_hevthr
1884 pcmpeqb m1, m7 ; abs(p1-p0) <= I
1885 pcmpeqb m6, m7 ; abs(p1-p0) <= hev_thresh
1889 pmaxub m0, m1 ; max_I
1890 SWAP 1, 4 ; max_hev_thresh
1893 SWAP 6, 4 ; now m6 is I
1895 movrow m4, [dst1q] ; q0
1896 %if mmsize == 16 && %2 == 8
1908 psubusb m1, m5 ; q0-q1
1909 psubusb m7, m4 ; q1-q0
1910 por m1, m7 ; abs(q1-q0)
1911 %if notcpuflag(mmxext)
1914 psubusb m7, m_hevthr
1916 pcmpeqb m1, m6 ; abs(q1-q0) <= I
1917 pcmpeqb m7, m6 ; abs(q1-q0) <= hev_thresh
1919 pand m0, m1 ; abs([pq][321]-[pq][210]) <= I
1926 psubusb m6, m_hevthr
1927 pcmpeqb m0, m7 ; max(abs(..)) <= I
1928 pcmpeqb m6, m7 ; !(max(abs..) > thresh)
1933 mova m_maskres, m6 ; !(abs(p1-p0) > hev_t || abs(q1-q0) > hev_t)
1939 mova m6, m4 ; keep copies of p0/q0 around for later use
1941 psubusb m1, m4 ; p0-q0
1942 psubusb m6, m3 ; q0-p0
1943 por m1, m6 ; abs(q0-p0)
1944 paddusb m1, m1 ; m1=2*abs(q0-p0)
1950 psubusb m7, m5 ; p1-q1
1951 psubusb m6, m2 ; q1-p1
1952 por m7, m6 ; abs(q1-p1)
1955 psrlq m7, 1 ; abs(q1-p1)/2
1956 paddusb m7, m1 ; abs(q0-p0)*2+abs(q1-p1)/2
1958 pcmpeqb m7, m6 ; abs(q0-p0)*2+abs(q1-p1)/2 <= E
1959 pand m0, m7 ; normal_limit result
1961 ; filter_common; at this point, m2-m5=p1-q1 and m0 is filter_mask
1962 %ifdef m8 ; x86-64 && sse2
1965 %else ; x86-32 or mmx/mmxext
1966 %define m_pb_80 [pb_80]
1972 psubsb m1, m7 ; (signed) q0-p0
1977 psubsb m6, m7 ; (signed) p1-q1
1982 paddsb m7, m1 ; 3*(q0-p0)+is4tap?(p1-q1)
2001 paddusb m3, m1 ; p0+f2
2012 paddusb m4, m1 ; q0-f1
2019 %if notcpuflag(mmxext)
2026 %if notcpuflag(mmxext)
2040 paddusb m5, m1 ; q1-a
2041 paddusb m2, m0 ; p1+a
2045 movrow [dst1q+mstrideq*2], m2
2046 movrow [dst1q+mstrideq ], m3
2048 movrow [dst1q+ strideq ], m5
2049 %if mmsize == 16 && %2 == 8
2050 movhps [dst8q+mstrideq*2], m2
2051 movhps [dst8q+mstrideq ], m3
2053 movhps [dst8q+ strideq ], m5
2060 TRANSPOSE4x4B 2, 3, 4, 5, 6
2062 %if mmsize == 8 ; mmx/mmxext (h)
2063 WRITE_4x2D 2, 3, 4, 5, dst1q, dst2q, mstrideq, strideq
2065 lea dst8q, [dst8q+mstrideq +2]
2066 WRITE_4x4D 2, 3, 4, 5, dst1q, dst2q, dst8q, mstrideq, strideq, %2
2071 %if %2 == 8 ; chroma
2080 lea dst1q, [dst1q+ strideq*8-2]
2088 %else ; mmsize == 16
2095 INNER_LOOPFILTER v, 16
2096 INNER_LOOPFILTER h, 16
2097 INNER_LOOPFILTER v, 8
2098 INNER_LOOPFILTER h, 8
2101 INNER_LOOPFILTER v, 16
2102 INNER_LOOPFILTER h, 16
2103 INNER_LOOPFILTER v, 8
2104 INNER_LOOPFILTER h, 8
2108 INNER_LOOPFILTER v, 16
2109 INNER_LOOPFILTER h, 16
2110 INNER_LOOPFILTER v, 8
2111 INNER_LOOPFILTER h, 8
2114 INNER_LOOPFILTER v, 16
2115 INNER_LOOPFILTER h, 16
2116 INNER_LOOPFILTER v, 8
2117 INNER_LOOPFILTER h, 8
2119 ;-----------------------------------------------------------------------------
2120 ; void vp8_h/v_loop_filter<size>_mbedge_<opt>(uint8_t *dst, [uint8_t *v,] int stride,
2121 ; int flimE, int flimI, int hev_thr);
2122 ;-----------------------------------------------------------------------------
2124 %macro MBEDGE_LOOPFILTER 2
2125 %define stack_size 0
2126 %ifndef m8 ; stack layout: [0]=E, [1]=I, [2]=hev_thr
2127 %if mmsize == 16 ; [3]=hev() result
2128 ; [4]=filter tmp result
2129 ; [5]/[6] = p2/q2 backup
2130 ; [7]=lim_res sign result
2131 %define stack_size mmsize * -7
2132 %else ; 8 ; extra storage space for transposes
2133 %define stack_size mmsize * -8
2137 %if %2 == 8 ; chroma
2138 cglobal vp8_%1_loop_filter8uv_mbedge, 6, 6, 15, stack_size, dst1, dst8, stride, flimE, flimI, hevthr
2140 cglobal vp8_%1_loop_filter16y_mbedge, 5, 5, 15, stack_size, dst1, stride, flimE, flimI, hevthr
2148 ; splat function arguments
2149 SPLATB_REG m0, flimEq, m7 ; E
2150 SPLATB_REG m1, flimIq, m7 ; I
2151 SPLATB_REG m2, hevthrq, m7 ; hev_thresh
2153 %define m_flimE [rsp]
2154 %define m_flimI [rsp+mmsize]
2155 %define m_hevthr [rsp+mmsize*2]
2156 %define m_maskres [rsp+mmsize*3]
2157 %define m_limres [rsp+mmsize*4]
2158 %define m_p0backup [rsp+mmsize*3]
2159 %define m_q0backup [rsp+mmsize*4]
2160 %define m_p2backup [rsp+mmsize*5]
2161 %define m_q2backup [rsp+mmsize*6]
2163 %define m_limsign [rsp]
2165 %define m_limsign [rsp+mmsize*7]
2171 %else ; sse2 on x86-64
2174 %define m_hevthr m11
2175 %define m_maskres m12
2177 %define m_p0backup m12
2178 %define m_q0backup m8
2179 %define m_p2backup m13
2180 %define m_q2backup m14
2181 %define m_limsign m9
2183 ; splat function arguments
2184 SPLATB_REG m_flimE, flimEq, m7 ; E
2185 SPLATB_REG m_flimI, flimIq, m7 ; I
2186 SPLATB_REG m_hevthr, hevthrq, m7 ; hev_thresh
2189 %if %2 == 8 ; chroma
2190 DEFINE_ARGS dst1, dst8, mstride, stride, dst2
2192 DEFINE_ARGS dst1, mstride, stride, dst2, cntr
2195 DEFINE_ARGS dst1, mstride, stride, dst2, dst8
2197 mov strideq, mstrideq
2200 lea dst1q, [dst1q+strideq*4-4]
2201 %if %2 == 8 ; chroma
2202 lea dst8q, [dst8q+strideq*4-4]
2210 lea dst2q, [dst1q+ strideq ]
2212 %if %2 == 8 && mmsize == 16
2217 movrow m0, [dst1q+mstrideq*4] ; p3
2218 movrow m1, [dst2q+mstrideq*4] ; p2
2219 movrow m2, [dst1q+mstrideq*2] ; p1
2220 movrow m5, [dst2q] ; q1
2221 movrow m6, [dst2q+ strideq ] ; q2
2222 movrow m7, [dst2q+ strideq*2] ; q3
2223 %if mmsize == 16 && %2 == 8
2224 movhps m0, [dst8q+mstrideq*4]
2225 movhps m2, [dst8q+mstrideq*2]
2227 movhps m1, [dst8q+mstrideq*4]
2229 movhps m6, [dst8q+ strideq ]
2230 movhps m7, [dst8q+ strideq*2]
2233 %elif mmsize == 8 ; mmx/mmxext (h)
2234 ; read 8 rows of 8px each
2235 movu m0, [dst1q+mstrideq*4]
2236 movu m1, [dst2q+mstrideq*4]
2237 movu m2, [dst1q+mstrideq*2]
2238 movu m3, [dst1q+mstrideq ]
2241 movu m6, [dst2q+ strideq ]
2244 TRANSPOSE4x4B 0, 1, 2, 3, 7
2246 movu m7, [dst2q+ strideq*2]
2247 TRANSPOSE4x4B 4, 5, 6, 7, 1
2248 SBUTTERFLY dq, 0, 4, 1 ; p3/p2
2249 SBUTTERFLY dq, 2, 6, 1 ; q0/q1
2250 SBUTTERFLY dq, 3, 7, 1 ; q2/q3
2252 mova m_q0backup, m2 ; store q0
2253 SBUTTERFLY dq, 1, 5, 2 ; p1/p0
2254 mova m_p0backup, m5 ; store p0
2261 lea dst8q, [dst1q+ strideq*8 ]
2264 ; read 16 rows of 8px each, interleave
2265 movh m0, [dst1q+mstrideq*4]
2266 movh m1, [dst8q+mstrideq*4]
2267 movh m2, [dst1q+mstrideq*2]
2268 movh m5, [dst8q+mstrideq*2]
2269 movh m3, [dst1q+mstrideq ]
2270 movh m6, [dst8q+mstrideq ]
2273 punpcklbw m0, m1 ; A/I
2274 punpcklbw m2, m5 ; C/K
2275 punpcklbw m3, m6 ; D/L
2276 punpcklbw m4, m7 ; E/M
2279 movh m1, [dst2q+mstrideq*4]
2280 movh m6, [dst8q+mstrideq*4]
2283 punpcklbw m1, m6 ; B/J
2284 punpcklbw m5, m7 ; F/N
2285 movh m6, [dst2q+ strideq ]
2286 movh m7, [dst8q+ strideq ]
2287 punpcklbw m6, m7 ; G/O
2290 TRANSPOSE4x4B 0, 1, 2, 3, 7
2296 movh m7, [dst2q+ strideq*2]
2297 movh m1, [dst8q+ strideq*2]
2298 punpcklbw m7, m1 ; H/P
2299 TRANSPOSE4x4B 4, 5, 6, 7, 1
2300 SBUTTERFLY dq, 0, 4, 1 ; p3/p2
2301 SBUTTERFLY dq, 2, 6, 1 ; q0/q1
2302 SBUTTERFLY dq, 3, 7, 1 ; q2/q3
2308 mova m_q0backup, m2 ; store q0
2310 SBUTTERFLY dq, 1, 5, 2 ; p1/p0
2314 mova m_p0backup, m5 ; store p0
2322 ; normal_limit for p3-p2, p2-p1, q3-q2 and q2-q1
2325 psubusb m4, m0 ; p2-p3
2326 psubusb m0, m1 ; p3-p2
2327 por m0, m4 ; abs(p3-p2)
2331 psubusb m4, m1 ; p1-p2
2333 psubusb m1, m2 ; p2-p1
2334 por m1, m4 ; abs(p2-p1)
2338 psubusb m4, m7 ; q2-q3
2339 psubusb m7, m6 ; q3-q2
2340 por m7, m4 ; abs(q3-q2)
2344 psubusb m4, m6 ; q1-q2
2346 psubusb m6, m5 ; q2-q1
2347 por m6, m4 ; abs(q2-q1)
2349 %if notcpuflag(mmxext)
2356 pcmpeqb m0, m3 ; abs(p3-p2) <= I
2357 pcmpeqb m1, m3 ; abs(p2-p1) <= I
2358 pcmpeqb m7, m3 ; abs(q3-q2) <= I
2359 pcmpeqb m6, m3 ; abs(q2-q1) <= I
2369 ; normal_limit and high_edge_variance for p1-p0, q1-q0
2370 SWAP 7, 3 ; now m7 is zero
2372 movrow m3, [dst1q+mstrideq ] ; p0
2373 %if mmsize == 16 && %2 == 8
2374 movhps m3, [dst8q+mstrideq ]
2386 psubusb m1, m3 ; p1-p0
2387 psubusb m6, m2 ; p0-p1
2388 por m1, m6 ; abs(p1-p0)
2389 %if notcpuflag(mmxext)
2392 psubusb m6, m_hevthr
2393 pcmpeqb m1, m7 ; abs(p1-p0) <= I
2394 pcmpeqb m6, m7 ; abs(p1-p0) <= hev_thresh
2398 pmaxub m0, m1 ; max_I
2399 SWAP 1, 4 ; max_hev_thresh
2402 SWAP 6, 4 ; now m6 is I
2404 movrow m4, [dst1q] ; q0
2405 %if mmsize == 16 && %2 == 8
2417 psubusb m1, m5 ; q0-q1
2418 psubusb m7, m4 ; q1-q0
2419 por m1, m7 ; abs(q1-q0)
2420 %if notcpuflag(mmxext)
2423 psubusb m7, m_hevthr
2425 pcmpeqb m1, m6 ; abs(q1-q0) <= I
2426 pcmpeqb m7, m6 ; abs(q1-q0) <= hev_thresh
2428 pand m0, m1 ; abs([pq][321]-[pq][210]) <= I
2435 psubusb m6, m_hevthr
2436 pcmpeqb m0, m7 ; max(abs(..)) <= I
2437 pcmpeqb m6, m7 ; !(max(abs..) > thresh)
2442 mova m_maskres, m6 ; !(abs(p1-p0) > hev_t || abs(q1-q0) > hev_t)
2448 mova m6, m4 ; keep copies of p0/q0 around for later use
2450 psubusb m1, m4 ; p0-q0
2451 psubusb m6, m3 ; q0-p0
2452 por m1, m6 ; abs(q0-p0)
2453 paddusb m1, m1 ; m1=2*abs(q0-p0)
2459 psubusb m7, m5 ; p1-q1
2460 psubusb m6, m2 ; q1-p1
2461 por m7, m6 ; abs(q1-p1)
2464 psrlq m7, 1 ; abs(q1-p1)/2
2465 paddusb m7, m1 ; abs(q0-p0)*2+abs(q1-p1)/2
2467 pcmpeqb m7, m6 ; abs(q0-p0)*2+abs(q1-p1)/2 <= E
2468 pand m0, m7 ; normal_limit result
2470 ; filter_common; at this point, m2-m5=p1-q1 and m0 is filter_mask
2471 %ifdef m8 ; x86-64 && sse2
2474 %else ; x86-32 or mmx/mmxext
2475 %define m_pb_80 [pb_80]
2481 psubsb m1, m7 ; (signed) q0-p0
2486 psubsb m6, m7 ; (signed) p1-q1
2493 mova m_limres, m6 ; 3*(qp-p0)+(p1-q1) masked for filter_mbedge
2500 pandn m7, m6 ; 3*(q0-p0)+(p1-q1) masked for filter_common
2518 paddusb m3, m1 ; p0+f2
2529 paddusb m4, m1 ; q0-f1
2531 ; filter_mbedge (m2-m5 = p1-q1; lim_res carries w)
2544 pcmpgtb m0, m1 ; which are negative
2546 punpcklbw m6, m7 ; interleave with "1" for rounding
2549 punpcklbw m6, m0 ; signed byte->word
2559 SWAP 0, 10 ; don't lose lim_sign copy
2572 mova m_maskres, m6 ; backup for later in filter
2581 packsswb m6, m1 ; a0
2587 mova m6, [pb_18_63] ; pipelining
2591 paddusb m3, m0 ; p0+a0
2592 psubusb m4, m0 ; q0-a0
2621 packsswb m6, m1 ; a1
2631 paddusb m2, m0 ; p1+a1
2632 psubusb m5, m0 ; q1-a1
2666 packsswb m6, m1 ; a1
2680 paddusb m1, m7 ; p1+a1
2681 psubusb m6, m7 ; q1-a1
2685 movrow [dst2q+mstrideq*4], m1
2686 movrow [dst1q+mstrideq*2], m2
2687 movrow [dst1q+mstrideq ], m3
2690 movrow [dst2q+ strideq ], m6
2691 %if mmsize == 16 && %2 == 8
2693 movhps [dst8q+mstrideq*2], m1
2694 movhps [dst8q+mstrideq ], m2
2698 movhps [dst8q+ strideq ], m5
2699 movhps [dst8q+ strideq*2], m6
2706 TRANSPOSE4x4B 1, 2, 3, 4, 0
2707 SBUTTERFLY bw, 5, 6, 0
2709 %if mmsize == 8 ; mmx/mmxext (h)
2710 WRITE_4x2D 1, 2, 3, 4, dst1q, dst2q, mstrideq, strideq
2712 WRITE_2x4W m5, m6, dst2q, dst1q, mstrideq, strideq
2714 lea dst8q, [dst8q+mstrideq+1]
2715 WRITE_4x4D 1, 2, 3, 4, dst1q, dst2q, dst8q, mstrideq, strideq, %2
2716 lea dst1q, [dst2q+mstrideq+4]
2717 lea dst8q, [dst8q+mstrideq+4]
2721 WRITE_8W m5, dst2q, dst1q, mstrideq, strideq
2723 lea dst2q, [dst8q+ strideq ]
2725 WRITE_8W m6, dst2q, dst8q, mstrideq, strideq
2730 %if %2 == 8 ; chroma
2739 lea dst1q, [dst1q+ strideq*8-5]
2747 %else ; mmsize == 16
2754 MBEDGE_LOOPFILTER v, 16
2755 MBEDGE_LOOPFILTER h, 16
2756 MBEDGE_LOOPFILTER v, 8
2757 MBEDGE_LOOPFILTER h, 8
2760 MBEDGE_LOOPFILTER v, 16
2761 MBEDGE_LOOPFILTER h, 16
2762 MBEDGE_LOOPFILTER v, 8
2763 MBEDGE_LOOPFILTER h, 8
2767 MBEDGE_LOOPFILTER v, 16
2768 MBEDGE_LOOPFILTER h, 16
2769 MBEDGE_LOOPFILTER v, 8
2770 MBEDGE_LOOPFILTER h, 8
2773 MBEDGE_LOOPFILTER v, 16
2774 MBEDGE_LOOPFILTER h, 16
2775 MBEDGE_LOOPFILTER v, 8
2776 MBEDGE_LOOPFILTER h, 8
2779 MBEDGE_LOOPFILTER h, 16
2780 MBEDGE_LOOPFILTER h, 8