1 |
|
|
/* |
2 |
|
|
* Copyright (c) 2014 James Almer |
3 |
|
|
* |
4 |
|
|
* This file is part of FFmpeg. |
5 |
|
|
* |
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. |
10 |
|
|
* |
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. |
15 |
|
|
* |
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 |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include "libavcodec/flacdsp.h" |
22 |
|
|
#include "libavutil/x86/cpu.h" |
23 |
|
|
#include "config.h" |
24 |
|
|
|
25 |
|
|
void ff_flac_lpc_32_sse4(int32_t *samples, const int coeffs[32], int order, |
26 |
|
|
int qlevel, int len); |
27 |
|
|
void ff_flac_lpc_32_xop(int32_t *samples, const int coeffs[32], int order, |
28 |
|
|
int qlevel, int len); |
29 |
|
|
|
30 |
|
|
void ff_flac_enc_lpc_16_sse4(int32_t *, const int32_t *, int, int, const int32_t *,int); |
31 |
|
|
|
32 |
|
|
#define DECORRELATE_FUNCS(fmt, opt) \ |
33 |
|
|
void ff_flac_decorrelate_ls_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \ |
34 |
|
|
int len, int shift); \ |
35 |
|
|
void ff_flac_decorrelate_rs_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \ |
36 |
|
|
int len, int shift); \ |
37 |
|
|
void ff_flac_decorrelate_ms_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \ |
38 |
|
|
int len, int shift); \ |
39 |
|
|
void ff_flac_decorrelate_indep2_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \ |
40 |
|
|
int len, int shift); \ |
41 |
|
|
void ff_flac_decorrelate_indep4_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \ |
42 |
|
|
int len, int shift); \ |
43 |
|
|
void ff_flac_decorrelate_indep6_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \ |
44 |
|
|
int len, int shift); \ |
45 |
|
|
void ff_flac_decorrelate_indep8_##fmt##_##opt(uint8_t **out, int32_t **in, int channels, \ |
46 |
|
|
int len, int shift) |
47 |
|
|
|
48 |
|
|
DECORRELATE_FUNCS(16, sse2); |
49 |
|
|
DECORRELATE_FUNCS(16, avx); |
50 |
|
|
DECORRELATE_FUNCS(32, sse2); |
51 |
|
|
DECORRELATE_FUNCS(32, avx); |
52 |
|
|
|
53 |
|
5979 |
av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt, int channels, |
54 |
|
|
int bps) |
55 |
|
|
{ |
56 |
|
|
#if HAVE_X86ASM |
57 |
|
5979 |
int cpu_flags = av_get_cpu_flags(); |
58 |
|
|
|
59 |
|
|
#if CONFIG_FLAC_DECODER |
60 |
✓✓ |
5979 |
if (EXTERNAL_SSE2(cpu_flags)) { |
61 |
✓✓ |
3635 |
if (fmt == AV_SAMPLE_FMT_S16) { |
62 |
✓✓ |
3287 |
if (channels == 2) |
63 |
|
1650 |
c->decorrelate[0] = ff_flac_decorrelate_indep2_16_sse2; |
64 |
✓✓ |
1637 |
else if (channels == 4) |
65 |
|
9 |
c->decorrelate[0] = ff_flac_decorrelate_indep4_16_sse2; |
66 |
✓✓ |
1628 |
else if (channels == 6) |
67 |
|
813 |
c->decorrelate[0] = ff_flac_decorrelate_indep6_16_sse2; |
68 |
✓✓ |
815 |
else if (ARCH_X86_64 && channels == 8) |
69 |
|
9 |
c->decorrelate[0] = ff_flac_decorrelate_indep8_16_sse2; |
70 |
|
3287 |
c->decorrelate[1] = ff_flac_decorrelate_ls_16_sse2; |
71 |
|
3287 |
c->decorrelate[2] = ff_flac_decorrelate_rs_16_sse2; |
72 |
|
3287 |
c->decorrelate[3] = ff_flac_decorrelate_ms_16_sse2; |
73 |
✓✗ |
348 |
} else if (fmt == AV_SAMPLE_FMT_S32) { |
74 |
✓✓ |
348 |
if (channels == 2) |
75 |
|
321 |
c->decorrelate[0] = ff_flac_decorrelate_indep2_32_sse2; |
76 |
✓✓ |
27 |
else if (channels == 4) |
77 |
|
9 |
c->decorrelate[0] = ff_flac_decorrelate_indep4_32_sse2; |
78 |
✓✓ |
18 |
else if (channels == 6) |
79 |
|
9 |
c->decorrelate[0] = ff_flac_decorrelate_indep6_32_sse2; |
80 |
✓✗ |
9 |
else if (ARCH_X86_64 && channels == 8) |
81 |
|
9 |
c->decorrelate[0] = ff_flac_decorrelate_indep8_32_sse2; |
82 |
|
348 |
c->decorrelate[1] = ff_flac_decorrelate_ls_32_sse2; |
83 |
|
348 |
c->decorrelate[2] = ff_flac_decorrelate_rs_32_sse2; |
84 |
|
348 |
c->decorrelate[3] = ff_flac_decorrelate_ms_32_sse2; |
85 |
|
|
} |
86 |
|
|
} |
87 |
✓✓ |
5979 |
if (EXTERNAL_SSE4(cpu_flags)) { |
88 |
|
3605 |
c->lpc32 = ff_flac_lpc_32_sse4; |
89 |
|
|
} |
90 |
✓✓ |
5979 |
if (EXTERNAL_AVX(cpu_flags)) { |
91 |
✓✓ |
3575 |
if (fmt == AV_SAMPLE_FMT_S16) { |
92 |
✓✓ |
3257 |
if (ARCH_X86_64 && channels == 8) |
93 |
|
3 |
c->decorrelate[0] = ff_flac_decorrelate_indep8_16_avx; |
94 |
✓✗ |
318 |
} else if (fmt == AV_SAMPLE_FMT_S32) { |
95 |
✓✓ |
318 |
if (channels == 4) |
96 |
|
3 |
c->decorrelate[0] = ff_flac_decorrelate_indep4_32_avx; |
97 |
✓✓ |
315 |
else if (channels == 6) |
98 |
|
3 |
c->decorrelate[0] = ff_flac_decorrelate_indep6_32_avx; |
99 |
✓✓ |
312 |
else if (ARCH_X86_64 && channels == 8) |
100 |
|
3 |
c->decorrelate[0] = ff_flac_decorrelate_indep8_32_avx; |
101 |
|
|
} |
102 |
|
|
} |
103 |
✗✓ |
5979 |
if (EXTERNAL_XOP(cpu_flags)) { |
104 |
|
|
c->lpc32 = ff_flac_lpc_32_xop; |
105 |
|
|
} |
106 |
|
|
#endif |
107 |
|
|
|
108 |
|
|
#if CONFIG_FLAC_ENCODER |
109 |
✓✓ |
5979 |
if (EXTERNAL_SSE4(cpu_flags)) { |
110 |
|
|
if (CONFIG_GPL) |
111 |
|
3605 |
c->lpc16_encode = ff_flac_enc_lpc_16_sse4; |
112 |
|
|
} |
113 |
|
|
#endif |
114 |
|
|
#endif /* HAVE_X86ASM */ |
115 |
|
5979 |
} |