You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
8.6KB

  1. ;******************************************************************************
  2. ;* VP9 motion compensation SIMD optimizations
  3. ;*
  4. ;* Copyright (c) 2013 Ronald S. Bultje <rsbultje gmail com>
  5. ;*
  6. ;* This file is part of Libav.
  7. ;*
  8. ;* Libav 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.
  12. ;*
  13. ;* Libav 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.
  17. ;*
  18. ;* You should have received a copy of the GNU Lesser General Public
  19. ;* License along with Libav; if not, write to the Free Software
  20. ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. ;******************************************************************************
  22. %include "libavutil/x86/x86util.asm"
  23. SECTION_RODATA
  24. cextern pw_256
  25. %macro F8_TAPS 8
  26. times 8 db %1, %2
  27. times 8 db %3, %4
  28. times 8 db %5, %6
  29. times 8 db %7, %8
  30. %endmacro
  31. ; int8_t ff_filters_ssse3[3][15][4][16]
  32. const filters_ssse3 ; smooth
  33. F8_TAPS -3, -1, 32, 64, 38, 1, -3, 0
  34. F8_TAPS -2, -2, 29, 63, 41, 2, -3, 0
  35. F8_TAPS -2, -2, 26, 63, 43, 4, -4, 0
  36. F8_TAPS -2, -3, 24, 62, 46, 5, -4, 0
  37. F8_TAPS -2, -3, 21, 60, 49, 7, -4, 0
  38. F8_TAPS -1, -4, 18, 59, 51, 9, -4, 0
  39. F8_TAPS -1, -4, 16, 57, 53, 12, -4, -1
  40. F8_TAPS -1, -4, 14, 55, 55, 14, -4, -1
  41. F8_TAPS -1, -4, 12, 53, 57, 16, -4, -1
  42. F8_TAPS 0, -4, 9, 51, 59, 18, -4, -1
  43. F8_TAPS 0, -4, 7, 49, 60, 21, -3, -2
  44. F8_TAPS 0, -4, 5, 46, 62, 24, -3, -2
  45. F8_TAPS 0, -4, 4, 43, 63, 26, -2, -2
  46. F8_TAPS 0, -3, 2, 41, 63, 29, -2, -2
  47. F8_TAPS 0, -3, 1, 38, 64, 32, -1, -3
  48. ; regular
  49. F8_TAPS 0, 1, -5, 126, 8, -3, 1, 0
  50. F8_TAPS -1, 3, -10, 122, 18, -6, 2, 0
  51. F8_TAPS -1, 4, -13, 118, 27, -9, 3, -1
  52. F8_TAPS -1, 4, -16, 112, 37, -11, 4, -1
  53. F8_TAPS -1, 5, -18, 105, 48, -14, 4, -1
  54. F8_TAPS -1, 5, -19, 97, 58, -16, 5, -1
  55. F8_TAPS -1, 6, -19, 88, 68, -18, 5, -1
  56. F8_TAPS -1, 6, -19, 78, 78, -19, 6, -1
  57. F8_TAPS -1, 5, -18, 68, 88, -19, 6, -1
  58. F8_TAPS -1, 5, -16, 58, 97, -19, 5, -1
  59. F8_TAPS -1, 4, -14, 48, 105, -18, 5, -1
  60. F8_TAPS -1, 4, -11, 37, 112, -16, 4, -1
  61. F8_TAPS -1, 3, -9, 27, 118, -13, 4, -1
  62. F8_TAPS 0, 2, -6, 18, 122, -10, 3, -1
  63. F8_TAPS 0, 1, -3, 8, 126, -5, 1, 0
  64. ; sharp
  65. F8_TAPS -1, 3, -7, 127, 8, -3, 1, 0
  66. F8_TAPS -2, 5, -13, 125, 17, -6, 3, -1
  67. F8_TAPS -3, 7, -17, 121, 27, -10, 5, -2
  68. F8_TAPS -4, 9, -20, 115, 37, -13, 6, -2
  69. F8_TAPS -4, 10, -23, 108, 48, -16, 8, -3
  70. F8_TAPS -4, 10, -24, 100, 59, -19, 9, -3
  71. F8_TAPS -4, 11, -24, 90, 70, -21, 10, -4
  72. F8_TAPS -4, 11, -23, 80, 80, -23, 11, -4
  73. F8_TAPS -4, 10, -21, 70, 90, -24, 11, -4
  74. F8_TAPS -3, 9, -19, 59, 100, -24, 10, -4
  75. F8_TAPS -3, 8, -16, 48, 108, -23, 10, -4
  76. F8_TAPS -2, 6, -13, 37, 115, -20, 9, -4
  77. F8_TAPS -2, 5, -10, 27, 121, -17, 7, -3
  78. F8_TAPS -1, 3, -6, 17, 125, -13, 5, -2
  79. F8_TAPS 0, 1, -3, 8, 127, -7, 3, -1
  80. SECTION .text
  81. %macro filter_h_fn 1
  82. %assign %%px mmsize/2
  83. cglobal %1_8tap_1d_h_ %+ %%px, 6, 6, 11, dst, src, dstride, sstride, h, filtery
  84. mova m6, [pw_256]
  85. mova m7, [filteryq+ 0]
  86. %if ARCH_X86_64 && mmsize > 8
  87. mova m8, [filteryq+16]
  88. mova m9, [filteryq+32]
  89. mova m10, [filteryq+48]
  90. %endif
  91. .loop:
  92. movh m0, [srcq-3]
  93. movh m1, [srcq-2]
  94. movh m2, [srcq-1]
  95. movh m3, [srcq+0]
  96. movh m4, [srcq+1]
  97. movh m5, [srcq+2]
  98. punpcklbw m0, m1
  99. punpcklbw m2, m3
  100. movh m1, [srcq+3]
  101. movh m3, [srcq+4]
  102. add srcq, sstrideq
  103. punpcklbw m4, m5
  104. punpcklbw m1, m3
  105. pmaddubsw m0, m7
  106. %if ARCH_X86_64 && mmsize > 8
  107. pmaddubsw m2, m8
  108. pmaddubsw m4, m9
  109. pmaddubsw m1, m10
  110. %else
  111. pmaddubsw m2, [filteryq+16]
  112. pmaddubsw m4, [filteryq+32]
  113. pmaddubsw m1, [filteryq+48]
  114. %endif
  115. paddw m0, m2
  116. paddw m4, m1
  117. paddsw m0, m4
  118. pmulhrsw m0, m6
  119. %ifidn %1, avg
  120. movh m1, [dstq]
  121. %endif
  122. packuswb m0, m0
  123. %ifidn %1, avg
  124. pavgb m0, m1
  125. %endif
  126. movh [dstq], m0
  127. add dstq, dstrideq
  128. dec hd
  129. jg .loop
  130. RET
  131. %endmacro
  132. INIT_MMX ssse3
  133. filter_h_fn put
  134. filter_h_fn avg
  135. INIT_XMM ssse3
  136. filter_h_fn put
  137. filter_h_fn avg
  138. %macro filter_v_fn 1
  139. %assign %%px mmsize/2
  140. %if ARCH_X86_64
  141. cglobal %1_8tap_1d_v_ %+ %%px, 6, 8, 11, dst, src, dstride, sstride, h, filtery, src4, sstride3
  142. %else
  143. cglobal %1_8tap_1d_v_ %+ %%px, 4, 7, 11, dst, src, dstride, sstride, filtery, src4, sstride3
  144. mov filteryq, r5mp
  145. %define hd r4mp
  146. %endif
  147. sub srcq, sstrideq
  148. lea sstride3q, [sstrideq*3]
  149. sub srcq, sstrideq
  150. mova m6, [pw_256]
  151. sub srcq, sstrideq
  152. mova m7, [filteryq+ 0]
  153. lea src4q, [srcq+sstrideq*4]
  154. %if ARCH_X86_64 && mmsize > 8
  155. mova m8, [filteryq+16]
  156. mova m9, [filteryq+32]
  157. mova m10, [filteryq+48]
  158. %endif
  159. .loop:
  160. ; FIXME maybe reuse loads from previous rows, or just more generally
  161. ; unroll this to prevent multiple loads of the same data?
  162. movh m0, [srcq]
  163. movh m1, [srcq+sstrideq]
  164. movh m2, [srcq+sstrideq*2]
  165. movh m3, [srcq+sstride3q]
  166. movh m4, [src4q]
  167. movh m5, [src4q+sstrideq]
  168. punpcklbw m0, m1
  169. punpcklbw m2, m3
  170. movh m1, [src4q+sstrideq*2]
  171. movh m3, [src4q+sstride3q]
  172. add srcq, sstrideq
  173. add src4q, sstrideq
  174. punpcklbw m4, m5
  175. punpcklbw m1, m3
  176. pmaddubsw m0, m7
  177. %if ARCH_X86_64 && mmsize > 8
  178. pmaddubsw m2, m8
  179. pmaddubsw m4, m9
  180. pmaddubsw m1, m10
  181. %else
  182. pmaddubsw m2, [filteryq+16]
  183. pmaddubsw m4, [filteryq+32]
  184. pmaddubsw m1, [filteryq+48]
  185. %endif
  186. paddw m0, m2
  187. paddw m4, m1
  188. paddsw m0, m4
  189. pmulhrsw m0, m6
  190. %ifidn %1, avg
  191. movh m1, [dstq]
  192. %endif
  193. packuswb m0, m0
  194. %ifidn %1, avg
  195. pavgb m0, m1
  196. %endif
  197. movh [dstq], m0
  198. add dstq, dstrideq
  199. dec hd
  200. jg .loop
  201. RET
  202. %endmacro
  203. INIT_MMX ssse3
  204. filter_v_fn put
  205. filter_v_fn avg
  206. INIT_XMM ssse3
  207. filter_v_fn put
  208. filter_v_fn avg
  209. %macro fpel_fn 6
  210. %if %2 == 4
  211. %define %%srcfn movh
  212. %define %%dstfn movh
  213. %else
  214. %define %%srcfn movu
  215. %define %%dstfn mova
  216. %endif
  217. %if %2 <= 16
  218. cglobal %1%2, 5, 7, 4, dst, src, dstride, sstride, h, dstride3, sstride3
  219. lea sstride3q, [sstrideq*3]
  220. lea dstride3q, [dstrideq*3]
  221. %else
  222. cglobal %1%2, 5, 5, 4, dst, src, dstride, sstride, h
  223. %endif
  224. .loop:
  225. %%srcfn m0, [srcq]
  226. %%srcfn m1, [srcq+s%3]
  227. %%srcfn m2, [srcq+s%4]
  228. %%srcfn m3, [srcq+s%5]
  229. lea srcq, [srcq+sstrideq*%6]
  230. %ifidn %1, avg
  231. pavgb m0, [dstq]
  232. pavgb m1, [dstq+d%3]
  233. pavgb m2, [dstq+d%4]
  234. pavgb m3, [dstq+d%5]
  235. %endif
  236. %%dstfn [dstq], m0
  237. %%dstfn [dstq+d%3], m1
  238. %%dstfn [dstq+d%4], m2
  239. %%dstfn [dstq+d%5], m3
  240. lea dstq, [dstq+dstrideq*%6]
  241. sub hd, %6
  242. jnz .loop
  243. RET
  244. %endmacro
  245. %define d16 16
  246. %define s16 16
  247. INIT_MMX mmx
  248. fpel_fn put, 4, strideq, strideq*2, stride3q, 4
  249. fpel_fn put, 8, strideq, strideq*2, stride3q, 4
  250. INIT_MMX sse
  251. fpel_fn avg, 4, strideq, strideq*2, stride3q, 4
  252. fpel_fn avg, 8, strideq, strideq*2, stride3q, 4
  253. INIT_XMM sse
  254. fpel_fn put, 16, strideq, strideq*2, stride3q, 4
  255. fpel_fn put, 32, mmsize, strideq, strideq+mmsize, 2
  256. fpel_fn put, 64, mmsize, mmsize*2, mmsize*3, 1
  257. INIT_XMM sse2
  258. fpel_fn avg, 16, strideq, strideq*2, stride3q, 4
  259. fpel_fn avg, 32, mmsize, strideq, strideq+mmsize, 2
  260. fpel_fn avg, 64, mmsize, mmsize*2, mmsize*3, 1
  261. %undef s16
  262. %undef d16