FFmpeg  4.4
ac3dsp_init.c
Go to the documentation of this file.
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 
22 #include "libavutil/attributes.h"
23 #include "libavutil/mem.h"
24 #include "libavutil/x86/asm.h"
25 #include "libavutil/x86/cpu.h"
26 #include "libavcodec/ac3.h"
27 #include "libavcodec/ac3dsp.h"
28 
29 void ff_ac3_exponent_min_mmx (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
30 void ff_ac3_exponent_min_mmxext(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
31 void ff_ac3_exponent_min_sse2 (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
32 
33 void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned int len);
34 void ff_float_to_fixed24_sse (int32_t *dst, const float *src, unsigned int len);
35 void ff_float_to_fixed24_sse2 (int32_t *dst, const float *src, unsigned int len);
36 
37 int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16]);
38 
39 void ff_ac3_extract_exponents_sse2 (uint8_t *exp, int32_t *coef, int nb_coefs);
40 void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs);
41 
43 {
45 
46  if (EXTERNAL_MMX(cpu_flags)) {
47  c->ac3_exponent_min = ff_ac3_exponent_min_mmx;
48  }
50  if (!bit_exact) {
51  c->float_to_fixed24 = ff_float_to_fixed24_3dnow;
52  }
53  }
55  c->ac3_exponent_min = ff_ac3_exponent_min_mmxext;
56  }
57  if (EXTERNAL_SSE(cpu_flags)) {
58  c->float_to_fixed24 = ff_float_to_fixed24_sse;
59  }
60  if (EXTERNAL_SSE2(cpu_flags)) {
61  c->ac3_exponent_min = ff_ac3_exponent_min_sse2;
62  c->float_to_fixed24 = ff_float_to_fixed24_sse2;
63  c->compute_mantissa_size = ff_ac3_compute_mantissa_size_sse2;
64  c->extract_exponents = ff_ac3_extract_exponents_sse2;
65  }
66 
68  if (!(cpu_flags & AV_CPU_FLAG_ATOM))
69  c->extract_exponents = ff_ac3_extract_exponents_ssse3;
70  }
71 }
72 
73 #define DOWNMIX_FUNC_OPT(ch, opt) \
74 void ff_ac3_downmix_ ## ch ## _to_1_ ## opt(float **samples, \
75  float **matrix, int len); \
76 void ff_ac3_downmix_ ## ch ## _to_2_ ## opt(float **samples, \
77  float **matrix, int len);
78 
79 #define DOWNMIX_FUNCS(opt) \
80  DOWNMIX_FUNC_OPT(3, opt) \
81  DOWNMIX_FUNC_OPT(4, opt) \
82  DOWNMIX_FUNC_OPT(5, opt) \
83  DOWNMIX_FUNC_OPT(6, opt)
84 
86 DOWNMIX_FUNCS(avx)
87 DOWNMIX_FUNCS(fma3)
88 
90 {
92 
93 #define SET_DOWNMIX(ch, suf, SUF) \
94  if (ch == c->in_channels) { \
95  if (EXTERNAL_ ## SUF (cpu_flags)) { \
96  if (c->out_channels == 1) \
97  c->downmix = ff_ac3_downmix_ ## ch ## _to_1_ ## suf; \
98  else \
99  c->downmix = ff_ac3_downmix_ ## ch ## _to_2_ ## suf; \
100  } \
101  }
102 
103 #define SET_DOWNMIX_ALL(suf, SUF) \
104  SET_DOWNMIX(3, suf, SUF) \
105  SET_DOWNMIX(4, suf, SUF) \
106  SET_DOWNMIX(5, suf, SUF) \
107  SET_DOWNMIX(6, suf, SUF)
108 
109  SET_DOWNMIX_ALL(sse, SSE)
110  if (!(cpu_flags & AV_CPU_FLAG_AVXSLOW)) {
111  SET_DOWNMIX_ALL(avx, AVX)
112  SET_DOWNMIX_ALL(fma3, FMA3)
113  }
114 }
Common code between the AC-3 encoder and decoder.
#define DOWNMIX_FUNCS(opt)
Definition: ac3dsp_init.c:79
void ff_ac3_exponent_min_sse2(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs)
void ff_ac3dsp_set_downmix_x86(AC3DSPContext *c)
Definition: ac3dsp_init.c:89
void ff_float_to_fixed24_sse2(int32_t *dst, const float *src, unsigned int len)
void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned int len)
av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
Definition: ac3dsp_init.c:42
void ff_float_to_fixed24_sse(int32_t *dst, const float *src, unsigned int len)
int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16])
void ff_ac3_exponent_min_mmx(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
void ff_ac3_extract_exponents_sse2(uint8_t *exp, int32_t *coef, int nb_coefs)
#define SET_DOWNMIX_ALL(suf, SUF)
void ff_ac3_exponent_min_mmxext(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:88
uint8_t
int32_t
static atomic_int cpu_flags
Definition: cpu.c:50
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:95
#define AV_CPU_FLAG_ATOM
Atom processor, some SSSE3 instructions are slower.
Definition: cpu.h:45
#define AV_CPU_FLAG_AVXSLOW
AVX supported, but slow when using YMM registers (e.g. Bulldozer)
Definition: cpu.h:50
int8_t exp
Definition: eval.c:72
Memory handling functions.
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
typedef void(RENAME(mix_any_func_type))
#define src
Definition: vp8dsp.c:255
int len
static double c[64]
#define EXTERNAL_SSE(flags)
Definition: cpu.h:58
#define EXTERNAL_MMXEXT(flags)
Definition: cpu.h:57
#define EXTERNAL_SSSE3(flags)
Definition: cpu.h:65
#define EXTERNAL_MMX(flags)
Definition: cpu.h:56
#define EXTERNAL_AMD3DNOW(flags)
Definition: cpu.h:54
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:59