2 * Copyright (c) 2014 James Almer
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavutil/attributes.h"
22 #include "libavcodec/flacdsp.h"
23 #include "libavutil/x86/cpu.h"
26 void ff_flac_lpc_32_sse4(int32_t *samples, const int coeffs[32], int order,
28 void ff_flac_lpc_32_xop(int32_t *samples, const int coeffs[32], int order,
31 void ff_flac_enc_lpc_16_sse4(int32_t *, const int32_t *, int, int, const int32_t *,int);
33 #define DECORRELATE_FUNCS(fmt, opt) \
34 void ff_flac_decorrelate_ls_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
35 int len, int shift); \
36 void ff_flac_decorrelate_rs_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
37 int len, int shift); \
38 void ff_flac_decorrelate_ms_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
39 int len, int shift); \
40 void ff_flac_decorrelate_indep2_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
41 int len, int shift); \
42 void ff_flac_decorrelate_indep4_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
43 int len, int shift); \
44 void ff_flac_decorrelate_indep6_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
45 int len, int shift); \
46 void ff_flac_decorrelate_indep8_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \
49 DECORRELATE_FUNCS(16, sse2);
50 DECORRELATE_FUNCS(16, avx);
51 DECORRELATE_FUNCS(32, sse2);
52 DECORRELATE_FUNCS(32, avx);
54 av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt, int channels,
58 int cpu_flags = av_get_cpu_flags();
60 #if CONFIG_FLAC_DECODER
61 if (EXTERNAL_SSE2(cpu_flags)) {
62 if (fmt == AV_SAMPLE_FMT_S16) {
64 c->decorrelate[0] = ff_flac_decorrelate_indep2_16_sse2;
65 else if (channels == 4)
66 c->decorrelate[0] = ff_flac_decorrelate_indep4_16_sse2;
67 else if (channels == 6)
68 c->decorrelate[0] = ff_flac_decorrelate_indep6_16_sse2;
69 else if (ARCH_X86_64 && channels == 8)
70 c->decorrelate[0] = ff_flac_decorrelate_indep8_16_sse2;
71 c->decorrelate[1] = ff_flac_decorrelate_ls_16_sse2;
72 c->decorrelate[2] = ff_flac_decorrelate_rs_16_sse2;
73 c->decorrelate[3] = ff_flac_decorrelate_ms_16_sse2;
74 } else if (fmt == AV_SAMPLE_FMT_S32) {
76 c->decorrelate[0] = ff_flac_decorrelate_indep2_32_sse2;
77 else if (channels == 4)
78 c->decorrelate[0] = ff_flac_decorrelate_indep4_32_sse2;
79 else if (channels == 6)
80 c->decorrelate[0] = ff_flac_decorrelate_indep6_32_sse2;
81 else if (ARCH_X86_64 && channels == 8)
82 c->decorrelate[0] = ff_flac_decorrelate_indep8_32_sse2;
83 c->decorrelate[1] = ff_flac_decorrelate_ls_32_sse2;
84 c->decorrelate[2] = ff_flac_decorrelate_rs_32_sse2;
85 c->decorrelate[3] = ff_flac_decorrelate_ms_32_sse2;
88 if (EXTERNAL_SSE4(cpu_flags)) {
89 c->lpc32 = ff_flac_lpc_32_sse4;
91 if (EXTERNAL_AVX(cpu_flags)) {
92 if (fmt == AV_SAMPLE_FMT_S16) {
93 if (ARCH_X86_64 && channels == 8)
94 c->decorrelate[0] = ff_flac_decorrelate_indep8_16_avx;
95 } else if (fmt == AV_SAMPLE_FMT_S32) {
97 c->decorrelate[0] = ff_flac_decorrelate_indep4_32_avx;
98 else if (channels == 6)
99 c->decorrelate[0] = ff_flac_decorrelate_indep6_32_avx;
100 else if (ARCH_X86_64 && channels == 8)
101 c->decorrelate[0] = ff_flac_decorrelate_indep8_32_avx;
104 if (EXTERNAL_XOP(cpu_flags)) {
105 c->lpc32 = ff_flac_lpc_32_xop;
109 #if CONFIG_FLAC_ENCODER
110 if (EXTERNAL_SSE4(cpu_flags)) {
112 c->lpc16_encode = ff_flac_enc_lpc_16_sse4;
115 #endif /* HAVE_X86ASM */