ac3dsp_init.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * x86-optimized AC-3 DSP functions
  3. * Copyright (c) 2011 Justin Ruggles
  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/mem.h"
  23. #include "libavutil/x86/asm.h"
  24. #include "libavutil/x86/cpu.h"
  25. #include "libavcodec/ac3.h"
  26. #include "libavcodec/ac3dsp.h"
  27. void ff_ac3_exponent_min_mmx (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
  28. void ff_ac3_exponent_min_mmxext(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
  29. void ff_ac3_exponent_min_sse2 (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
  30. int ff_ac3_max_msb_abs_int16_mmx (const int16_t *src, int len);
  31. int ff_ac3_max_msb_abs_int16_mmxext(const int16_t *src, int len);
  32. int ff_ac3_max_msb_abs_int16_sse2 (const int16_t *src, int len);
  33. int ff_ac3_max_msb_abs_int16_ssse3(const int16_t *src, int len);
  34. void ff_ac3_lshift_int16_mmx (int16_t *src, unsigned int len, unsigned int shift);
  35. void ff_ac3_lshift_int16_sse2(int16_t *src, unsigned int len, unsigned int shift);
  36. void ff_ac3_rshift_int32_mmx (int32_t *src, unsigned int len, unsigned int shift);
  37. void ff_ac3_rshift_int32_sse2(int32_t *src, unsigned int len, unsigned int shift);
  38. void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned int len);
  39. void ff_float_to_fixed24_sse (int32_t *dst, const float *src, unsigned int len);
  40. void ff_float_to_fixed24_sse2 (int32_t *dst, const float *src, unsigned int len);
  41. int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16]);
  42. void ff_ac3_extract_exponents_sse2 (uint8_t *exp, int32_t *coef, int nb_coefs);
  43. void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs);
  44. void ff_apply_window_int16_round_mmxext(int16_t *output, const int16_t *input,
  45. const int16_t *window, unsigned int len);
  46. void ff_apply_window_int16_round_sse2(int16_t *output, const int16_t *input,
  47. const int16_t *window, unsigned int len);
  48. void ff_apply_window_int16_mmxext(int16_t *output, const int16_t *input,
  49. const int16_t *window, unsigned int len);
  50. void ff_apply_window_int16_sse2(int16_t *output, const int16_t *input,
  51. const int16_t *window, unsigned int len);
  52. void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input,
  53. const int16_t *window, unsigned int len);
  54. void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
  55. const int16_t *window, unsigned int len);
  56. av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
  57. {
  58. int cpu_flags = av_get_cpu_flags();
  59. if (EXTERNAL_MMX(cpu_flags)) {
  60. c->ac3_exponent_min = ff_ac3_exponent_min_mmx;
  61. c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx;
  62. c->ac3_lshift_int16 = ff_ac3_lshift_int16_mmx;
  63. c->ac3_rshift_int32 = ff_ac3_rshift_int32_mmx;
  64. }
  65. if (EXTERNAL_AMD3DNOW(cpu_flags)) {
  66. if (!bit_exact) {
  67. c->float_to_fixed24 = ff_float_to_fixed24_3dnow;
  68. }
  69. }
  70. if (EXTERNAL_MMXEXT(cpu_flags)) {
  71. c->ac3_exponent_min = ff_ac3_exponent_min_mmxext;
  72. c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmxext;
  73. if (bit_exact) {
  74. c->apply_window_int16 = ff_apply_window_int16_mmxext;
  75. } else {
  76. c->apply_window_int16 = ff_apply_window_int16_round_mmxext;
  77. }
  78. }
  79. if (EXTERNAL_SSE(cpu_flags)) {
  80. c->float_to_fixed24 = ff_float_to_fixed24_sse;
  81. }
  82. if (EXTERNAL_SSE2(cpu_flags)) {
  83. c->ac3_exponent_min = ff_ac3_exponent_min_sse2;
  84. c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_sse2;
  85. c->float_to_fixed24 = ff_float_to_fixed24_sse2;
  86. c->compute_mantissa_size = ff_ac3_compute_mantissa_size_sse2;
  87. c->extract_exponents = ff_ac3_extract_exponents_sse2;
  88. if (bit_exact) {
  89. c->apply_window_int16 = ff_apply_window_int16_sse2;
  90. }
  91. }
  92. if (EXTERNAL_SSE2_FAST(cpu_flags)) {
  93. c->ac3_lshift_int16 = ff_ac3_lshift_int16_sse2;
  94. c->ac3_rshift_int32 = ff_ac3_rshift_int32_sse2;
  95. if (!bit_exact) {
  96. c->apply_window_int16 = ff_apply_window_int16_round_sse2;
  97. }
  98. }
  99. if (EXTERNAL_SSSE3(cpu_flags)) {
  100. c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_ssse3;
  101. if (cpu_flags & AV_CPU_FLAG_ATOM) {
  102. c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
  103. } else {
  104. c->extract_exponents = ff_ac3_extract_exponents_ssse3;
  105. c->apply_window_int16 = ff_apply_window_int16_ssse3;
  106. }
  107. }
  108. }
  109. #define DOWNMIX_FUNC_OPT(ch, opt) \
  110. void ff_ac3_downmix_ ## ch ## _to_1_ ## opt(float **samples, \
  111. float **matrix, int len); \
  112. void ff_ac3_downmix_ ## ch ## _to_2_ ## opt(float **samples, \
  113. float **matrix, int len);
  114. #define DOWNMIX_FUNCS(opt) \
  115. DOWNMIX_FUNC_OPT(3, opt) \
  116. DOWNMIX_FUNC_OPT(4, opt) \
  117. DOWNMIX_FUNC_OPT(5, opt) \
  118. DOWNMIX_FUNC_OPT(6, opt)
  119. DOWNMIX_FUNCS(sse)
  120. DOWNMIX_FUNCS(avx)
  121. DOWNMIX_FUNCS(fma3)
  122. void ff_ac3dsp_set_downmix_x86(AC3DSPContext *c)
  123. {
  124. int cpu_flags = av_get_cpu_flags();
  125. #define SET_DOWNMIX(ch, suf, SUF) \
  126. if (ch == c->in_channels) { \
  127. if (EXTERNAL_ ## SUF (cpu_flags)) { \
  128. if (c->out_channels == 1) \
  129. c->downmix = ff_ac3_downmix_ ## ch ## _to_1_ ## suf; \
  130. else \
  131. c->downmix = ff_ac3_downmix_ ## ch ## _to_2_ ## suf; \
  132. } \
  133. }
  134. #define SET_DOWNMIX_ALL(suf, SUF) \
  135. SET_DOWNMIX(3, suf, SUF) \
  136. SET_DOWNMIX(4, suf, SUF) \
  137. SET_DOWNMIX(5, suf, SUF) \
  138. SET_DOWNMIX(6, suf, SUF)
  139. SET_DOWNMIX_ALL(sse, SSE)
  140. if (!(cpu_flags & AV_CPU_FLAG_AVXSLOW)) {
  141. SET_DOWNMIX_ALL(avx, AVX)
  142. SET_DOWNMIX_ALL(fma3, FMA3)
  143. }
  144. }