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.

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