FFmpeg
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/x86/asm.h"
24 #include "libavutil/x86/cpu.h"
25 #include "libavcodec/ac3dsp.h"
26 
27 void ff_ac3_exponent_min_sse2 (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
28 
29 void ff_float_to_fixed24_sse2 (int32_t *dst, const float *src, unsigned int len);
30 
31 int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16]);
32 
33 void ff_ac3_extract_exponents_sse2 (uint8_t *exp, int32_t *coef, int nb_coefs);
34 void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs);
35 
37 {
39 
40  if (EXTERNAL_SSE2(cpu_flags)) {
41  c->ac3_exponent_min = ff_ac3_exponent_min_sse2;
42  c->float_to_fixed24 = ff_float_to_fixed24_sse2;
43  c->compute_mantissa_size = ff_ac3_compute_mantissa_size_sse2;
44  c->extract_exponents = ff_ac3_extract_exponents_sse2;
45  }
46 
48  if (!(cpu_flags & AV_CPU_FLAG_ATOM))
49  c->extract_exponents = ff_ac3_extract_exponents_ssse3;
50  }
51 }
52 
53 #define DOWNMIX_FUNC_OPT(ch, opt) \
54 void ff_ac3_downmix_ ## ch ## _to_1_ ## opt(float **samples, \
55  float **matrix, int len); \
56 void ff_ac3_downmix_ ## ch ## _to_2_ ## opt(float **samples, \
57  float **matrix, int len);
58 
59 #define DOWNMIX_FUNCS(opt) \
60  DOWNMIX_FUNC_OPT(3, opt) \
61  DOWNMIX_FUNC_OPT(4, opt) \
62  DOWNMIX_FUNC_OPT(5, opt) \
63  DOWNMIX_FUNC_OPT(6, opt)
64 
66 DOWNMIX_FUNCS(avx)
67 DOWNMIX_FUNCS(fma3)
68 
70 {
72 
73 #define SET_DOWNMIX(ch, suf, SUF) \
74  if (ch == c->in_channels) { \
75  if (EXTERNAL_ ## SUF (cpu_flags)) { \
76  if (c->out_channels == 1) \
77  c->downmix = ff_ac3_downmix_ ## ch ## _to_1_ ## suf; \
78  else \
79  c->downmix = ff_ac3_downmix_ ## ch ## _to_2_ ## suf; \
80  } \
81  }
82 
83 #define SET_DOWNMIX_ALL(suf, SUF) \
84  SET_DOWNMIX(3, suf, SUF) \
85  SET_DOWNMIX(4, suf, SUF) \
86  SET_DOWNMIX(5, suf, SUF) \
87  SET_DOWNMIX(6, suf, SUF)
88 
89  SET_DOWNMIX_ALL(sse, SSE)
90  if (!(cpu_flags & AV_CPU_FLAG_AVXSLOW)) {
91  SET_DOWNMIX_ALL(avx, AVX)
92  SET_DOWNMIX_ALL(fma3, FMA3)
93  }
94 }
nb_coefs
static int nb_coefs(int length, int level, uint64_t sn)
Definition: af_afwtdn.c:513
cpu.h
ff_ac3_extract_exponents_ssse3
void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs)
ff_ac3_extract_exponents_sse2
void ff_ac3_extract_exponents_sse2(uint8_t *exp, int32_t *coef, int nb_coefs)
AC3DSPContext
Definition: ac3dsp.h:33
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:103
ff_ac3dsp_init_x86
av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c)
Definition: ac3dsp_init.c:36
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:52
av_cold
#define av_cold
Definition: attributes.h:90
SET_DOWNMIX_ALL
#define SET_DOWNMIX_ALL(suf, SUF)
ac3dsp.h
exp
int8_t exp
Definition: eval.c:72
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AV_CPU_FLAG_AVXSLOW
#define AV_CPU_FLAG_AVXSLOW
AVX supported, but slow when using YMM registers (e.g. Bulldozer)
Definition: cpu.h:48
asm.h
attributes.h
EXTERNAL_SSE2
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:59
len
int len
Definition: vorbis_enc_data.h:426
AV_CPU_FLAG_ATOM
#define AV_CPU_FLAG_ATOM
Atom processor, some SSSE3 instructions are slower.
Definition: cpu.h:43
ff_ac3_compute_mantissa_size_sse2
int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16])
ff_float_to_fixed24_sse2
void ff_float_to_fixed24_sse2(int32_t *dst, const float *src, unsigned int len)
ff_ac3_exponent_min_sse2
void ff_ac3_exponent_min_sse2(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
DOWNMIX_FUNCS
#define DOWNMIX_FUNCS(opt)
Definition: ac3dsp_init.c:59
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
int32_t
int32_t
Definition: audioconvert.c:56
sse
static int sse(MpegEncContext *s, const uint8_t *src1, const uint8_t *src2, int w, int h, int stride)
Definition: mpegvideo_enc.c:2636
EXTERNAL_SSSE3
#define EXTERNAL_SSSE3(flags)
Definition: cpu.h:65
ff_ac3dsp_set_downmix_x86
void ff_ac3dsp_set_downmix_x86(AC3DSPContext *c)
Definition: ac3dsp_init.c:69