hpeldsp_init.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * SIMD-optimized halfpel functions
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
  23. */
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/cpu.h"
  26. #include "libavutil/x86/cpu.h"
  27. #include "libavcodec/avcodec.h"
  28. #include "libavcodec/hpeldsp.h"
  29. #include "libavcodec/pixels.h"
  30. #include "fpel.h"
  31. #include "hpeldsp.h"
  32. void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  33. ptrdiff_t line_size, int h);
  34. void ff_put_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  35. ptrdiff_t line_size, int h);
  36. void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  37. ptrdiff_t line_size, int h);
  38. void ff_put_pixels16_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  39. ptrdiff_t line_size, int h);
  40. void ff_put_pixels16_x2_sse2(uint8_t *block, const uint8_t *pixels,
  41. ptrdiff_t line_size, int h);
  42. void ff_avg_pixels16_x2_sse2(uint8_t *block, const uint8_t *pixels,
  43. ptrdiff_t line_size, int h);
  44. void ff_put_pixels16_y2_sse2(uint8_t *block, const uint8_t *pixels,
  45. ptrdiff_t line_size, int h);
  46. void ff_avg_pixels16_y2_sse2(uint8_t *block, const uint8_t *pixels,
  47. ptrdiff_t line_size, int h);
  48. void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  49. ptrdiff_t line_size, int h);
  50. void ff_put_no_rnd_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  51. ptrdiff_t line_size, int h);
  52. void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  53. ptrdiff_t line_size, int h);
  54. void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  55. ptrdiff_t line_size, int h);
  56. void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  57. ptrdiff_t line_size, int h);
  58. void ff_put_no_rnd_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  59. ptrdiff_t line_size, int h);
  60. void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
  61. ptrdiff_t line_size, int h);
  62. void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  63. ptrdiff_t line_size, int h);
  64. void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  65. ptrdiff_t line_size, int h);
  66. void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  67. ptrdiff_t line_size, int h);
  68. void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  69. ptrdiff_t line_size, int h);
  70. void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
  71. ptrdiff_t line_size, int h);
  72. void ff_avg_approx_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
  73. ptrdiff_t line_size, int h);
  74. void ff_avg_approx_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
  75. ptrdiff_t line_size, int h);
  76. #define avg_pixels8_mmx ff_avg_pixels8_mmx
  77. #define avg_pixels8_x2_mmx ff_avg_pixels8_x2_mmx
  78. #define avg_pixels16_mmx ff_avg_pixels16_mmx
  79. #define avg_pixels8_xy2_mmx ff_avg_pixels8_xy2_mmx
  80. #define avg_pixels16_xy2_mmx ff_avg_pixels16_xy2_mmx
  81. #define put_pixels8_mmx ff_put_pixels8_mmx
  82. #define put_pixels16_mmx ff_put_pixels16_mmx
  83. #define put_pixels8_xy2_mmx ff_put_pixels8_xy2_mmx
  84. #define put_pixels16_xy2_mmx ff_put_pixels16_xy2_mmx
  85. #define avg_no_rnd_pixels16_mmx ff_avg_pixels16_mmx
  86. #define put_no_rnd_pixels8_mmx ff_put_pixels8_mmx
  87. #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
  88. #if HAVE_INLINE_ASM
  89. /***********************************/
  90. /* MMX no rounding */
  91. #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
  92. #define SET_RND MOVQ_WONE
  93. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
  94. #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
  95. #define STATIC static
  96. #include "rnd_template.c"
  97. #include "hpeldsp_rnd_template.c"
  98. #undef DEF
  99. #undef SET_RND
  100. #undef PAVGBP
  101. #undef PAVGB
  102. #undef STATIC
  103. #if HAVE_MMX
  104. CALL_2X_PIXELS(avg_no_rnd_pixels16_y2_mmx, avg_no_rnd_pixels8_y2_mmx, 8)
  105. CALL_2X_PIXELS(put_no_rnd_pixels16_y2_mmx, put_no_rnd_pixels8_y2_mmx, 8)
  106. CALL_2X_PIXELS(avg_no_rnd_pixels16_xy2_mmx, avg_no_rnd_pixels8_xy2_mmx, 8)
  107. CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_mmx, put_no_rnd_pixels8_xy2_mmx, 8)
  108. #endif
  109. /***********************************/
  110. /* MMX rounding */
  111. #define DEF(x, y) x ## _ ## y ## _mmx
  112. #define SET_RND MOVQ_WTWO
  113. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
  114. #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
  115. #include "hpeldsp_rnd_template.c"
  116. #undef DEF
  117. #define DEF(x, y) ff_ ## x ## _ ## y ## _mmx
  118. #define STATIC
  119. #include "rnd_template.c"
  120. #undef DEF
  121. #undef SET_RND
  122. #undef PAVGBP
  123. #undef PAVGB
  124. #if HAVE_MMX
  125. CALL_2X_PIXELS(avg_pixels16_y2_mmx, avg_pixels8_y2_mmx, 8)
  126. CALL_2X_PIXELS(put_pixels16_y2_mmx, put_pixels8_y2_mmx, 8)
  127. CALL_2X_PIXELS_EXPORT(ff_avg_pixels16_xy2_mmx, ff_avg_pixels8_xy2_mmx, 8)
  128. CALL_2X_PIXELS_EXPORT(ff_put_pixels16_xy2_mmx, ff_put_pixels8_xy2_mmx, 8)
  129. #endif
  130. #endif /* HAVE_INLINE_ASM */
  131. #if HAVE_X86ASM
  132. #define HPELDSP_AVG_PIXELS16(CPUEXT) \
  133. CALL_2X_PIXELS(put_no_rnd_pixels16_x2 ## CPUEXT, ff_put_no_rnd_pixels8_x2 ## CPUEXT, 8) \
  134. CALL_2X_PIXELS(put_pixels16_y2 ## CPUEXT, ff_put_pixels8_y2 ## CPUEXT, 8) \
  135. CALL_2X_PIXELS(put_no_rnd_pixels16_y2 ## CPUEXT, ff_put_no_rnd_pixels8_y2 ## CPUEXT, 8) \
  136. CALL_2X_PIXELS(avg_pixels16 ## CPUEXT, ff_avg_pixels8 ## CPUEXT, 8) \
  137. CALL_2X_PIXELS(avg_pixels16_x2 ## CPUEXT, ff_avg_pixels8_x2 ## CPUEXT, 8) \
  138. CALL_2X_PIXELS(avg_pixels16_y2 ## CPUEXT, ff_avg_pixels8_y2 ## CPUEXT, 8) \
  139. CALL_2X_PIXELS(avg_pixels16_xy2 ## CPUEXT, ff_avg_pixels8_xy2 ## CPUEXT, 8) \
  140. CALL_2X_PIXELS(avg_approx_pixels16_xy2## CPUEXT, ff_avg_approx_pixels8_xy2## CPUEXT, 8)
  141. HPELDSP_AVG_PIXELS16(_3dnow)
  142. HPELDSP_AVG_PIXELS16(_mmxext)
  143. #endif /* HAVE_X86ASM */
  144. #define SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU) \
  145. if (HAVE_MMX_EXTERNAL) \
  146. c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU;
  147. #if HAVE_MMX_INLINE
  148. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  149. do { \
  150. SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU) \
  151. c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
  152. c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
  153. c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
  154. } while (0)
  155. #else
  156. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  157. do { \
  158. SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU) \
  159. } while (0)
  160. #endif
  161. static void hpeldsp_init_mmx(HpelDSPContext *c, int flags)
  162. {
  163. SET_HPEL_FUNCS(put, [0], 16, mmx);
  164. SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
  165. SET_HPEL_FUNCS(avg, [0], 16, mmx);
  166. SET_HPEL_FUNCS(avg_no_rnd, , 16, mmx);
  167. SET_HPEL_FUNCS(put, [1], 8, mmx);
  168. SET_HPEL_FUNCS(put_no_rnd, [1], 8, mmx);
  169. if (HAVE_MMX_EXTERNAL) {
  170. c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmx;
  171. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmx;
  172. }
  173. #if HAVE_MMX_INLINE
  174. c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx;
  175. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmx;
  176. #endif
  177. }
  178. static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags)
  179. {
  180. #if HAVE_MMXEXT_EXTERNAL
  181. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_mmxext;
  182. c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
  183. c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
  184. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
  185. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
  186. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
  187. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_mmxext;
  188. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_mmxext;
  189. c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmxext;
  190. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmxext;
  191. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_mmxext;
  192. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmxext;
  193. if (!(flags & AV_CODEC_FLAG_BITEXACT)) {
  194. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
  195. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
  196. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_mmxext;
  197. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_mmxext;
  198. c->avg_pixels_tab[0][3] = avg_approx_pixels16_xy2_mmxext;
  199. c->avg_pixels_tab[1][3] = ff_avg_approx_pixels8_xy2_mmxext;
  200. }
  201. #endif /* HAVE_MMXEXT_EXTERNAL */
  202. }
  203. static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags)
  204. {
  205. #if HAVE_AMD3DNOW_EXTERNAL
  206. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_3dnow;
  207. c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
  208. c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
  209. c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
  210. c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
  211. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
  212. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_3dnow;
  213. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_3dnow;
  214. c->avg_pixels_tab[1][0] = ff_avg_pixels8_3dnow;
  215. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_3dnow;
  216. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_3dnow;
  217. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_3dnow;
  218. if (!(flags & AV_CODEC_FLAG_BITEXACT)){
  219. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
  220. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
  221. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_3dnow;
  222. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_3dnow;
  223. c->avg_pixels_tab[0][3] = avg_approx_pixels16_xy2_3dnow;
  224. c->avg_pixels_tab[1][3] = ff_avg_approx_pixels8_xy2_3dnow;
  225. }
  226. #endif /* HAVE_AMD3DNOW_EXTERNAL */
  227. }
  228. static void hpeldsp_init_sse2_fast(HpelDSPContext *c, int flags)
  229. {
  230. #if HAVE_SSE2_EXTERNAL
  231. c->put_pixels_tab[0][0] = ff_put_pixels16_sse2;
  232. c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
  233. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_sse2;
  234. c->put_pixels_tab[0][2] = ff_put_pixels16_y2_sse2;
  235. c->put_pixels_tab[0][3] = ff_put_pixels16_xy2_sse2;
  236. c->avg_pixels_tab[0][0] = ff_avg_pixels16_sse2;
  237. c->avg_pixels_tab[0][1] = ff_avg_pixels16_x2_sse2;
  238. c->avg_pixels_tab[0][2] = ff_avg_pixels16_y2_sse2;
  239. c->avg_pixels_tab[0][3] = ff_avg_pixels16_xy2_sse2;
  240. #endif /* HAVE_SSE2_EXTERNAL */
  241. }
  242. static void hpeldsp_init_ssse3(HpelDSPContext *c, int flags)
  243. {
  244. #if HAVE_SSSE3_EXTERNAL
  245. c->put_pixels_tab[0][3] = ff_put_pixels16_xy2_ssse3;
  246. c->avg_pixels_tab[0][3] = ff_avg_pixels16_xy2_ssse3;
  247. c->put_pixels_tab[1][3] = ff_put_pixels8_xy2_ssse3;
  248. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_ssse3;
  249. #endif
  250. }
  251. av_cold void ff_hpeldsp_init_x86(HpelDSPContext *c, int flags)
  252. {
  253. int cpu_flags = av_get_cpu_flags();
  254. if (INLINE_MMX(cpu_flags))
  255. hpeldsp_init_mmx(c, flags);
  256. if (EXTERNAL_AMD3DNOW(cpu_flags))
  257. hpeldsp_init_3dnow(c, flags);
  258. if (EXTERNAL_MMXEXT(cpu_flags))
  259. hpeldsp_init_mmxext(c, flags);
  260. if (EXTERNAL_SSE2_FAST(cpu_flags))
  261. hpeldsp_init_sse2_fast(c, flags);
  262. if (EXTERNAL_SSSE3(cpu_flags))
  263. hpeldsp_init_ssse3(c, flags);
  264. if (CONFIG_VP3_DECODER)
  265. ff_hpeldsp_vp3_init_x86(c, cpu_flags, flags);
  266. }