00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/mem.h"
00023 #include "libavutil/x86/asm.h"
00024 #include "libavutil/x86/cpu.h"
00025 #include "dsputil_mmx.h"
00026 #include "libavcodec/ac3.h"
00027 #include "libavcodec/ac3dsp.h"
00028
00029 extern void ff_ac3_exponent_min_mmx (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
00030 extern void ff_ac3_exponent_min_mmxext(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
00031 extern void ff_ac3_exponent_min_sse2 (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
00032
00033 extern int ff_ac3_max_msb_abs_int16_mmx (const int16_t *src, int len);
00034 extern int ff_ac3_max_msb_abs_int16_mmx2 (const int16_t *src, int len);
00035 extern int ff_ac3_max_msb_abs_int16_sse2 (const int16_t *src, int len);
00036 extern int ff_ac3_max_msb_abs_int16_ssse3(const int16_t *src, int len);
00037
00038 extern void ff_ac3_lshift_int16_mmx (int16_t *src, unsigned int len, unsigned int shift);
00039 extern void ff_ac3_lshift_int16_sse2(int16_t *src, unsigned int len, unsigned int shift);
00040
00041 extern void ff_ac3_rshift_int32_mmx (int32_t *src, unsigned int len, unsigned int shift);
00042 extern void ff_ac3_rshift_int32_sse2(int32_t *src, unsigned int len, unsigned int shift);
00043
00044 extern void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned int len);
00045 extern void ff_float_to_fixed24_sse (int32_t *dst, const float *src, unsigned int len);
00046 extern void ff_float_to_fixed24_sse2 (int32_t *dst, const float *src, unsigned int len);
00047
00048 extern int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16]);
00049
00050 extern void ff_ac3_extract_exponents_3dnow(uint8_t *exp, int32_t *coef, int nb_coefs);
00051 extern void ff_ac3_extract_exponents_sse2 (uint8_t *exp, int32_t *coef, int nb_coefs);
00052 extern void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs);
00053
00054 #if HAVE_SSE_INLINE
00055
00056 #define IF1(x) x
00057 #define IF0(x)
00058
00059 #define MIX5(mono, stereo) \
00060 __asm__ volatile ( \
00061 "movss 0(%2), %%xmm5 \n" \
00062 "movss 8(%2), %%xmm6 \n" \
00063 "movss 24(%2), %%xmm7 \n" \
00064 "shufps $0, %%xmm5, %%xmm5 \n" \
00065 "shufps $0, %%xmm6, %%xmm6 \n" \
00066 "shufps $0, %%xmm7, %%xmm7 \n" \
00067 "1: \n" \
00068 "movaps (%0, %1), %%xmm0 \n" \
00069 "movaps 0x400(%0, %1), %%xmm1 \n" \
00070 "movaps 0x800(%0, %1), %%xmm2 \n" \
00071 "movaps 0xc00(%0, %1), %%xmm3 \n" \
00072 "movaps 0x1000(%0, %1), %%xmm4 \n" \
00073 "mulps %%xmm5, %%xmm0 \n" \
00074 "mulps %%xmm6, %%xmm1 \n" \
00075 "mulps %%xmm5, %%xmm2 \n" \
00076 "mulps %%xmm7, %%xmm3 \n" \
00077 "mulps %%xmm7, %%xmm4 \n" \
00078 stereo("addps %%xmm1, %%xmm0 \n") \
00079 "addps %%xmm1, %%xmm2 \n" \
00080 "addps %%xmm3, %%xmm0 \n" \
00081 "addps %%xmm4, %%xmm2 \n" \
00082 mono("addps %%xmm2, %%xmm0 \n") \
00083 "movaps %%xmm0, (%0, %1) \n" \
00084 stereo("movaps %%xmm2, 0x400(%0, %1) \n") \
00085 "add $16, %0 \n" \
00086 "jl 1b \n" \
00087 : "+&r"(i) \
00088 : "r"(samples[0] + len), "r"(matrix) \
00089 : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \
00090 "%xmm4", "%xmm5", "%xmm6", "%xmm7",) \
00091 "memory" \
00092 );
00093
00094 #define MIX_MISC(stereo) \
00095 __asm__ volatile ( \
00096 "1: \n" \
00097 "movaps (%3, %0), %%xmm0 \n" \
00098 stereo("movaps %%xmm0, %%xmm1 \n") \
00099 "mulps %%xmm4, %%xmm0 \n" \
00100 stereo("mulps %%xmm5, %%xmm1 \n") \
00101 "lea 1024(%3, %0), %1 \n" \
00102 "mov %5, %2 \n" \
00103 "2: \n" \
00104 "movaps (%1), %%xmm2 \n" \
00105 stereo("movaps %%xmm2, %%xmm3 \n") \
00106 "mulps (%4, %2), %%xmm2 \n" \
00107 stereo("mulps 16(%4, %2), %%xmm3 \n") \
00108 "addps %%xmm2, %%xmm0 \n" \
00109 stereo("addps %%xmm3, %%xmm1 \n") \
00110 "add $1024, %1 \n" \
00111 "add $32, %2 \n" \
00112 "jl 2b \n" \
00113 "movaps %%xmm0, (%3, %0) \n" \
00114 stereo("movaps %%xmm1, 1024(%3, %0) \n") \
00115 "add $16, %0 \n" \
00116 "jl 1b \n" \
00117 : "+&r"(i), "=&r"(j), "=&r"(k) \
00118 : "r"(samples[0] + len), "r"(matrix_simd + in_ch), \
00119 "g"((intptr_t) - 32 * (in_ch - 1)) \
00120 : "memory" \
00121 );
00122
00123 static void ac3_downmix_sse(float (*samples)[256], float (*matrix)[2],
00124 int out_ch, int in_ch, int len)
00125 {
00126 int (*matrix_cmp)[2] = (int(*)[2])matrix;
00127 intptr_t i, j, k;
00128
00129 i = -len * sizeof(float);
00130 if (in_ch == 5 && out_ch == 2 &&
00131 !(matrix_cmp[0][1] | matrix_cmp[2][0] |
00132 matrix_cmp[3][1] | matrix_cmp[4][0] |
00133 (matrix_cmp[1][0] ^ matrix_cmp[1][1]) |
00134 (matrix_cmp[0][0] ^ matrix_cmp[2][1]))) {
00135 MIX5(IF0, IF1);
00136 } else if (in_ch == 5 && out_ch == 1 &&
00137 matrix_cmp[0][0] == matrix_cmp[2][0] &&
00138 matrix_cmp[3][0] == matrix_cmp[4][0]) {
00139 MIX5(IF1, IF0);
00140 } else {
00141 DECLARE_ALIGNED(16, float, matrix_simd)[AC3_MAX_CHANNELS][2][4];
00142 j = 2 * in_ch * sizeof(float);
00143 __asm__ volatile (
00144 "1: \n"
00145 "sub $8, %0 \n"
00146 "movss (%2, %0), %%xmm4 \n"
00147 "movss 4(%2, %0), %%xmm5 \n"
00148 "shufps $0, %%xmm4, %%xmm4 \n"
00149 "shufps $0, %%xmm5, %%xmm5 \n"
00150 "movaps %%xmm4, (%1, %0, 4) \n"
00151 "movaps %%xmm5, 16(%1, %0, 4) \n"
00152 "jg 1b \n"
00153 : "+&r"(j)
00154 : "r"(matrix_simd), "r"(matrix)
00155 : "memory"
00156 );
00157 if (out_ch == 2) {
00158 MIX_MISC(IF1);
00159 } else {
00160 MIX_MISC(IF0);
00161 }
00162 }
00163 }
00164
00165 #endif
00166
00167 av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
00168 {
00169 int mm_flags = av_get_cpu_flags();
00170
00171 if (EXTERNAL_MMX(mm_flags)) {
00172 c->ac3_exponent_min = ff_ac3_exponent_min_mmx;
00173 c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx;
00174 c->ac3_lshift_int16 = ff_ac3_lshift_int16_mmx;
00175 c->ac3_rshift_int32 = ff_ac3_rshift_int32_mmx;
00176 }
00177 if (EXTERNAL_AMD3DNOW(mm_flags)) {
00178 c->extract_exponents = ff_ac3_extract_exponents_3dnow;
00179 if (!bit_exact) {
00180 c->float_to_fixed24 = ff_float_to_fixed24_3dnow;
00181 }
00182 }
00183 if (EXTERNAL_MMXEXT(mm_flags)) {
00184 c->ac3_exponent_min = ff_ac3_exponent_min_mmxext;
00185 c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx2;
00186 }
00187 if (EXTERNAL_SSE(mm_flags)) {
00188 c->float_to_fixed24 = ff_float_to_fixed24_sse;
00189 }
00190 if (EXTERNAL_SSE2(mm_flags)) {
00191 c->ac3_exponent_min = ff_ac3_exponent_min_sse2;
00192 c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_sse2;
00193 c->float_to_fixed24 = ff_float_to_fixed24_sse2;
00194 c->compute_mantissa_size = ff_ac3_compute_mantissa_size_sse2;
00195 c->extract_exponents = ff_ac3_extract_exponents_sse2;
00196 if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
00197 c->ac3_lshift_int16 = ff_ac3_lshift_int16_sse2;
00198 c->ac3_rshift_int32 = ff_ac3_rshift_int32_sse2;
00199 }
00200 }
00201 if (EXTERNAL_SSSE3(mm_flags)) {
00202 c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_ssse3;
00203 if (!(mm_flags & AV_CPU_FLAG_ATOM)) {
00204 c->extract_exponents = ff_ac3_extract_exponents_ssse3;
00205 }
00206 }
00207
00208 #if HAVE_SSE_INLINE
00209 if (INLINE_SSE(mm_flags)) {
00210 c->downmix = ac3_downmix_sse;
00211 }
00212 #endif
00213 }