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.

283 lines
11KB

  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 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. * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
  23. */
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/cpu.h"
  26. #include "libavutil/x86/asm.h"
  27. #include "libavutil/x86/cpu.h"
  28. #include "libavcodec/avcodec.h"
  29. #include "libavcodec/hpeldsp.h"
  30. #include "libavcodec/pixels.h"
  31. #include "fpel.h"
  32. #include "hpeldsp.h"
  33. void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  34. ptrdiff_t line_size, int h);
  35. void ff_put_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  36. ptrdiff_t line_size, int h);
  37. void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  38. ptrdiff_t line_size, int h);
  39. void ff_put_pixels16_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  40. ptrdiff_t line_size, int h);
  41. void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  42. ptrdiff_t line_size, int h);
  43. void ff_put_no_rnd_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  44. ptrdiff_t line_size, int h);
  45. void ff_put_no_rnd_pixels8_x2_exact_mmxext(uint8_t *block,
  46. const uint8_t *pixels,
  47. ptrdiff_t line_size, int h);
  48. void ff_put_no_rnd_pixels8_x2_exact_3dnow(uint8_t *block,
  49. const uint8_t *pixels,
  50. ptrdiff_t line_size, int h);
  51. void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  52. ptrdiff_t line_size, int h);
  53. void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  54. ptrdiff_t line_size, int h);
  55. void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  56. ptrdiff_t line_size, int h);
  57. void ff_put_no_rnd_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  58. ptrdiff_t line_size, int h);
  59. void ff_put_no_rnd_pixels8_y2_exact_mmxext(uint8_t *block,
  60. const uint8_t *pixels,
  61. ptrdiff_t line_size, int h);
  62. void ff_put_no_rnd_pixels8_y2_exact_3dnow(uint8_t *block,
  63. const uint8_t *pixels,
  64. ptrdiff_t line_size, int h);
  65. void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
  66. ptrdiff_t line_size, int h);
  67. void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  68. ptrdiff_t line_size, int h);
  69. void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  70. ptrdiff_t line_size, int h);
  71. void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  72. ptrdiff_t line_size, int h);
  73. void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  74. ptrdiff_t line_size, int h);
  75. void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
  76. ptrdiff_t line_size, int h);
  77. void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
  78. ptrdiff_t line_size, int h);
  79. #define avg_pixels8_mmx ff_avg_pixels8_mmx
  80. #define avg_pixels8_x2_mmx ff_avg_pixels8_x2_mmx
  81. #define avg_pixels16_mmx ff_avg_pixels16_mmx
  82. #define avg_pixels8_xy2_mmx ff_avg_pixels8_xy2_mmx
  83. #define avg_pixels16_xy2_mmx ff_avg_pixels16_xy2_mmx
  84. #define put_pixels8_mmx ff_put_pixels8_mmx
  85. #define put_pixels16_mmx ff_put_pixels16_mmx
  86. #define put_pixels8_xy2_mmx ff_put_pixels8_xy2_mmx
  87. #define put_pixels16_xy2_mmx ff_put_pixels16_xy2_mmx
  88. #define avg_no_rnd_pixels16_mmx ff_avg_pixels16_mmx
  89. #define put_no_rnd_pixels8_mmx ff_put_pixels8_mmx
  90. #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
  91. #if HAVE_INLINE_ASM
  92. /***********************************/
  93. /* MMX no rounding */
  94. #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
  95. #define SET_RND MOVQ_WONE
  96. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
  97. #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
  98. #define STATIC static
  99. #include "rnd_template.c"
  100. #include "hpeldsp_rnd_template.c"
  101. #undef DEF
  102. #undef SET_RND
  103. #undef PAVGBP
  104. #undef PAVGB
  105. #undef STATIC
  106. CALL_2X_PIXELS(avg_no_rnd_pixels16_y2_mmx, avg_no_rnd_pixels8_y2_mmx, 8)
  107. CALL_2X_PIXELS(put_no_rnd_pixels16_y2_mmx, put_no_rnd_pixels8_y2_mmx, 8)
  108. CALL_2X_PIXELS(avg_no_rnd_pixels16_xy2_mmx, avg_no_rnd_pixels8_xy2_mmx, 8)
  109. CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_mmx, put_no_rnd_pixels8_xy2_mmx, 8)
  110. /***********************************/
  111. /* MMX rounding */
  112. #define DEF(x, y) x ## _ ## y ## _mmx
  113. #define SET_RND MOVQ_WTWO
  114. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
  115. #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
  116. #include "hpeldsp_rnd_template.c"
  117. #undef DEF
  118. #define DEF(x, y) ff_ ## x ## _ ## y ## _mmx
  119. #define STATIC
  120. #include "rnd_template.c"
  121. #undef DEF
  122. #undef SET_RND
  123. #undef PAVGBP
  124. #undef PAVGB
  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 /* HAVE_INLINE_ASM */
  130. #if HAVE_YASM
  131. #define HPELDSP_AVG_PIXELS16(CPUEXT) \
  132. CALL_2X_PIXELS(put_no_rnd_pixels16_x2 ## CPUEXT, ff_put_no_rnd_pixels8_x2 ## CPUEXT, 8) \
  133. CALL_2X_PIXELS(put_pixels16_y2 ## CPUEXT, ff_put_pixels8_y2 ## CPUEXT, 8) \
  134. CALL_2X_PIXELS(put_no_rnd_pixels16_y2 ## CPUEXT, ff_put_no_rnd_pixels8_y2 ## CPUEXT, 8) \
  135. CALL_2X_PIXELS(avg_pixels16 ## CPUEXT, ff_avg_pixels8 ## CPUEXT, 8) \
  136. CALL_2X_PIXELS(avg_pixels16_x2 ## CPUEXT, ff_avg_pixels8_x2 ## CPUEXT, 8) \
  137. CALL_2X_PIXELS(avg_pixels16_y2 ## CPUEXT, ff_avg_pixels8_y2 ## CPUEXT, 8) \
  138. CALL_2X_PIXELS(avg_pixels16_xy2 ## CPUEXT, ff_avg_pixels8_xy2 ## CPUEXT, 8)
  139. HPELDSP_AVG_PIXELS16(_3dnow)
  140. HPELDSP_AVG_PIXELS16(_mmxext)
  141. #endif /* HAVE_YASM */
  142. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  143. do { \
  144. c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
  145. c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
  146. c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
  147. c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
  148. } while (0)
  149. static void hpeldsp_init_mmx(HpelDSPContext *c, int flags, int cpu_flags)
  150. {
  151. #if HAVE_MMX_INLINE
  152. SET_HPEL_FUNCS(put, [0], 16, mmx);
  153. SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
  154. SET_HPEL_FUNCS(avg, [0], 16, mmx);
  155. SET_HPEL_FUNCS(avg_no_rnd, , 16, mmx);
  156. SET_HPEL_FUNCS(put, [1], 8, mmx);
  157. SET_HPEL_FUNCS(put_no_rnd, [1], 8, mmx);
  158. SET_HPEL_FUNCS(avg, [1], 8, mmx);
  159. #endif /* HAVE_MMX_INLINE */
  160. }
  161. static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags, int cpu_flags)
  162. {
  163. #if HAVE_MMXEXT_EXTERNAL
  164. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_mmxext;
  165. c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
  166. c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
  167. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
  168. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
  169. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_mmxext;
  170. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_mmxext;
  171. c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmxext;
  172. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmxext;
  173. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_mmxext;
  174. if (!(flags & CODEC_FLAG_BITEXACT)) {
  175. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
  176. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
  177. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_mmxext;
  178. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_mmxext;
  179. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
  180. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmxext;
  181. }
  182. if (flags & CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
  183. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_mmxext;
  184. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_mmxext;
  185. }
  186. #endif /* HAVE_MMXEXT_EXTERNAL */
  187. }
  188. static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags, int cpu_flags)
  189. {
  190. #if HAVE_AMD3DNOW_EXTERNAL
  191. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_3dnow;
  192. c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
  193. c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
  194. c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
  195. c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
  196. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_3dnow;
  197. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_3dnow;
  198. c->avg_pixels_tab[1][0] = ff_avg_pixels8_3dnow;
  199. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_3dnow;
  200. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_3dnow;
  201. if (!(flags & CODEC_FLAG_BITEXACT)){
  202. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
  203. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
  204. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_3dnow;
  205. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_3dnow;
  206. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
  207. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_3dnow;
  208. }
  209. if (flags & CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
  210. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_3dnow;
  211. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_3dnow;
  212. }
  213. #endif /* HAVE_AMD3DNOW_EXTERNAL */
  214. }
  215. static void hpeldsp_init_sse2(HpelDSPContext *c, int flags, int cpu_flags)
  216. {
  217. #if HAVE_SSE2_EXTERNAL
  218. if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
  219. // these functions are slower than mmx on AMD, but faster on Intel
  220. c->put_pixels_tab[0][0] = ff_put_pixels16_sse2;
  221. c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
  222. c->avg_pixels_tab[0][0] = ff_avg_pixels16_sse2;
  223. }
  224. #endif /* HAVE_SSE2_EXTERNAL */
  225. }
  226. av_cold void ff_hpeldsp_init_x86(HpelDSPContext *c, int flags)
  227. {
  228. int cpu_flags = av_get_cpu_flags();
  229. if (INLINE_MMX(cpu_flags))
  230. hpeldsp_init_mmx(c, flags, cpu_flags);
  231. if (EXTERNAL_AMD3DNOW(cpu_flags))
  232. hpeldsp_init_3dnow(c, flags, cpu_flags);
  233. if (EXTERNAL_MMXEXT(cpu_flags))
  234. hpeldsp_init_mmxext(c, flags, cpu_flags);
  235. if (EXTERNAL_SSE2(cpu_flags))
  236. hpeldsp_init_sse2(c, flags, cpu_flags);
  237. }