yadif-10.asm 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. ;*****************************************************************************
  2. ;* x86-optimized functions for yadif filter
  3. ;*
  4. ;* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
  5. ;* Copyright (c) 2013 Daniel Kang <daniel.d.kang@gmail.com>
  6. ;* Copyright (c) 2011-2013 James Darnley <james.darnley@gmail.com>
  7. ;*
  8. ;* This file is part of FFmpeg.
  9. ;*
  10. ;* FFmpeg is free software; you can redistribute it and/or
  11. ;* modify it under the terms of the GNU Lesser General Public
  12. ;* License as published by the Free Software Foundation; either
  13. ;* version 2.1 of the License, or (at your option) any later version.
  14. ;*
  15. ;* FFmpeg is distributed in the hope that it will be useful,
  16. ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. ;* Lesser General Public License for more details.
  19. ;*
  20. ;* You should have received a copy of the GNU Lesser General Public
  21. ;* License along with FFmpeg; if not, write to the Free Software
  22. ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. ;******************************************************************************
  24. %include "libavutil/x86/x86util.asm"
  25. SECTION_RODATA
  26. pw_1: times 8 dw 1
  27. SECTION .text
  28. %macro PMAXUW 2
  29. %if cpuflag(sse4)
  30. pmaxuw %1, %2
  31. %else
  32. psubusw %1, %2
  33. paddusw %1, %2
  34. %endif
  35. %endmacro
  36. %macro CHECK 2
  37. movu m2, [curq+t1+%1*2]
  38. movu m3, [curq+t0+%2*2]
  39. mova m4, m2
  40. mova m5, m2
  41. pxor m4, m3
  42. pavgw m5, m3
  43. pand m4, [pw_1]
  44. psubusw m5, m4
  45. RSHIFT m5, 2
  46. mova m4, m2
  47. psubusw m2, m3
  48. psubusw m3, m4
  49. PMAXUW m2, m3
  50. mova m3, m2
  51. mova m4, m2
  52. RSHIFT m3, 2
  53. RSHIFT m4, 4
  54. paddw m2, m3
  55. paddw m2, m4
  56. %endmacro
  57. %macro CHECK1 0
  58. mova m3, m0
  59. pcmpgtw m3, m2
  60. pminsw m0, m2
  61. mova m6, m3
  62. pand m5, m3
  63. pandn m3, m1
  64. por m3, m5
  65. mova m1, m3
  66. %endmacro
  67. ; %macro CHECK2 0
  68. ; paddw m6, [pw_1]
  69. ; psllw m6, 14
  70. ; paddsw m2, m6
  71. ; mova m3, m0
  72. ; pcmpgtw m3, m2
  73. ; pminsw m0, m2
  74. ; pand m5, m3
  75. ; pandn m3, m1
  76. ; por m3, m5
  77. ; mova m1, m3
  78. ; %endmacro
  79. ; This version of CHECK2 is required for 14-bit samples. The left-shift trick
  80. ; in the old code is not large enough to correctly select pixels or scores.
  81. %macro CHECK2 0
  82. mova m3, m0
  83. pcmpgtw m0, m2
  84. pand m0, m6
  85. mova m6, m0
  86. pand m5, m6
  87. pand m2, m0
  88. pandn m6, m1
  89. pandn m0, m3
  90. por m6, m5
  91. por m0, m2
  92. mova m1, m6
  93. %endmacro
  94. %macro LOAD 2
  95. movu %1, %2
  96. %endmacro
  97. %macro FILTER 3
  98. .loop%1:
  99. pxor m7, m7
  100. LOAD m0, [curq+t1]
  101. LOAD m1, [curq+t0]
  102. LOAD m2, [%2]
  103. LOAD m3, [%3]
  104. mova m4, m3
  105. paddw m3, m2
  106. psraw m3, 1
  107. mova [rsp+ 0], m0
  108. mova [rsp+16], m3
  109. mova [rsp+32], m1
  110. psubw m2, m4
  111. ABS1 m2, m4
  112. LOAD m3, [prevq+t1]
  113. LOAD m4, [prevq+t0]
  114. psubw m3, m0
  115. psubw m4, m1
  116. ABS2 m3, m4, m5, m6
  117. paddw m3, m4
  118. psrlw m2, 1
  119. psrlw m3, 1
  120. pmaxsw m2, m3
  121. LOAD m3, [nextq+t1]
  122. LOAD m4, [nextq+t0]
  123. psubw m3, m0
  124. psubw m4, m1
  125. ABS2 m3, m4, m5, m6
  126. paddw m3, m4
  127. psrlw m3, 1
  128. pmaxsw m2, m3
  129. mova [rsp+48], m2
  130. paddw m1, m0
  131. paddw m0, m0
  132. psubw m0, m1
  133. psrlw m1, 1
  134. ABS1 m0, m2
  135. movu m2, [curq+t1-1*2]
  136. movu m3, [curq+t0-1*2]
  137. mova m4, m2
  138. psubusw m2, m3
  139. psubusw m3, m4
  140. PMAXUW m2, m3
  141. mova m3, m2
  142. RSHIFT m3, 4
  143. paddw m0, m2
  144. paddw m0, m3
  145. psubw m0, [pw_1]
  146. CHECK -2, 0
  147. CHECK1
  148. CHECK -3, 1
  149. CHECK2
  150. CHECK 0, -2
  151. CHECK1
  152. CHECK 1, -3
  153. CHECK2
  154. mova m6, [rsp+48]
  155. cmp DWORD r8m, 2
  156. jge .end%1
  157. LOAD m2, [%2+t1*2]
  158. LOAD m4, [%3+t1*2]
  159. LOAD m3, [%2+t0*2]
  160. LOAD m5, [%3+t0*2]
  161. paddw m2, m4
  162. paddw m3, m5
  163. psrlw m2, 1
  164. psrlw m3, 1
  165. mova m4, [rsp+ 0]
  166. mova m5, [rsp+16]
  167. mova m7, [rsp+32]
  168. psubw m2, m4
  169. psubw m3, m7
  170. mova m0, m5
  171. psubw m5, m4
  172. psubw m0, m7
  173. mova m4, m2
  174. pminsw m2, m3
  175. pmaxsw m3, m4
  176. pmaxsw m2, m5
  177. pminsw m3, m5
  178. pmaxsw m2, m0
  179. pminsw m3, m0
  180. pxor m4, m4
  181. pmaxsw m6, m3
  182. psubw m4, m2
  183. pmaxsw m6, m4
  184. .end%1:
  185. mova m2, [rsp+16]
  186. mova m3, m2
  187. psubw m2, m6
  188. paddw m3, m6
  189. pmaxsw m1, m2
  190. pminsw m1, m3
  191. movu [dstq], m1
  192. add dstq, mmsize-4
  193. add prevq, mmsize-4
  194. add curq, mmsize-4
  195. add nextq, mmsize-4
  196. sub DWORD r4m, mmsize/2-2
  197. jg .loop%1
  198. %endmacro
  199. %macro YADIF 0
  200. %if ARCH_X86_32
  201. cglobal yadif_filter_line_10bit, 4, 6, 8, 80, dst, prev, cur, next, w, \
  202. prefs, mrefs, parity, mode
  203. %else
  204. cglobal yadif_filter_line_10bit, 4, 7, 8, 80, dst, prev, cur, next, w, \
  205. prefs, mrefs, parity, mode
  206. %endif
  207. %if ARCH_X86_32
  208. mov r4, r5mp
  209. mov r5, r6mp
  210. DECLARE_REG_TMP 4,5
  211. %else
  212. movsxd r5, DWORD r5m
  213. movsxd r6, DWORD r6m
  214. DECLARE_REG_TMP 5,6
  215. %endif
  216. cmp DWORD paritym, 0
  217. je .parity0
  218. FILTER 1, prevq, curq
  219. jmp .ret
  220. .parity0:
  221. FILTER 0, curq, nextq
  222. .ret:
  223. RET
  224. %endmacro
  225. INIT_XMM ssse3
  226. YADIF
  227. INIT_XMM sse2
  228. YADIF
  229. %if ARCH_X86_32
  230. INIT_MMX mmxext
  231. YADIF
  232. %endif