yadif-16.asm 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. pw_8000: times 8 dw 0x8000
  28. pd_1: times 4 dd 1
  29. pd_8000: times 4 dd 0x8000
  30. SECTION .text
  31. %macro PABS 2
  32. %if cpuflag(ssse3)
  33. pabsd %1, %1
  34. %else
  35. pxor %2, %2
  36. pcmpgtd %2, %1
  37. pxor %1, %2
  38. psubd %1, %2
  39. %endif
  40. %endmacro
  41. %macro PACK 1
  42. %if cpuflag(sse4)
  43. packusdw %1, %1
  44. %else
  45. psubd %1, [pd_8000]
  46. packssdw %1, %1
  47. paddw %1, [pw_8000]
  48. %endif
  49. %endmacro
  50. %macro PMAXUW 2
  51. %if cpuflag(sse4)
  52. pmaxuw %1, %2
  53. %else
  54. psubusw %1, %2
  55. paddusw %1, %2
  56. %endif
  57. %endmacro
  58. %macro CHECK 2
  59. movu m2, [curq+t1+%1*2]
  60. movu m3, [curq+t0+%2*2]
  61. mova m4, m2
  62. mova m5, m2
  63. pxor m4, m3
  64. pavgw m5, m3
  65. pand m4, [pw_1]
  66. psubusw m5, m4
  67. RSHIFT m5, 2
  68. punpcklwd m5, m7
  69. mova m4, m2
  70. psubusw m2, m3
  71. psubusw m3, m4
  72. PMAXUW m2, m3
  73. mova m3, m2
  74. mova m4, m2
  75. RSHIFT m3, 2
  76. RSHIFT m4, 4
  77. punpcklwd m2, m7
  78. punpcklwd m3, m7
  79. punpcklwd m4, m7
  80. paddd m2, m3
  81. paddd m2, m4
  82. %endmacro
  83. %macro CHECK1 0
  84. mova m3, m0
  85. pcmpgtd m3, m2
  86. PMINSD m0, m2, m6
  87. mova m6, m3
  88. pand m5, m3
  89. pandn m3, m1
  90. por m3, m5
  91. mova m1, m3
  92. %endmacro
  93. %macro CHECK2 0
  94. paddd m6, [pd_1]
  95. pslld m6, 30
  96. paddd m2, m6
  97. mova m3, m0
  98. pcmpgtd m3, m2
  99. PMINSD m0, m2, m4
  100. pand m5, m3
  101. pandn m3, m1
  102. por m3, m5
  103. mova m1, m3
  104. %endmacro
  105. ; This version of CHECK2 has 3 fewer instructions on sets older than SSE4 but I
  106. ; am not sure whether it is any faster. A rewrite or refactor of the filter
  107. ; code should make it possible to eliminate the move instruction at the end. It
  108. ; exists to satisfy the expectation that the "score" values are in m1.
  109. ; %macro CHECK2 0
  110. ; mova m3, m0
  111. ; pcmpgtd m0, m2
  112. ; pand m0, m6
  113. ; mova m6, m0
  114. ; pand m5, m6
  115. ; pand m2, m0
  116. ; pandn m6, m1
  117. ; pandn m0, m3
  118. ; por m6, m5
  119. ; por m0, m2
  120. ; mova m1, m6
  121. ; %endmacro
  122. %macro LOAD 2
  123. movh %1, %2
  124. punpcklwd %1, m7
  125. %endmacro
  126. %macro FILTER 3
  127. .loop%1:
  128. pxor m7, m7
  129. LOAD m0, [curq+t1]
  130. LOAD m1, [curq+t0]
  131. LOAD m2, [%2]
  132. LOAD m3, [%3]
  133. mova m4, m3
  134. paddd m3, m2
  135. psrad m3, 1
  136. mova [rsp+ 0], m0
  137. mova [rsp+16], m3
  138. mova [rsp+32], m1
  139. psubd m2, m4
  140. PABS m2, m4
  141. LOAD m3, [prevq+t1]
  142. LOAD m4, [prevq+t0]
  143. psubd m3, m0
  144. psubd m4, m1
  145. PABS m3, m5
  146. PABS m4, m5
  147. paddd m3, m4
  148. psrld m2, 1
  149. psrld m3, 1
  150. PMAXSD m2, m3, m6
  151. LOAD m3, [nextq+t1]
  152. LOAD m4, [nextq+t0]
  153. psubd m3, m0
  154. psubd m4, m1
  155. PABS m3, m5
  156. PABS m4, m5
  157. paddd m3, m4
  158. psrld m3, 1
  159. PMAXSD m2, m3, m6
  160. mova [rsp+48], m2
  161. paddd m1, m0
  162. paddd m0, m0
  163. psubd m0, m1
  164. psrld m1, 1
  165. PABS m0, m2
  166. movu m2, [curq+t1-1*2]
  167. movu m3, [curq+t0-1*2]
  168. mova m4, m2
  169. psubusw m2, m3
  170. psubusw m3, m4
  171. PMAXUW m2, m3
  172. mova m3, m2
  173. RSHIFT m3, 4
  174. punpcklwd m2, m7
  175. punpcklwd m3, m7
  176. paddd m0, m2
  177. paddd m0, m3
  178. psubd m0, [pd_1]
  179. CHECK -2, 0
  180. CHECK1
  181. CHECK -3, 1
  182. CHECK2
  183. CHECK 0, -2
  184. CHECK1
  185. CHECK 1, -3
  186. CHECK2
  187. mova m6, [rsp+48]
  188. cmp DWORD r8m, 2
  189. jge .end%1
  190. LOAD m2, [%2+t1*2]
  191. LOAD m4, [%3+t1*2]
  192. LOAD m3, [%2+t0*2]
  193. LOAD m5, [%3+t0*2]
  194. paddd m2, m4
  195. paddd m3, m5
  196. psrld m2, 1
  197. psrld m3, 1
  198. mova m4, [rsp+ 0]
  199. mova m5, [rsp+16]
  200. mova m7, [rsp+32]
  201. psubd m2, m4
  202. psubd m3, m7
  203. mova m0, m5
  204. psubd m5, m4
  205. psubd m0, m7
  206. mova m4, m2
  207. PMINSD m2, m3, m7
  208. PMAXSD m3, m4, m7
  209. PMAXSD m2, m5, m7
  210. PMINSD m3, m5, m7
  211. PMAXSD m2, m0, m7
  212. PMINSD m3, m0, m7
  213. pxor m4, m4
  214. PMAXSD m6, m3, m7
  215. psubd m4, m2
  216. PMAXSD m6, m4, m7
  217. .end%1:
  218. mova m2, [rsp+16]
  219. mova m3, m2
  220. psubd m2, m6
  221. paddd m3, m6
  222. PMAXSD m1, m2, m7
  223. PMINSD m1, m3, m7
  224. PACK m1
  225. movh [dstq], m1
  226. add dstq, mmsize/2
  227. add prevq, mmsize/2
  228. add curq, mmsize/2
  229. add nextq, mmsize/2
  230. sub DWORD r4m, mmsize/4
  231. jg .loop%1
  232. %endmacro
  233. %macro YADIF 0
  234. %if ARCH_X86_32
  235. cglobal yadif_filter_line_16bit, 4, 6, 8, 80, dst, prev, cur, next, w, \
  236. prefs, mrefs, parity, mode
  237. %else
  238. cglobal yadif_filter_line_16bit, 4, 7, 8, 80, dst, prev, cur, next, w, \
  239. prefs, mrefs, parity, mode
  240. %endif
  241. %if ARCH_X86_32
  242. mov r4, r5mp
  243. mov r5, r6mp
  244. DECLARE_REG_TMP 4,5
  245. %else
  246. movsxd r5, DWORD r5m
  247. movsxd r6, DWORD r6m
  248. DECLARE_REG_TMP 5,6
  249. %endif
  250. cmp DWORD paritym, 0
  251. je .parity0
  252. FILTER 1, prevq, curq
  253. jmp .ret
  254. .parity0:
  255. FILTER 0, curq, nextq
  256. .ret:
  257. RET
  258. %endmacro
  259. INIT_XMM sse4
  260. YADIF
  261. INIT_XMM ssse3
  262. YADIF
  263. INIT_XMM sse2
  264. YADIF
  265. %if ARCH_X86_32
  266. INIT_MMX mmxext
  267. YADIF
  268. %endif