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.

200 lines
7.1KB

  1. /*
  2. * Copyright (c) 2000, 2001 Fabrice Bellard
  3. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  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 "config.h"
  22. #include "libavutil/attributes.h"
  23. #include "libavutil/cpu.h"
  24. #include "libavutil/internal.h"
  25. #include "libavutil/x86/cpu.h"
  26. #include "libavcodec/avcodec.h"
  27. #include "libavcodec/dsputil.h"
  28. #include "libavcodec/simple_idct.h"
  29. #include "libavcodec/version.h"
  30. #include "dsputil_x86.h"
  31. #include "idct_xvid.h"
  32. int32_t ff_scalarproduct_int16_mmxext(const int16_t *v1, const int16_t *v2,
  33. int order);
  34. int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
  35. int order);
  36. void ff_bswap32_buf_ssse3(uint32_t *dst, const uint32_t *src, int w);
  37. void ff_bswap32_buf_sse2(uint32_t *dst, const uint32_t *src, int w);
  38. void ff_vector_clip_int32_mmx(int32_t *dst, const int32_t *src,
  39. int32_t min, int32_t max, unsigned int len);
  40. void ff_vector_clip_int32_sse2(int32_t *dst, const int32_t *src,
  41. int32_t min, int32_t max, unsigned int len);
  42. void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src,
  43. int32_t min, int32_t max, unsigned int len);
  44. void ff_vector_clip_int32_sse4(int32_t *dst, const int32_t *src,
  45. int32_t min, int32_t max, unsigned int len);
  46. static av_cold void dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx,
  47. int cpu_flags, unsigned high_bit_depth)
  48. {
  49. #if HAVE_MMX_INLINE
  50. c->put_pixels_clamped = ff_put_pixels_clamped_mmx;
  51. c->add_pixels_clamped = ff_add_pixels_clamped_mmx;
  52. if (!high_bit_depth) {
  53. c->draw_edges = ff_draw_edges_mmx;
  54. }
  55. #if CONFIG_VIDEODSP && (ARCH_X86_32 || !HAVE_YASM)
  56. c->gmc = ff_gmc_mmx;
  57. #endif
  58. #endif /* HAVE_MMX_INLINE */
  59. #if HAVE_MMX_EXTERNAL
  60. if (!high_bit_depth) {
  61. c->clear_block = ff_clear_block_mmx;
  62. c->clear_blocks = ff_clear_blocks_mmx;
  63. }
  64. c->vector_clip_int32 = ff_vector_clip_int32_mmx;
  65. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx;
  66. #endif /* HAVE_MMX_EXTERNAL */
  67. }
  68. static av_cold void dsputil_init_mmxext(DSPContext *c, AVCodecContext *avctx,
  69. int cpu_flags, unsigned high_bit_depth)
  70. {
  71. #if HAVE_MMXEXT_INLINE
  72. if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
  73. c->idct_put = ff_idct_xvid_mmxext_put;
  74. c->idct_add = ff_idct_xvid_mmxext_add;
  75. c->idct = ff_idct_xvid_mmxext;
  76. }
  77. #endif /* HAVE_MMXEXT_INLINE */
  78. #if HAVE_MMXEXT_EXTERNAL
  79. c->scalarproduct_int16 = ff_scalarproduct_int16_mmxext;
  80. #endif /* HAVE_MMXEXT_EXTERNAL */
  81. }
  82. static av_cold void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx,
  83. int cpu_flags, unsigned high_bit_depth)
  84. {
  85. #if HAVE_YASM
  86. #if HAVE_SSE_EXTERNAL
  87. c->vector_clipf = ff_vector_clipf_sse;
  88. /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
  89. if (CONFIG_XVMC && avctx->hwaccel && avctx->hwaccel->decode_mb)
  90. return;
  91. if (!high_bit_depth) {
  92. c->clear_block = ff_clear_block_sse;
  93. c->clear_blocks = ff_clear_blocks_sse;
  94. }
  95. #endif
  96. #if HAVE_INLINE_ASM && CONFIG_VIDEODSP
  97. c->gmc = ff_gmc_sse;
  98. #endif
  99. #endif /* HAVE_YASM */
  100. }
  101. static av_cold void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
  102. int cpu_flags, unsigned high_bit_depth)
  103. {
  104. #if HAVE_SSE2_INLINE
  105. if (!high_bit_depth && avctx->idct_algo == FF_IDCT_XVIDMMX && avctx->lowres == 0) {
  106. c->idct_put = ff_idct_xvid_sse2_put;
  107. c->idct_add = ff_idct_xvid_sse2_add;
  108. c->idct = ff_idct_xvid_sse2;
  109. c->idct_permutation_type = FF_SSE2_IDCT_PERM;
  110. }
  111. #endif /* HAVE_SSE2_INLINE */
  112. #if HAVE_SSE2_EXTERNAL
  113. c->scalarproduct_int16 = ff_scalarproduct_int16_sse2;
  114. if (cpu_flags & AV_CPU_FLAG_ATOM) {
  115. c->vector_clip_int32 = ff_vector_clip_int32_int_sse2;
  116. } else {
  117. c->vector_clip_int32 = ff_vector_clip_int32_sse2;
  118. }
  119. c->bswap_buf = ff_bswap32_buf_sse2;
  120. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_sse2;
  121. #endif /* HAVE_SSE2_EXTERNAL */
  122. }
  123. static av_cold void dsputil_init_ssse3(DSPContext *c, AVCodecContext *avctx,
  124. int cpu_flags, unsigned high_bit_depth)
  125. {
  126. #if HAVE_SSSE3_EXTERNAL
  127. c->bswap_buf = ff_bswap32_buf_ssse3;
  128. #endif /* HAVE_SSSE3_EXTERNAL */
  129. }
  130. static av_cold void dsputil_init_sse4(DSPContext *c, AVCodecContext *avctx,
  131. int cpu_flags, unsigned high_bit_depth)
  132. {
  133. #if HAVE_SSE4_EXTERNAL
  134. c->vector_clip_int32 = ff_vector_clip_int32_sse4;
  135. #endif /* HAVE_SSE4_EXTERNAL */
  136. }
  137. av_cold void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
  138. unsigned high_bit_depth)
  139. {
  140. int cpu_flags = av_get_cpu_flags();
  141. if (X86_MMX(cpu_flags)) {
  142. #if HAVE_INLINE_ASM
  143. const int idct_algo = avctx->idct_algo;
  144. if (avctx->lowres == 0 && !high_bit_depth) {
  145. if (idct_algo == FF_IDCT_AUTO || idct_algo == FF_IDCT_SIMPLEMMX) {
  146. c->idct_put = ff_simple_idct_put_mmx;
  147. c->idct_add = ff_simple_idct_add_mmx;
  148. c->idct = ff_simple_idct_mmx;
  149. c->idct_permutation_type = FF_SIMPLE_IDCT_PERM;
  150. } else if (idct_algo == FF_IDCT_XVIDMMX) {
  151. c->idct_put = ff_idct_xvid_mmx_put;
  152. c->idct_add = ff_idct_xvid_mmx_add;
  153. c->idct = ff_idct_xvid_mmx;
  154. }
  155. }
  156. #endif /* HAVE_INLINE_ASM */
  157. dsputil_init_mmx(c, avctx, cpu_flags, high_bit_depth);
  158. }
  159. if (X86_MMXEXT(cpu_flags))
  160. dsputil_init_mmxext(c, avctx, cpu_flags, high_bit_depth);
  161. if (X86_SSE(cpu_flags))
  162. dsputil_init_sse(c, avctx, cpu_flags, high_bit_depth);
  163. if (X86_SSE2(cpu_flags))
  164. dsputil_init_sse2(c, avctx, cpu_flags, high_bit_depth);
  165. if (EXTERNAL_SSSE3(cpu_flags))
  166. dsputil_init_ssse3(c, avctx, cpu_flags, high_bit_depth);
  167. if (EXTERNAL_SSE4(cpu_flags))
  168. dsputil_init_sse4(c, avctx, cpu_flags, high_bit_depth);
  169. if (CONFIG_ENCODERS)
  170. ff_dsputilenc_init_mmx(c, avctx, high_bit_depth);
  171. }