vf_bwdif.asm 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. ;*****************************************************************************
  2. ;* x86-optimized functions for bwdif filter
  3. ;*
  4. ;* Copyright (C) 2016 Thomas Mundt <loudmax@yahoo.de>
  5. ;*
  6. ;* Based on yadif simd code
  7. ;* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
  8. ;* 2013 Daniel Kang <daniel.d.kang@gmail.com>
  9. ;*
  10. ;* This file is part of FFmpeg.
  11. ;*
  12. ;* FFmpeg is free software; you can redistribute it and/or
  13. ;* modify it under the terms of the GNU Lesser General Public
  14. ;* License as published by the Free Software Foundation; either
  15. ;* version 2.1 of the License, or (at your option) any later version.
  16. ;*
  17. ;* FFmpeg is distributed in the hope that it will be useful,
  18. ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. ;* Lesser General Public License for more details.
  21. ;*
  22. ;* You should have received a copy of the GNU Lesser General Public
  23. ;* License along with FFmpeg; if not, write to the Free Software
  24. ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  25. ;******************************************************************************
  26. %include "libavutil/x86/x86util.asm"
  27. SECTION_RODATA
  28. pw_coefhf: times 4 dw 1016, 5570
  29. pw_coefhf1: times 8 dw -3801
  30. pw_coefsp: times 4 dw 5077, -981
  31. pw_splfdif: times 4 dw -768, 768
  32. SECTION .text
  33. %macro LOAD8 2
  34. movh %1, %2
  35. punpcklbw %1, m7
  36. %endmacro
  37. %macro LOAD12 2
  38. movu %1, %2
  39. %endmacro
  40. %macro DISP8 0
  41. packuswb m2, m2
  42. movh [dstq], m2
  43. %endmacro
  44. %macro DISP12 0
  45. CLIPW m2, m7, m12
  46. movu [dstq], m2
  47. %endmacro
  48. %macro FILTER 5
  49. pxor m7, m7
  50. .loop%1:
  51. LOAD%4 m0, [curq+t0*%5]
  52. LOAD%4 m1, [curq+t1*%5]
  53. LOAD%4 m2, [%2]
  54. LOAD%4 m3, [%3]
  55. mova m4, m3
  56. paddw m3, m2
  57. psubw m2, m4
  58. ABS1 m2, m4
  59. mova m8, m3
  60. mova m9, m2
  61. LOAD%4 m3, [prevq+t0*%5]
  62. LOAD%4 m4, [prevq+t1*%5]
  63. psubw m3, m0
  64. psubw m4, m1
  65. ABS2 m3, m4, m5, m6
  66. paddw m3, m4
  67. psrlw m2, 1
  68. psrlw m3, 1
  69. pmaxsw m2, m3
  70. LOAD%4 m3, [nextq+t0*%5]
  71. LOAD%4 m4, [nextq+t1*%5]
  72. psubw m3, m0
  73. psubw m4, m1
  74. ABS2 m3, m4, m5, m6
  75. paddw m3, m4
  76. psrlw m3, 1
  77. pmaxsw m2, m3
  78. LOAD%4 m3, [%2+t0*2*%5]
  79. LOAD%4 m4, [%3+t0*2*%5]
  80. LOAD%4 m5, [%2+t1*2*%5]
  81. LOAD%4 m6, [%3+t1*2*%5]
  82. paddw m3, m4
  83. paddw m5, m6
  84. mova m6, m3
  85. paddw m6, m5
  86. mova m10, m6
  87. psrlw m3, 1
  88. psrlw m5, 1
  89. psubw m3, m0
  90. psubw m5, m1
  91. mova m6, m3
  92. pminsw m3, m5
  93. pmaxsw m5, m6
  94. mova m4, m8
  95. psraw m4, 1
  96. mova m6, m4
  97. psubw m6, m0
  98. psubw m4, m1
  99. pmaxsw m3, m6
  100. pminsw m5, m6
  101. pmaxsw m3, m4
  102. pminsw m5, m4
  103. mova m6, m7
  104. psubw m6, m3
  105. pmaxsw m6, m5
  106. mova m3, m2
  107. pcmpgtw m3, m7
  108. pand m6, m3
  109. pmaxsw m2, m6
  110. mova m11, m2
  111. LOAD%4 m2, [%2+t0*4*%5]
  112. LOAD%4 m3, [%3+t0*4*%5]
  113. LOAD%4 m4, [%2+t1*4*%5]
  114. LOAD%4 m5, [%3+t1*4*%5]
  115. paddw m2, m3
  116. paddw m4, m5
  117. paddw m2, m4
  118. mova m3, m2
  119. punpcklwd m2, m8
  120. punpckhwd m3, m8
  121. pmaddwd m2, [pw_coefhf]
  122. pmaddwd m3, [pw_coefhf]
  123. mova m4, m10
  124. mova m6, m4
  125. pmullw m4, [pw_coefhf1]
  126. pmulhw m6, [pw_coefhf1]
  127. mova m5, m4
  128. punpcklwd m4, m6
  129. punpckhwd m5, m6
  130. paddd m2, m4
  131. paddd m3, m5
  132. psrad m2, 2
  133. psrad m3, 2
  134. mova m4, m0
  135. paddw m0, m1
  136. %if ARCH_X86_64
  137. LOAD%4 m5, [curq+t2*%5]
  138. LOAD%4 m6, [curq+t3*%5]
  139. %else
  140. mov r4, prefs3mp
  141. mov r5, mrefs3mp
  142. LOAD%4 m5, [curq+t0*%5]
  143. LOAD%4 m6, [curq+t1*%5]
  144. mov r4, prefsmp
  145. mov r5, mrefsmp
  146. %endif
  147. paddw m6, m5
  148. psubw m1, m4
  149. ABS1 m1, m4
  150. pcmpgtw m1, m9
  151. mova m4, m1
  152. punpcklwd m1, m4
  153. punpckhwd m4, m4
  154. pand m2, m1
  155. pand m3, m4
  156. mova m5, [pw_splfdif]
  157. mova m7, m5
  158. pand m5, m1
  159. pand m7, m4
  160. paddw m5, [pw_coefsp]
  161. paddw m7, [pw_coefsp]
  162. mova m4, m0
  163. punpcklwd m0, m6
  164. punpckhwd m4, m6
  165. pmaddwd m0, m5
  166. pmaddwd m4, m7
  167. paddd m2, m0
  168. paddd m3, m4
  169. psrad m2, 13
  170. psrad m3, 13
  171. packssdw m2, m3
  172. mova m4, m8
  173. psraw m4, 1
  174. mova m0, m11
  175. mova m3, m4
  176. psubw m4, m0
  177. paddw m3, m0
  178. CLIPW m2, m4, m3
  179. pxor m7, m7
  180. DISP%4
  181. add dstq, STEP
  182. add prevq, STEP
  183. add curq, STEP
  184. add nextq, STEP
  185. sub DWORD wm, mmsize/2
  186. jg .loop%1
  187. %endmacro
  188. %macro PROC 2
  189. %if ARCH_X86_64
  190. movsxd r5, DWORD prefsm
  191. movsxd r6, DWORD mrefsm
  192. movsxd r7, DWORD prefs3m
  193. movsxd r8, DWORD mrefs3m
  194. DECLARE_REG_TMP 5, 6, 7, 8
  195. %else
  196. %define m8 [rsp+ 0]
  197. %define m9 [rsp+16]
  198. %define m10 [rsp+32]
  199. %define m11 [rsp+48]
  200. mov r4, prefsmp
  201. mov r5, mrefsmp
  202. DECLARE_REG_TMP 4, 5
  203. %endif
  204. cmp DWORD paritym, 0
  205. je .parity0
  206. FILTER 1, prevq, curq, %1, %2
  207. jmp .ret
  208. .parity0:
  209. FILTER 0, curq, nextq, %1, %2
  210. .ret:
  211. RET
  212. %endmacro
  213. %macro BWDIF 0
  214. %if ARCH_X86_64
  215. cglobal bwdif_filter_line, 4, 9, 12, 0, dst, prev, cur, next, w, prefs, \
  216. mrefs, prefs2, mrefs2, prefs3, mrefs3, \
  217. prefs4, mrefs4, parity, clip_max
  218. %else
  219. cglobal bwdif_filter_line, 4, 6, 8, 64, dst, prev, cur, next, w, prefs, \
  220. mrefs, prefs2, mrefs2, prefs3, mrefs3, \
  221. prefs4, mrefs4, parity, clip_max
  222. %endif
  223. %define STEP mmsize/2
  224. PROC 8, 1
  225. %if ARCH_X86_64
  226. cglobal bwdif_filter_line_12bit, 4, 9, 13, 0, dst, prev, cur, next, w, \
  227. prefs, mrefs, prefs2, mrefs2, \
  228. prefs3, mrefs3, prefs4, \
  229. mrefs4, parity, clip_max
  230. movd m12, DWORD clip_maxm
  231. SPLATW m12, m12, 0
  232. %else
  233. cglobal bwdif_filter_line_12bit, 4, 6, 8, 80, dst, prev, cur, next, w, \
  234. prefs, mrefs, prefs2, mrefs2, \
  235. prefs3, mrefs3, prefs4, \
  236. mrefs4, parity, clip_max
  237. %define m12 [rsp+64]
  238. movd m0, DWORD clip_maxm
  239. SPLATW m0, m0, 0
  240. mova m12, m0
  241. %endif
  242. %define STEP mmsize
  243. PROC 12, 2
  244. %endmacro
  245. INIT_XMM ssse3
  246. BWDIF
  247. INIT_XMM sse2
  248. BWDIF
  249. %if ARCH_X86_32
  250. INIT_MMX mmxext
  251. BWDIF
  252. %endif