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.

260 lines
10KB

  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/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_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  41. ptrdiff_t line_size, int h);
  42. void ff_put_no_rnd_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  43. ptrdiff_t line_size, int h);
  44. void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  45. ptrdiff_t line_size, int h);
  46. void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  47. ptrdiff_t line_size, int h);
  48. void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  49. ptrdiff_t line_size, int h);
  50. void ff_put_no_rnd_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  51. ptrdiff_t line_size, int h);
  52. void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
  53. ptrdiff_t line_size, int h);
  54. void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  55. ptrdiff_t line_size, int h);
  56. void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  57. ptrdiff_t line_size, int h);
  58. void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  59. ptrdiff_t line_size, int h);
  60. void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  61. ptrdiff_t line_size, int h);
  62. void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
  63. ptrdiff_t line_size, int h);
  64. void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
  65. ptrdiff_t line_size, int h);
  66. #define avg_pixels8_mmx ff_avg_pixels8_mmx
  67. #define avg_pixels8_x2_mmx ff_avg_pixels8_x2_mmx
  68. #define avg_pixels16_mmx ff_avg_pixels16_mmx
  69. #define avg_pixels8_xy2_mmx ff_avg_pixels8_xy2_mmx
  70. #define avg_pixels16_xy2_mmx ff_avg_pixels16_xy2_mmx
  71. #define put_pixels8_mmx ff_put_pixels8_mmx
  72. #define put_pixels16_mmx ff_put_pixels16_mmx
  73. #define put_pixels8_xy2_mmx ff_put_pixels8_xy2_mmx
  74. #define put_pixels16_xy2_mmx ff_put_pixels16_xy2_mmx
  75. #define avg_no_rnd_pixels16_mmx ff_avg_pixels16_mmx
  76. #define put_no_rnd_pixels8_mmx ff_put_pixels8_mmx
  77. #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
  78. #if HAVE_INLINE_ASM
  79. /***********************************/
  80. /* MMX no rounding */
  81. #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
  82. #define SET_RND MOVQ_WONE
  83. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
  84. #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
  85. #define STATIC static
  86. #include "rnd_template.c"
  87. #include "hpeldsp_rnd_template.c"
  88. #undef DEF
  89. #undef SET_RND
  90. #undef PAVGBP
  91. #undef PAVGB
  92. #undef STATIC
  93. CALL_2X_PIXELS(avg_no_rnd_pixels16_y2_mmx, avg_no_rnd_pixels8_y2_mmx, 8)
  94. CALL_2X_PIXELS(put_no_rnd_pixels16_y2_mmx, put_no_rnd_pixels8_y2_mmx, 8)
  95. CALL_2X_PIXELS(avg_no_rnd_pixels16_xy2_mmx, avg_no_rnd_pixels8_xy2_mmx, 8)
  96. CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_mmx, put_no_rnd_pixels8_xy2_mmx, 8)
  97. /***********************************/
  98. /* MMX rounding */
  99. #define DEF(x, y) x ## _ ## y ## _mmx
  100. #define SET_RND MOVQ_WTWO
  101. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
  102. #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
  103. #include "hpeldsp_rnd_template.c"
  104. #undef DEF
  105. #define DEF(x, y) ff_ ## x ## _ ## y ## _mmx
  106. #define STATIC
  107. #include "rnd_template.c"
  108. #undef DEF
  109. #undef SET_RND
  110. #undef PAVGBP
  111. #undef PAVGB
  112. CALL_2X_PIXELS(avg_pixels16_y2_mmx, avg_pixels8_y2_mmx, 8)
  113. CALL_2X_PIXELS(put_pixels16_y2_mmx, put_pixels8_y2_mmx, 8)
  114. CALL_2X_PIXELS_EXPORT(ff_avg_pixels16_xy2_mmx, ff_avg_pixels8_xy2_mmx, 8)
  115. CALL_2X_PIXELS_EXPORT(ff_put_pixels16_xy2_mmx, ff_put_pixels8_xy2_mmx, 8)
  116. #endif /* HAVE_INLINE_ASM */
  117. #if HAVE_X86ASM
  118. #define HPELDSP_AVG_PIXELS16(CPUEXT) \
  119. CALL_2X_PIXELS(put_no_rnd_pixels16_x2 ## CPUEXT, ff_put_no_rnd_pixels8_x2 ## CPUEXT, 8) \
  120. CALL_2X_PIXELS(put_pixels16_y2 ## CPUEXT, ff_put_pixels8_y2 ## CPUEXT, 8) \
  121. CALL_2X_PIXELS(put_no_rnd_pixels16_y2 ## CPUEXT, ff_put_no_rnd_pixels8_y2 ## CPUEXT, 8) \
  122. CALL_2X_PIXELS(avg_pixels16 ## CPUEXT, ff_avg_pixels8 ## CPUEXT, 8) \
  123. CALL_2X_PIXELS(avg_pixels16_x2 ## CPUEXT, ff_avg_pixels8_x2 ## CPUEXT, 8) \
  124. CALL_2X_PIXELS(avg_pixels16_y2 ## CPUEXT, ff_avg_pixels8_y2 ## CPUEXT, 8) \
  125. CALL_2X_PIXELS(avg_pixels16_xy2 ## CPUEXT, ff_avg_pixels8_xy2 ## CPUEXT, 8)
  126. HPELDSP_AVG_PIXELS16(_3dnow)
  127. HPELDSP_AVG_PIXELS16(_mmxext)
  128. #endif /* HAVE_X86ASM */
  129. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  130. do { \
  131. c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
  132. c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
  133. c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
  134. c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
  135. } while (0)
  136. static void hpeldsp_init_mmx(HpelDSPContext *c, int flags)
  137. {
  138. #if HAVE_MMX_INLINE
  139. SET_HPEL_FUNCS(put, [0], 16, mmx);
  140. SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
  141. SET_HPEL_FUNCS(avg, [0], 16, mmx);
  142. SET_HPEL_FUNCS(avg_no_rnd, , 16, mmx);
  143. SET_HPEL_FUNCS(put, [1], 8, mmx);
  144. SET_HPEL_FUNCS(put_no_rnd, [1], 8, mmx);
  145. SET_HPEL_FUNCS(avg, [1], 8, mmx);
  146. #endif /* HAVE_MMX_INLINE */
  147. }
  148. static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags)
  149. {
  150. #if HAVE_MMXEXT_EXTERNAL
  151. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_mmxext;
  152. c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
  153. c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
  154. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
  155. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
  156. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_mmxext;
  157. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_mmxext;
  158. c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmxext;
  159. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmxext;
  160. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_mmxext;
  161. if (!(flags & AV_CODEC_FLAG_BITEXACT)) {
  162. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
  163. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
  164. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_mmxext;
  165. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_mmxext;
  166. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
  167. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmxext;
  168. }
  169. #endif /* HAVE_MMXEXT_EXTERNAL */
  170. }
  171. static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags)
  172. {
  173. #if HAVE_AMD3DNOW_EXTERNAL
  174. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_3dnow;
  175. c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
  176. c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
  177. c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
  178. c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
  179. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_3dnow;
  180. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_3dnow;
  181. c->avg_pixels_tab[1][0] = ff_avg_pixels8_3dnow;
  182. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_3dnow;
  183. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_3dnow;
  184. if (!(flags & AV_CODEC_FLAG_BITEXACT)){
  185. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
  186. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
  187. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_3dnow;
  188. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_3dnow;
  189. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
  190. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_3dnow;
  191. }
  192. #endif /* HAVE_AMD3DNOW_EXTERNAL */
  193. }
  194. static void hpeldsp_init_sse2_fast(HpelDSPContext *c, int flags)
  195. {
  196. #if HAVE_SSE2_EXTERNAL
  197. c->put_pixels_tab[0][0] = ff_put_pixels16_sse2;
  198. c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
  199. c->avg_pixels_tab[0][0] = ff_avg_pixels16_sse2;
  200. #endif /* HAVE_SSE2_EXTERNAL */
  201. }
  202. av_cold void ff_hpeldsp_init_x86(HpelDSPContext *c, int flags)
  203. {
  204. int cpu_flags = av_get_cpu_flags();
  205. if (INLINE_MMX(cpu_flags))
  206. hpeldsp_init_mmx(c, flags);
  207. if (EXTERNAL_AMD3DNOW(cpu_flags))
  208. hpeldsp_init_3dnow(c, flags);
  209. if (EXTERNAL_MMXEXT(cpu_flags))
  210. hpeldsp_init_mmxext(c, flags);
  211. if (EXTERNAL_SSE2_FAST(cpu_flags))
  212. hpeldsp_init_sse2_fast(c, flags);
  213. if (CONFIG_VP3_DECODER)
  214. ff_hpeldsp_vp3_init_x86(c, cpu_flags);
  215. }