vf_interlace.asm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. ;*****************************************************************************
  2. ;* x86-optimized functions for interlace filter
  3. ;*
  4. ;* Copyright (C) 2014 Kieran Kunhya <kierank@obe.tv>
  5. ;* Copyright (c) 2014 Michael Niedermayer <michaelni@gmx.at>
  6. ;* Copyright (c) 2017 Thomas Mundt <tmundt75@gmail.com>
  7. ;*
  8. ;* This file is part of FFmpeg.
  9. ;*
  10. ;* FFmpeg is free software; you can redistribute it and/or modify
  11. ;* it under the terms of the GNU General Public License as published by
  12. ;* the Free Software Foundation; either version 2 of the License, or
  13. ;* (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
  18. ;* GNU General Public License for more details.
  19. ;*
  20. ;* You should have received a copy of the GNU General Public License along
  21. ;* with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  22. ;* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. ;******************************************************************************
  24. %include "libavutil/x86/x86util.asm"
  25. SECTION_RODATA
  26. pw_4: times 8 dw 4
  27. SECTION .text
  28. %macro LOWPASS 1
  29. add dstq, hq
  30. add srcq, hq
  31. add mrefq, srcq
  32. add prefq, srcq
  33. neg hq
  34. pcmpeq%1 m6, m6
  35. test hq, mmsize
  36. je .loop
  37. ;process 1 * mmsize
  38. movu m0, [mrefq+hq]
  39. pavg%1 m0, [prefq+hq]
  40. pxor m0, m6
  41. pxor m2, m6, [srcq+hq]
  42. pavg%1 m0, m2
  43. pxor m0, m6
  44. mova [dstq+hq], m0
  45. add hq, mmsize
  46. jge .end
  47. .loop:
  48. movu m0, [mrefq+hq]
  49. movu m1, [mrefq+hq+mmsize]
  50. pavg%1 m0, [prefq+hq]
  51. pavg%1 m1, [prefq+hq+mmsize]
  52. pxor m0, m6
  53. pxor m1, m6
  54. pxor m2, m6, [srcq+hq]
  55. pxor m3, m6, [srcq+hq+mmsize]
  56. pavg%1 m0, m2
  57. pavg%1 m1, m3
  58. pxor m0, m6
  59. pxor m1, m6
  60. mova [dstq+hq], m0
  61. mova [dstq+hq+mmsize], m1
  62. add hq, 2*mmsize
  63. jl .loop
  64. .end:
  65. REP_RET
  66. %endmacro
  67. %macro LOWPASS_LINE 0
  68. cglobal lowpass_line, 5, 5, 7, dst, h, src, mref, pref
  69. LOWPASS b
  70. cglobal lowpass_line_16, 5, 5, 7, dst, h, src, mref, pref
  71. shl hq, 1
  72. LOWPASS w
  73. %endmacro
  74. %macro LOWPASS_LINE_COMPLEX 0
  75. cglobal lowpass_line_complex, 5, 5, 8, dst, h, src, mref, pref
  76. pxor m7, m7
  77. .loop:
  78. movu m0, [srcq+mrefq]
  79. movu m2, [srcq+prefq]
  80. mova m1, m0
  81. mova m3, m2
  82. punpcklbw m0, m7
  83. punpcklbw m2, m7
  84. punpckhbw m1, m7
  85. punpckhbw m3, m7
  86. paddw m0, m2
  87. paddw m1, m3
  88. mova m6, m0
  89. mova m5, m1
  90. movu m2, [srcq]
  91. mova m3, m2
  92. punpcklbw m2, m7
  93. punpckhbw m3, m7
  94. paddw m0, m2
  95. paddw m1, m3
  96. psllw m2, 1
  97. psllw m3, 1
  98. paddw m0, m2
  99. paddw m1, m3
  100. psllw m0, 1
  101. psllw m1, 1
  102. pcmpgtw m6, m2
  103. pcmpgtw m5, m3
  104. packsswb m6, m5
  105. movu m2, [srcq+mrefq*2]
  106. movu m4, [srcq+prefq*2]
  107. mova m3, m2
  108. mova m5, m4
  109. punpcklbw m2, m7
  110. punpcklbw m4, m7
  111. punpckhbw m3, m7
  112. punpckhbw m5, m7
  113. paddw m2, m4
  114. paddw m3, m5
  115. paddw m0, [pw_4]
  116. paddw m1, [pw_4]
  117. psubusw m0, m2
  118. psubusw m1, m3
  119. psrlw m0, 3
  120. psrlw m1, 3
  121. packuswb m0, m1
  122. mova m1, m0
  123. movu m2, [srcq]
  124. pmaxub m0, m2
  125. pminub m1, m2
  126. pand m0, m6
  127. pandn m6, m1
  128. por m0, m6
  129. mova [dstq], m0
  130. add dstq, mmsize
  131. add srcq, mmsize
  132. sub hd, mmsize
  133. jg .loop
  134. REP_RET
  135. cglobal lowpass_line_complex_12, 5, 5, 8, 16, dst, h, src, mref, pref, clip_max
  136. movd m7, DWORD clip_maxm
  137. SPLATW m7, m7, 0
  138. movu [rsp], m7
  139. .loop:
  140. movu m0, [srcq+mrefq]
  141. movu m1, [srcq+mrefq+mmsize]
  142. movu m2, [srcq+prefq]
  143. movu m3, [srcq+prefq+mmsize]
  144. paddw m0, m2
  145. paddw m1, m3
  146. mova m6, m0
  147. mova m7, m1
  148. movu m2, [srcq]
  149. movu m3, [srcq+mmsize]
  150. paddw m0, m2
  151. paddw m1, m3
  152. psllw m2, 1
  153. psllw m3, 1
  154. paddw m0, m2
  155. paddw m1, m3
  156. psllw m0, 1
  157. psllw m1, 1
  158. pcmpgtw m6, m2
  159. pcmpgtw m7, m3
  160. movu m2, [srcq+2*mrefq]
  161. movu m3, [srcq+2*mrefq+mmsize]
  162. movu m4, [srcq+2*prefq]
  163. movu m5, [srcq+2*prefq+mmsize]
  164. paddw m2, m4
  165. paddw m3, m5
  166. paddw m0, [pw_4]
  167. paddw m1, [pw_4]
  168. psubusw m0, m2
  169. psubusw m1, m3
  170. psrlw m0, 3
  171. psrlw m1, 3
  172. pminsw m0, [rsp]
  173. pminsw m1, [rsp]
  174. mova m2, m0
  175. mova m3, m1
  176. movu m4, [srcq]
  177. pmaxsw m0, m4
  178. pminsw m2, m4
  179. movu m4, [srcq + mmsize]
  180. pmaxsw m1, m4
  181. pminsw m3, m4
  182. pand m0, m6
  183. pand m1, m7
  184. pandn m6, m2
  185. pandn m7, m3
  186. por m0, m6
  187. por m1, m7
  188. mova [dstq], m0
  189. mova [dstq+mmsize], m1
  190. add dstq, 2*mmsize
  191. add srcq, 2*mmsize
  192. sub hd, mmsize
  193. jg .loop
  194. REP_RET
  195. %endmacro
  196. INIT_XMM sse2
  197. LOWPASS_LINE
  198. INIT_XMM avx
  199. LOWPASS_LINE
  200. %if HAVE_AVX2_EXTERNAL
  201. INIT_YMM avx2
  202. LOWPASS_LINE
  203. %endif
  204. INIT_XMM sse2
  205. LOWPASS_LINE_COMPLEX