FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 int ff_ac3_max_msb_abs_int16_mmx (const int16_t *src, int len);
34 int ff_ac3_max_msb_abs_int16_mmxext(const int16_t *src, int len);
35 int ff_ac3_max_msb_abs_int16_sse2 (const int16_t *src, int len);
36 int ff_ac3_max_msb_abs_int16_ssse3(const int16_t *src, int len);
37 
38 void ff_ac3_lshift_int16_mmx (int16_t *src, unsigned int len, unsigned int shift);
39 void ff_ac3_lshift_int16_sse2(int16_t *src, unsigned int len, unsigned int shift);
40 
41 void ff_ac3_rshift_int32_mmx (int32_t *src, unsigned int len, unsigned int shift);
42 void ff_ac3_rshift_int32_sse2(int32_t *src, unsigned int len, unsigned int shift);
43 
44 void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned int len);
45 void ff_float_to_fixed24_sse (int32_t *dst, const float *src, unsigned int len);
46 void ff_float_to_fixed24_sse2 (int32_t *dst, const float *src, unsigned int len);
47 
48 int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16]);
49 
50 void ff_ac3_extract_exponents_sse2 (uint8_t *exp, int32_t *coef, int nb_coefs);
51 void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs);
52 
53 void ff_apply_window_int16_round_mmxext(int16_t *output, const int16_t *input,
54  const int16_t *window, unsigned int len);
55 void ff_apply_window_int16_round_sse2(int16_t *output, const int16_t *input,
56  const int16_t *window, unsigned int len);
57 void ff_apply_window_int16_mmxext(int16_t *output, const int16_t *input,
58  const int16_t *window, unsigned int len);
59 void ff_apply_window_int16_sse2(int16_t *output, const int16_t *input,
60  const int16_t *window, unsigned int len);
61 void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input,
62  const int16_t *window, unsigned int len);
63 void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
64  const int16_t *window, unsigned int len);
65 
67 {
69 
70  if (EXTERNAL_MMX(cpu_flags)) {
75  }
76  if (EXTERNAL_AMD3DNOW(cpu_flags)) {
77  if (!bit_exact) {
79  }
80  }
81  if (EXTERNAL_MMXEXT(cpu_flags)) {
84  if (bit_exact) {
86  } else {
88  }
89  }
90  if (EXTERNAL_SSE(cpu_flags)) {
92  }
93  if (EXTERNAL_SSE2(cpu_flags)) {
99  if (bit_exact) {
101  }
102  }
103 
104  if (EXTERNAL_SSE2_FAST(cpu_flags)) {
107  if (!bit_exact) {
109  }
110  }
111 
112  if (EXTERNAL_SSSE3(cpu_flags)) {
114  if (cpu_flags & AV_CPU_FLAG_ATOM) {
116  } else {
119  }
120  }
121 }
122 
123 #define DOWNMIX_FUNC_OPT(ch, opt) \
124 void ff_ac3_downmix_ ## ch ## _to_1_ ## opt(float **samples, \
125  float **matrix, int len); \
126 void ff_ac3_downmix_ ## ch ## _to_2_ ## opt(float **samples, \
127  float **matrix, int len);
128 
129 #define DOWNMIX_FUNCS(opt) \
130  DOWNMIX_FUNC_OPT(3, opt) \
131  DOWNMIX_FUNC_OPT(4, opt) \
132  DOWNMIX_FUNC_OPT(5, opt) \
133  DOWNMIX_FUNC_OPT(6, opt)
134 
136 DOWNMIX_FUNCS(avx)
137 DOWNMIX_FUNCS(fma3)
138 
140 {
141  int cpu_flags = av_get_cpu_flags();
142 
143 #define SET_DOWNMIX(ch, suf, SUF) \
144  if (ch == c->in_channels) { \
145  if (EXTERNAL_ ## SUF (cpu_flags)) { \
146  if (c->out_channels == 1) \
147  c->downmix = ff_ac3_downmix_ ## ch ## _to_1_ ## suf; \
148  else \
149  c->downmix = ff_ac3_downmix_ ## ch ## _to_2_ ## suf; \
150  } \
151  }
152 
153 #define SET_DOWNMIX_ALL(suf, SUF) \
154  SET_DOWNMIX(3, suf, SUF) \
155  SET_DOWNMIX(4, suf, SUF) \
156  SET_DOWNMIX(5, suf, SUF) \
157  SET_DOWNMIX(6, suf, SUF)
158 
159  SET_DOWNMIX_ALL(sse, SSE)
160  if (!(cpu_flags & AV_CPU_FLAG_AVXSLOW)) {
161  SET_DOWNMIX_ALL(avx, AVX)
162  SET_DOWNMIX_ALL(fma3, FMA3)
163  }
164 }
#define EXTERNAL_MMX(flags)
Definition: cpu.h:56
void(* ac3_rshift_int32)(int32_t *src, unsigned int len, unsigned int shift)
Right-shift each value in an array of int32_t by a specified amount.
Definition: ac3dsp.h:76
void(* float_to_fixed24)(int32_t *dst, const float *src, unsigned int len)
Convert an array of float in range [-1.0,1.0] to int32_t with range [-(1<<24),(1<<24)].
Definition: ac3dsp.h:89
static int shift(int a, int b)
Definition: sonic.c:82
int ff_ac3_max_msb_abs_int16_sse2(const int16_t *src, int len)
Memory handling functions.
int ff_ac3_max_msb_abs_int16_mmx(const int16_t *src, int len)
void ff_ac3dsp_set_downmix_x86(AC3DSPContext *c)
Definition: ac3dsp_init.c:139
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
static atomic_int cpu_flags
Definition: cpu.c:50
#define EXTERNAL_SSE(flags)
Definition: cpu.h:58
void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned int len)
#define src
Definition: vp8dsp.c:254
Macro definitions for various function/variable attributes.
void ff_float_to_fixed24_sse2(int32_t *dst, const float *src, unsigned int len)
uint8_t
#define av_cold
Definition: attributes.h:82
void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs)
int(* ac3_max_msb_abs_int16)(const int16_t *src, int len)
Calculate the maximum MSB of the absolute value of each element in an array of int16_t.
Definition: ac3dsp.h:54
void ff_ac3_rshift_int32_mmx(int32_t *src, unsigned int len, unsigned int shift)
void ff_ac3_lshift_int16_mmx(int16_t *src, unsigned int len, unsigned int shift)
#define DOWNMIX_FUNCS(opt)
Definition: ac3dsp_init.c:129
void ff_ac3_lshift_int16_sse2(int16_t *src, unsigned int len, unsigned int shift)
#define AV_CPU_FLAG_ATOM
Atom processor, some SSSE3 instructions are slower.
Definition: cpu.h:45
#define EXTERNAL_SSE2_FAST(flags)
Definition: cpu.h:60
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:59
void ff_ac3_exponent_min_sse2(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input, const int16_t *window, unsigned int len)
av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
Definition: ac3dsp_init.c:66
void ff_apply_window_int16_round_mmxext(int16_t *output, const int16_t *input, const int16_t *window, unsigned int len)
void ff_ac3_rshift_int32_sse2(int32_t *src, unsigned int len, unsigned int shift)
int8_t exp
Definition: eval.c:72
static SDL_Window * window
Definition: ffplay.c:362
void ff_apply_window_int16_round_sse2(int16_t *output, const int16_t *input, const int16_t *window, unsigned int len)
int ff_ac3_max_msb_abs_int16_ssse3(const int16_t *src, int len)
int32_t
void ff_apply_window_int16_sse2(int16_t *output, const int16_t *input, const int16_t *window, unsigned int len)
void(* extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs)
Definition: ac3dsp.h:127
void ff_ac3_exponent_min_mmx(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
void ff_ac3_exponent_min_mmxext(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
void ff_apply_window_int16_mmxext(int16_t *output, const int16_t *input, const int16_t *window, unsigned int len)
#define AV_CPU_FLAG_AVXSLOW
AVX supported, but slow when using YMM registers (e.g. Bulldozer)
Definition: cpu.h:50
void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input, const int16_t *window, unsigned int len)
int ff_ac3_max_msb_abs_int16_mmxext(const int16_t *src, int len)
void ff_float_to_fixed24_sse(int32_t *dst, const float *src, unsigned int len)
#define EXTERNAL_SSSE3(flags)
Definition: cpu.h:65
void(* apply_window_int16)(int16_t *output, const int16_t *input, const int16_t *window, unsigned int len)
Apply symmetric window in 16-bit fixed-point.
Definition: ac3dsp.h:151
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:93
int(* compute_mantissa_size)(uint16_t mant_cnt[6][16])
Calculate the number of bits needed to encode a set of mantissas.
Definition: ac3dsp.h:125
#define EXTERNAL_MMXEXT(flags)
Definition: cpu.h:57
static double c[64]
#define SET_DOWNMIX_ALL(suf, SUF)
void(* ac3_lshift_int16)(int16_t *src, unsigned int len, unsigned int shift)
Left-shift each value in an array of int16_t by a specified amount.
Definition: ac3dsp.h:65
void(* ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
Set each encoded exponent in a block to the minimum of itself and the exponents in the same frequency...
Definition: ac3dsp.h:43
int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16])
int len
void ff_ac3_extract_exponents_sse2(uint8_t *exp, int32_t *coef, int nb_coefs)
#define EXTERNAL_AMD3DNOW(flags)
Definition: cpu.h:54
Common code between the AC-3 encoder and decoder.