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.

636 lines
30KB

  1. /*
  2. * Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
  3. * Copyright (c) 2011 Daniel Kang
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/attributes.h"
  22. #include "libavutil/cpu.h"
  23. #include "libavutil/x86/asm.h"
  24. #include "libavutil/x86/cpu.h"
  25. #include "libavcodec/h264qpel.h"
  26. #include "libavcodec/mpegvideo.h"
  27. #include "libavcodec/pixels.h"
  28. #include "fpel.h"
  29. #if HAVE_YASM
  30. void ff_put_pixels4_mmxext(uint8_t *block, const uint8_t *pixels,
  31. ptrdiff_t line_size, int h);
  32. void ff_avg_pixels4_mmxext(uint8_t *block, const uint8_t *pixels,
  33. ptrdiff_t line_size, int h);
  34. void ff_put_pixels4_l2_mmxext(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
  35. int dstStride, int src1Stride, int h);
  36. void ff_avg_pixels4_l2_mmxext(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
  37. int dstStride, int src1Stride, int h);
  38. void ff_put_pixels8_l2_mmxext(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
  39. int dstStride, int src1Stride, int h);
  40. void ff_avg_pixels8_l2_mmxext(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
  41. int dstStride, int src1Stride, int h);
  42. void ff_put_pixels16_l2_mmxext(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
  43. int dstStride, int src1Stride, int h);
  44. void ff_avg_pixels16_l2_mmxext(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
  45. int dstStride, int src1Stride, int h);
  46. #define ff_put_pixels8_l2_sse2 ff_put_pixels8_l2_mmxext
  47. #define ff_avg_pixels8_l2_sse2 ff_avg_pixels8_l2_mmxext
  48. #define ff_put_pixels16_l2_sse2 ff_put_pixels16_l2_mmxext
  49. #define ff_avg_pixels16_l2_sse2 ff_avg_pixels16_l2_mmxext
  50. CALL_2X_PIXELS(ff_avg_pixels16_mmxext, ff_avg_pixels8_mmxext, 8)
  51. CALL_2X_PIXELS(ff_put_pixels16_mmxext, ff_put_pixels8_mmxext, 8)
  52. #define DEF_QPEL(OPNAME)\
  53. void ff_ ## OPNAME ## _h264_qpel4_h_lowpass_mmxext(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride);\
  54. void ff_ ## OPNAME ## _h264_qpel8_h_lowpass_mmxext(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride);\
  55. void ff_ ## OPNAME ## _h264_qpel8_h_lowpass_ssse3(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride);\
  56. void ff_ ## OPNAME ## _h264_qpel4_h_lowpass_l2_mmxext(uint8_t *dst, const uint8_t *src, const uint8_t *src2, int dstStride, int src2Stride);\
  57. void ff_ ## OPNAME ## _h264_qpel8_h_lowpass_l2_mmxext(uint8_t *dst, const uint8_t *src, const uint8_t *src2, int dstStride, int src2Stride);\
  58. void ff_ ## OPNAME ## _h264_qpel8_h_lowpass_l2_ssse3(uint8_t *dst, const uint8_t *src, const uint8_t *src2, int dstStride, int src2Stride);\
  59. void ff_ ## OPNAME ## _h264_qpel4_v_lowpass_mmxext(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride);\
  60. void ff_ ## OPNAME ## _h264_qpel8or16_v_lowpass_op_mmxext(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h);\
  61. void ff_ ## OPNAME ## _h264_qpel8or16_v_lowpass_sse2(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h);\
  62. void ff_ ## OPNAME ## _h264_qpel4_hv_lowpass_v_mmxext(const uint8_t *src, int16_t *tmp, int srcStride);\
  63. void ff_ ## OPNAME ## _h264_qpel4_hv_lowpass_h_mmxext(int16_t *tmp, uint8_t *dst, int dstStride);\
  64. void ff_ ## OPNAME ## _h264_qpel8or16_hv1_lowpass_op_mmxext(const uint8_t *src, int16_t *tmp, int srcStride, int size);\
  65. void ff_ ## OPNAME ## _h264_qpel8or16_hv1_lowpass_op_sse2(const uint8_t *src, int16_t *tmp, int srcStride, int size);\
  66. void ff_ ## OPNAME ## _h264_qpel8or16_hv2_lowpass_op_mmxext(uint8_t *dst, int16_t *tmp, int dstStride, int unused, int h);\
  67. void ff_ ## OPNAME ## _h264_qpel8or16_hv2_lowpass_ssse3(uint8_t *dst, int16_t *tmp, int dstStride, int tmpStride, int size);\
  68. void ff_ ## OPNAME ## _pixels4_l2_shift5_mmxext(uint8_t *dst, const int16_t *src16, const uint8_t *src8, int dstStride, int src8Stride, int h);\
  69. void ff_ ## OPNAME ## _pixels8_l2_shift5_mmxext(uint8_t *dst, const int16_t *src16, const uint8_t *src8, int dstStride, int src8Stride, int h);
  70. DEF_QPEL(avg)
  71. DEF_QPEL(put)
  72. #define QPEL_H264(OPNAME, OP, MMX)\
  73. static av_always_inline void ff_ ## OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, const uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  74. int w=3;\
  75. src -= 2*srcStride+2;\
  76. while(w--){\
  77. ff_ ## OPNAME ## h264_qpel4_hv_lowpass_v_mmxext(src, tmp, srcStride);\
  78. tmp += 4;\
  79. src += 4;\
  80. }\
  81. tmp -= 3*4;\
  82. ff_ ## OPNAME ## h264_qpel4_hv_lowpass_h_mmxext(tmp, dst, dstStride);\
  83. }\
  84. \
  85. static av_always_inline void ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h){\
  86. src -= 2*srcStride;\
  87. ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_op_mmxext(dst, src, dstStride, srcStride, h);\
  88. src += 4;\
  89. dst += 4;\
  90. ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_op_mmxext(dst, src, dstStride, srcStride, h);\
  91. }\
  92. static av_always_inline void ff_ ## OPNAME ## h264_qpel8or16_hv1_lowpass_ ## MMX(int16_t *tmp, const uint8_t *src, int tmpStride, int srcStride, int size){\
  93. int w = (size+8)>>2;\
  94. src -= 2*srcStride+2;\
  95. while(w--){\
  96. ff_ ## OPNAME ## h264_qpel8or16_hv1_lowpass_op_mmxext(src, tmp, srcStride, size);\
  97. tmp += 4;\
  98. src += 4;\
  99. }\
  100. }\
  101. static av_always_inline void ff_ ## OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, int dstStride, int tmpStride, int size){\
  102. int w = size>>4;\
  103. do{\
  104. ff_ ## OPNAME ## h264_qpel8or16_hv2_lowpass_op_mmxext(dst, tmp, dstStride, 0, size);\
  105. tmp += 8;\
  106. dst += 8;\
  107. }while(w--);\
  108. }\
  109. \
  110. static av_always_inline void ff_ ## OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride){\
  111. ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 8);\
  112. }\
  113. static av_always_inline void ff_ ## OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride){\
  114. ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 16);\
  115. ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
  116. }\
  117. \
  118. static av_always_inline void ff_ ## OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride){\
  119. ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
  120. ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
  121. src += 8*srcStride;\
  122. dst += 8*dstStride;\
  123. ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
  124. ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
  125. }\
  126. \
  127. static av_always_inline void ff_ ## OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, const uint8_t *src, const uint8_t *src2, int dstStride, int src2Stride){\
  128. ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
  129. ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
  130. src += 8*dstStride;\
  131. dst += 8*dstStride;\
  132. src2 += 8*src2Stride;\
  133. ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
  134. ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
  135. }\
  136. \
  137. static av_always_inline void ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, const uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\
  138. ff_put_h264_qpel8or16_hv1_lowpass_ ## MMX(tmp, src, tmpStride, srcStride, size);\
  139. ff_ ## OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(dst, tmp, dstStride, tmpStride, size);\
  140. }\
  141. static av_always_inline void ff_ ## OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, const uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  142. ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 8);\
  143. }\
  144. \
  145. static av_always_inline void ff_ ## OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, const uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  146. ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 16);\
  147. }\
  148. \
  149. static av_always_inline void ff_ ## OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, const int16_t *src16, const uint8_t *src8, int dstStride, int src8Stride, int h)\
  150. {\
  151. ff_ ## OPNAME ## pixels8_l2_shift5_ ## MMX(dst , src16 , src8 , dstStride, src8Stride, h);\
  152. ff_ ## OPNAME ## pixels8_l2_shift5_ ## MMX(dst+8, src16+8, src8+8, dstStride, src8Stride, h);\
  153. }\
  154. #if ARCH_X86_64
  155. #define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\
  156. void ff_avg_h264_qpel16_h_lowpass_l2_ssse3(uint8_t *dst, const uint8_t *src, const uint8_t *src2, int dstStride, int src2Stride);
  157. void ff_put_h264_qpel16_h_lowpass_l2_ssse3(uint8_t *dst, const uint8_t *src, const uint8_t *src2, int dstStride, int src2Stride);
  158. #else // ARCH_X86_64
  159. #define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\
  160. static av_always_inline void ff_ ## OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, const uint8_t *src, const uint8_t *src2, int dstStride, int src2Stride){\
  161. ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
  162. ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
  163. src += 8*dstStride;\
  164. dst += 8*dstStride;\
  165. src2 += 8*src2Stride;\
  166. ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
  167. ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
  168. }
  169. #endif // ARCH_X86_64
  170. #define QPEL_H264_H_XMM(OPNAME, OP, MMX)\
  171. QPEL_H264_H16_XMM(OPNAME, OP, MMX)\
  172. static av_always_inline void ff_ ## OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride){\
  173. ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
  174. ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
  175. src += 8*srcStride;\
  176. dst += 8*dstStride;\
  177. ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
  178. ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
  179. }\
  180. #define QPEL_H264_V_XMM(OPNAME, OP, MMX)\
  181. static av_always_inline void ff_ ## OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride){\
  182. ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 8);\
  183. }\
  184. static av_always_inline void ff_ ## OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride){\
  185. ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 16);\
  186. ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
  187. }
  188. static av_always_inline void put_h264_qpel8or16_hv1_lowpass_sse2(int16_t *tmp,
  189. const uint8_t *src,
  190. int tmpStride,
  191. int srcStride,
  192. int size)
  193. {
  194. int w = (size+8)>>3;
  195. src -= 2*srcStride+2;
  196. while(w--){
  197. ff_put_h264_qpel8or16_hv1_lowpass_op_sse2(src, tmp, srcStride, size);
  198. tmp += 8;
  199. src += 8;
  200. }
  201. }
  202. #define QPEL_H264_HV_XMM(OPNAME, OP, MMX)\
  203. static av_always_inline void ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, const uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\
  204. put_h264_qpel8or16_hv1_lowpass_sse2(tmp, src, tmpStride, srcStride, size);\
  205. ff_ ## OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(dst, tmp, dstStride, tmpStride, size);\
  206. }\
  207. static av_always_inline void ff_ ## OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, const uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  208. ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst, tmp, src, dstStride, tmpStride, srcStride, 8);\
  209. }\
  210. static av_always_inline void ff_ ## OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, const uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  211. ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst, tmp, src, dstStride, tmpStride, srcStride, 16);\
  212. }\
  213. #define ff_put_h264_qpel8_h_lowpass_l2_sse2 ff_put_h264_qpel8_h_lowpass_l2_mmxext
  214. #define ff_avg_h264_qpel8_h_lowpass_l2_sse2 ff_avg_h264_qpel8_h_lowpass_l2_mmxext
  215. #define ff_put_h264_qpel16_h_lowpass_l2_sse2 ff_put_h264_qpel16_h_lowpass_l2_mmxext
  216. #define ff_avg_h264_qpel16_h_lowpass_l2_sse2 ff_avg_h264_qpel16_h_lowpass_l2_mmxext
  217. #define ff_put_h264_qpel8_v_lowpass_ssse3 ff_put_h264_qpel8_v_lowpass_sse2
  218. #define ff_avg_h264_qpel8_v_lowpass_ssse3 ff_avg_h264_qpel8_v_lowpass_sse2
  219. #define ff_put_h264_qpel16_v_lowpass_ssse3 ff_put_h264_qpel16_v_lowpass_sse2
  220. #define ff_avg_h264_qpel16_v_lowpass_ssse3 ff_avg_h264_qpel16_v_lowpass_sse2
  221. #define ff_put_h264_qpel8or16_hv2_lowpass_sse2 ff_put_h264_qpel8or16_hv2_lowpass_mmxext
  222. #define ff_avg_h264_qpel8or16_hv2_lowpass_sse2 ff_avg_h264_qpel8or16_hv2_lowpass_mmxext
  223. #define H264_MC(OPNAME, SIZE, MMX, ALIGN) \
  224. H264_MC_C(OPNAME, SIZE, MMX, ALIGN)\
  225. H264_MC_V(OPNAME, SIZE, MMX, ALIGN)\
  226. H264_MC_H(OPNAME, SIZE, MMX, ALIGN)\
  227. H264_MC_HV(OPNAME, SIZE, MMX, ALIGN)\
  228. static void put_h264_qpel16_mc00_sse2 (uint8_t *dst, const uint8_t *src,
  229. ptrdiff_t stride)
  230. {
  231. ff_put_pixels16_sse2(dst, src, stride, 16);
  232. }
  233. static void avg_h264_qpel16_mc00_sse2 (uint8_t *dst, const uint8_t *src,
  234. ptrdiff_t stride)
  235. {
  236. ff_avg_pixels16_sse2(dst, src, stride, 16);
  237. }
  238. #define put_h264_qpel8_mc00_sse2 put_h264_qpel8_mc00_mmxext
  239. #define avg_h264_qpel8_mc00_sse2 avg_h264_qpel8_mc00_mmxext
  240. #define H264_MC_C(OPNAME, SIZE, MMX, ALIGN) \
  241. static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## MMX (uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  242. {\
  243. ff_ ## OPNAME ## pixels ## SIZE ## _ ## MMX(dst, src, stride, SIZE);\
  244. }\
  245. #define H264_MC_H(OPNAME, SIZE, MMX, ALIGN) \
  246. static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  247. {\
  248. ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src, stride, stride);\
  249. }\
  250. \
  251. static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  252. {\
  253. ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## MMX(dst, src, stride, stride);\
  254. }\
  255. \
  256. static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  257. {\
  258. ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src+1, stride, stride);\
  259. }\
  260. #define H264_MC_V(OPNAME, SIZE, MMX, ALIGN) \
  261. static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  262. {\
  263. DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
  264. ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
  265. ff_ ## OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, temp, stride, stride, SIZE);\
  266. }\
  267. \
  268. static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  269. {\
  270. ff_ ## OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## MMX(dst, src, stride, stride);\
  271. }\
  272. \
  273. static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  274. {\
  275. DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
  276. ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
  277. ff_ ## OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, temp, stride, stride, SIZE);\
  278. }\
  279. #define H264_MC_HV(OPNAME, SIZE, MMX, ALIGN) \
  280. static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  281. {\
  282. DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
  283. ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
  284. ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\
  285. }\
  286. \
  287. static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  288. {\
  289. DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
  290. ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\
  291. ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\
  292. }\
  293. \
  294. static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  295. {\
  296. DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
  297. ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
  298. ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\
  299. }\
  300. \
  301. static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  302. {\
  303. DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
  304. ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\
  305. ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\
  306. }\
  307. \
  308. static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  309. {\
  310. DECLARE_ALIGNED(ALIGN, uint16_t, temp)[SIZE*(SIZE<8?12:24)];\
  311. ff_ ## OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, temp, src, stride, SIZE, stride);\
  312. }\
  313. \
  314. static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  315. {\
  316. DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\
  317. uint8_t * const halfHV= temp;\
  318. int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
  319. assert(((int)temp & 7) == 0);\
  320. ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
  321. ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfHV, stride, SIZE);\
  322. }\
  323. \
  324. static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  325. {\
  326. DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\
  327. uint8_t * const halfHV= temp;\
  328. int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
  329. assert(((int)temp & 7) == 0);\
  330. ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
  331. ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfHV, stride, SIZE);\
  332. }\
  333. \
  334. static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  335. {\
  336. DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\
  337. uint8_t * const halfHV= temp;\
  338. int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
  339. assert(((int)temp & 7) == 0);\
  340. ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
  341. ff_ ## OPNAME ## pixels ## SIZE ## _l2_shift5_mmxext(dst, halfV+2, halfHV, stride, SIZE, SIZE);\
  342. }\
  343. \
  344. static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  345. {\
  346. DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\
  347. uint8_t * const halfHV= temp;\
  348. int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
  349. assert(((int)temp & 7) == 0);\
  350. ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
  351. ff_ ## OPNAME ## pixels ## SIZE ## _l2_shift5_mmxext(dst, halfV+3, halfHV, stride, SIZE, SIZE);\
  352. }\
  353. #define H264_MC_4816(MMX)\
  354. H264_MC(put_, 4, MMX, 8)\
  355. H264_MC(put_, 8, MMX, 8)\
  356. H264_MC(put_, 16,MMX, 8)\
  357. H264_MC(avg_, 4, MMX, 8)\
  358. H264_MC(avg_, 8, MMX, 8)\
  359. H264_MC(avg_, 16,MMX, 8)\
  360. #define H264_MC_816(QPEL, XMM)\
  361. QPEL(put_, 8, XMM, 16)\
  362. QPEL(put_, 16,XMM, 16)\
  363. QPEL(avg_, 8, XMM, 16)\
  364. QPEL(avg_, 16,XMM, 16)\
  365. QPEL_H264(put_, PUT_OP, mmxext)
  366. QPEL_H264(avg_, AVG_MMXEXT_OP, mmxext)
  367. QPEL_H264_V_XMM(put_, PUT_OP, sse2)
  368. QPEL_H264_V_XMM(avg_,AVG_MMXEXT_OP, sse2)
  369. QPEL_H264_HV_XMM(put_, PUT_OP, sse2)
  370. QPEL_H264_HV_XMM(avg_,AVG_MMXEXT_OP, sse2)
  371. QPEL_H264_H_XMM(put_, PUT_OP, ssse3)
  372. QPEL_H264_H_XMM(avg_,AVG_MMXEXT_OP, ssse3)
  373. QPEL_H264_HV_XMM(put_, PUT_OP, ssse3)
  374. QPEL_H264_HV_XMM(avg_,AVG_MMXEXT_OP, ssse3)
  375. H264_MC_4816(mmxext)
  376. H264_MC_816(H264_MC_V, sse2)
  377. H264_MC_816(H264_MC_HV, sse2)
  378. H264_MC_816(H264_MC_H, ssse3)
  379. H264_MC_816(H264_MC_HV, ssse3)
  380. //10bit
  381. #define LUMA_MC_OP(OP, NUM, DEPTH, TYPE, OPT) \
  382. void ff_ ## OP ## _h264_qpel ## NUM ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT \
  383. (uint8_t *dst, const uint8_t *src, ptrdiff_t stride);
  384. #define LUMA_MC_ALL(DEPTH, TYPE, OPT) \
  385. LUMA_MC_OP(put, 4, DEPTH, TYPE, OPT) \
  386. LUMA_MC_OP(avg, 4, DEPTH, TYPE, OPT) \
  387. LUMA_MC_OP(put, 8, DEPTH, TYPE, OPT) \
  388. LUMA_MC_OP(avg, 8, DEPTH, TYPE, OPT) \
  389. LUMA_MC_OP(put, 16, DEPTH, TYPE, OPT) \
  390. LUMA_MC_OP(avg, 16, DEPTH, TYPE, OPT)
  391. #define LUMA_MC_816(DEPTH, TYPE, OPT) \
  392. LUMA_MC_OP(put, 8, DEPTH, TYPE, OPT) \
  393. LUMA_MC_OP(avg, 8, DEPTH, TYPE, OPT) \
  394. LUMA_MC_OP(put, 16, DEPTH, TYPE, OPT) \
  395. LUMA_MC_OP(avg, 16, DEPTH, TYPE, OPT)
  396. LUMA_MC_ALL(10, mc00, mmxext)
  397. LUMA_MC_ALL(10, mc10, mmxext)
  398. LUMA_MC_ALL(10, mc20, mmxext)
  399. LUMA_MC_ALL(10, mc30, mmxext)
  400. LUMA_MC_ALL(10, mc01, mmxext)
  401. LUMA_MC_ALL(10, mc11, mmxext)
  402. LUMA_MC_ALL(10, mc21, mmxext)
  403. LUMA_MC_ALL(10, mc31, mmxext)
  404. LUMA_MC_ALL(10, mc02, mmxext)
  405. LUMA_MC_ALL(10, mc12, mmxext)
  406. LUMA_MC_ALL(10, mc22, mmxext)
  407. LUMA_MC_ALL(10, mc32, mmxext)
  408. LUMA_MC_ALL(10, mc03, mmxext)
  409. LUMA_MC_ALL(10, mc13, mmxext)
  410. LUMA_MC_ALL(10, mc23, mmxext)
  411. LUMA_MC_ALL(10, mc33, mmxext)
  412. LUMA_MC_816(10, mc00, sse2)
  413. LUMA_MC_816(10, mc10, sse2)
  414. LUMA_MC_816(10, mc10, sse2_cache64)
  415. LUMA_MC_816(10, mc10, ssse3_cache64)
  416. LUMA_MC_816(10, mc20, sse2)
  417. LUMA_MC_816(10, mc20, sse2_cache64)
  418. LUMA_MC_816(10, mc20, ssse3_cache64)
  419. LUMA_MC_816(10, mc30, sse2)
  420. LUMA_MC_816(10, mc30, sse2_cache64)
  421. LUMA_MC_816(10, mc30, ssse3_cache64)
  422. LUMA_MC_816(10, mc01, sse2)
  423. LUMA_MC_816(10, mc11, sse2)
  424. LUMA_MC_816(10, mc21, sse2)
  425. LUMA_MC_816(10, mc31, sse2)
  426. LUMA_MC_816(10, mc02, sse2)
  427. LUMA_MC_816(10, mc12, sse2)
  428. LUMA_MC_816(10, mc22, sse2)
  429. LUMA_MC_816(10, mc32, sse2)
  430. LUMA_MC_816(10, mc03, sse2)
  431. LUMA_MC_816(10, mc13, sse2)
  432. LUMA_MC_816(10, mc23, sse2)
  433. LUMA_MC_816(10, mc33, sse2)
  434. #define QPEL16_OPMC(OP, MC, MMX)\
  435. void ff_ ## OP ## _h264_qpel16_ ## MC ## _10_ ## MMX(uint8_t *dst, const uint8_t *src, ptrdiff_t stride){\
  436. ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst , src , stride);\
  437. ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst+16, src+16, stride);\
  438. src += 8*stride;\
  439. dst += 8*stride;\
  440. ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst , src , stride);\
  441. ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst+16, src+16, stride);\
  442. }
  443. #define QPEL16_OP(MC, MMX)\
  444. QPEL16_OPMC(put, MC, MMX)\
  445. QPEL16_OPMC(avg, MC, MMX)
  446. #define QPEL16(MMX)\
  447. QPEL16_OP(mc00, MMX)\
  448. QPEL16_OP(mc01, MMX)\
  449. QPEL16_OP(mc02, MMX)\
  450. QPEL16_OP(mc03, MMX)\
  451. QPEL16_OP(mc10, MMX)\
  452. QPEL16_OP(mc11, MMX)\
  453. QPEL16_OP(mc12, MMX)\
  454. QPEL16_OP(mc13, MMX)\
  455. QPEL16_OP(mc20, MMX)\
  456. QPEL16_OP(mc21, MMX)\
  457. QPEL16_OP(mc22, MMX)\
  458. QPEL16_OP(mc23, MMX)\
  459. QPEL16_OP(mc30, MMX)\
  460. QPEL16_OP(mc31, MMX)\
  461. QPEL16_OP(mc32, MMX)\
  462. QPEL16_OP(mc33, MMX)
  463. #if ARCH_X86_32 // ARCH_X86_64 implies SSE2+
  464. QPEL16(mmxext)
  465. #endif
  466. #endif /* HAVE_YASM */
  467. #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
  468. do { \
  469. c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
  470. c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
  471. c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
  472. c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
  473. c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
  474. c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
  475. c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
  476. c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
  477. c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
  478. c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
  479. c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
  480. c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
  481. c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
  482. c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
  483. c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
  484. c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
  485. } while (0)
  486. #define H264_QPEL_FUNCS(x, y, CPU) \
  487. do { \
  488. c->put_h264_qpel_pixels_tab[0][x + y * 4] = put_h264_qpel16_mc ## x ## y ## _ ## CPU; \
  489. c->put_h264_qpel_pixels_tab[1][x + y * 4] = put_h264_qpel8_mc ## x ## y ## _ ## CPU; \
  490. c->avg_h264_qpel_pixels_tab[0][x + y * 4] = avg_h264_qpel16_mc ## x ## y ## _ ## CPU; \
  491. c->avg_h264_qpel_pixels_tab[1][x + y * 4] = avg_h264_qpel8_mc ## x ## y ## _ ## CPU; \
  492. } while (0)
  493. #define H264_QPEL_FUNCS_10(x, y, CPU) \
  494. do { \
  495. c->put_h264_qpel_pixels_tab[0][x + y * 4] = ff_put_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
  496. c->put_h264_qpel_pixels_tab[1][x + y * 4] = ff_put_h264_qpel8_mc ## x ## y ## _10_ ## CPU; \
  497. c->avg_h264_qpel_pixels_tab[0][x + y * 4] = ff_avg_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
  498. c->avg_h264_qpel_pixels_tab[1][x + y * 4] = ff_avg_h264_qpel8_mc ## x ## y ## _10_ ## CPU; \
  499. } while (0)
  500. av_cold void ff_h264qpel_init_x86(H264QpelContext *c, int bit_depth)
  501. {
  502. #if HAVE_YASM
  503. int high_bit_depth = bit_depth > 8;
  504. int cpu_flags = av_get_cpu_flags();
  505. if (EXTERNAL_MMXEXT(cpu_flags)) {
  506. if (!high_bit_depth) {
  507. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmxext, );
  508. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmxext, );
  509. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmxext, );
  510. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmxext, );
  511. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmxext, );
  512. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmxext, );
  513. } else if (bit_depth == 10) {
  514. #if ARCH_X86_32
  515. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_mmxext, ff_);
  516. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_mmxext, ff_);
  517. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_mmxext, ff_);
  518. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_mmxext, ff_);
  519. #endif
  520. SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 10_mmxext, ff_);
  521. SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 10_mmxext, ff_);
  522. }
  523. }
  524. if (EXTERNAL_SSE2(cpu_flags)) {
  525. if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW) && !high_bit_depth) {
  526. // these functions are slower than mmx on AMD, but faster on Intel
  527. H264_QPEL_FUNCS(0, 0, sse2);
  528. }
  529. if (!high_bit_depth) {
  530. H264_QPEL_FUNCS(0, 1, sse2);
  531. H264_QPEL_FUNCS(0, 2, sse2);
  532. H264_QPEL_FUNCS(0, 3, sse2);
  533. H264_QPEL_FUNCS(1, 1, sse2);
  534. H264_QPEL_FUNCS(1, 2, sse2);
  535. H264_QPEL_FUNCS(1, 3, sse2);
  536. H264_QPEL_FUNCS(2, 1, sse2);
  537. H264_QPEL_FUNCS(2, 2, sse2);
  538. H264_QPEL_FUNCS(2, 3, sse2);
  539. H264_QPEL_FUNCS(3, 1, sse2);
  540. H264_QPEL_FUNCS(3, 2, sse2);
  541. H264_QPEL_FUNCS(3, 3, sse2);
  542. }
  543. if (bit_depth == 10) {
  544. SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_sse2, ff_);
  545. SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_sse2, ff_);
  546. SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_sse2, ff_);
  547. SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_sse2, ff_);
  548. H264_QPEL_FUNCS_10(1, 0, sse2_cache64);
  549. H264_QPEL_FUNCS_10(2, 0, sse2_cache64);
  550. H264_QPEL_FUNCS_10(3, 0, sse2_cache64);
  551. }
  552. }
  553. if (EXTERNAL_SSSE3(cpu_flags)) {
  554. if (!high_bit_depth) {
  555. H264_QPEL_FUNCS(1, 0, ssse3);
  556. H264_QPEL_FUNCS(1, 1, ssse3);
  557. H264_QPEL_FUNCS(1, 2, ssse3);
  558. H264_QPEL_FUNCS(1, 3, ssse3);
  559. H264_QPEL_FUNCS(2, 0, ssse3);
  560. H264_QPEL_FUNCS(2, 1, ssse3);
  561. H264_QPEL_FUNCS(2, 2, ssse3);
  562. H264_QPEL_FUNCS(2, 3, ssse3);
  563. H264_QPEL_FUNCS(3, 0, ssse3);
  564. H264_QPEL_FUNCS(3, 1, ssse3);
  565. H264_QPEL_FUNCS(3, 2, ssse3);
  566. H264_QPEL_FUNCS(3, 3, ssse3);
  567. }
  568. if (bit_depth == 10) {
  569. H264_QPEL_FUNCS_10(1, 0, ssse3_cache64);
  570. H264_QPEL_FUNCS_10(2, 0, ssse3_cache64);
  571. H264_QPEL_FUNCS_10(3, 0, ssse3_cache64);
  572. }
  573. }
  574. if (EXTERNAL_AVX(cpu_flags)) {
  575. /* AVX implies 64 byte cache lines without the need to avoid unaligned
  576. * memory accesses that cross the boundary between two cache lines.
  577. * TODO: Port X264_CPU_CACHELINE_32/64 detection from x264 to avoid
  578. * having to treat SSE2 functions with such properties as AVX. */
  579. if (bit_depth == 10) {
  580. H264_QPEL_FUNCS_10(1, 0, sse2);
  581. H264_QPEL_FUNCS_10(2, 0, sse2);
  582. H264_QPEL_FUNCS_10(3, 0, sse2);
  583. }
  584. }
  585. #endif
  586. }