Commit | Line | Data |
---|---|---|
2ba45a60 DM |
1 | /* |
2 | * Copyright (C) 2012 Michael Niedermayer (michaelni@gmx.at) | |
3 | * | |
4 | * This file is part of libswresample | |
5 | * | |
6 | * libswresample 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 | * libswresample 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 libswresample; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include "libavutil/x86/cpu.h" | |
22 | #include "libswresample/swresample_internal.h" | |
23 | #include "libswresample/audioconvert.h" | |
24 | ||
25 | #define PROTO(pre, in, out, cap) void ff ## pre ## in## _to_ ##out## _a_ ##cap(uint8_t **dst, const uint8_t **src, int len); | |
26 | #define PROTO2(pre, out, cap) PROTO(pre, int16, out, cap) PROTO(pre, int32, out, cap) PROTO(pre, float, out, cap) | |
27 | #define PROTO3(pre, cap) PROTO2(pre, int16, cap) PROTO2(pre, int32, cap) PROTO2(pre, float, cap) | |
f6fa7814 | 28 | #define PROTO4(pre) PROTO3(pre, mmx) PROTO3(pre, sse) PROTO3(pre, sse2) PROTO3(pre, ssse3) PROTO3(pre, sse4) PROTO3(pre, avx) PROTO3(pre, avx2) |
2ba45a60 DM |
29 | PROTO4(_) |
30 | PROTO4(_pack_2ch_) | |
31 | PROTO4(_pack_6ch_) | |
32 | PROTO4(_unpack_2ch_) | |
33 | ||
34 | av_cold void swri_audio_convert_init_x86(struct AudioConvert *ac, | |
35 | enum AVSampleFormat out_fmt, | |
36 | enum AVSampleFormat in_fmt, | |
37 | int channels){ | |
38 | int mm_flags = av_get_cpu_flags(); | |
39 | ||
40 | ac->simd_f= NULL; | |
41 | ||
42 | //FIXME add memcpy case | |
43 | ||
44 | #define MULTI_CAPS_FUNC(flag, cap) \ | |
45 | if (EXTERNAL_##flag(mm_flags)) {\ | |
46 | if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S16 || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16P)\ | |
47 | ac->simd_f = ff_int16_to_int32_a_ ## cap;\ | |
48 | if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S32P)\ | |
49 | ac->simd_f = ff_int32_to_int16_a_ ## cap;\ | |
50 | } | |
51 | ||
52 | MULTI_CAPS_FUNC(MMX, mmx) | |
53 | MULTI_CAPS_FUNC(SSE2, sse2) | |
54 | ||
55 | if(EXTERNAL_MMX(mm_flags)) { | |
56 | if(channels == 6) { | |
57 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P) | |
58 | ac->simd_f = ff_pack_6ch_float_to_float_a_mmx; | |
59 | } | |
60 | } | |
f6fa7814 DM |
61 | if(EXTERNAL_SSE(mm_flags)) { |
62 | if(channels == 6) { | |
63 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P) | |
64 | ac->simd_f = ff_pack_6ch_float_to_float_a_sse; | |
65 | } | |
66 | } | |
2ba45a60 DM |
67 | if(EXTERNAL_SSE2(mm_flags)) { |
68 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32P) | |
69 | ac->simd_f = ff_int32_to_float_a_sse2; | |
70 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S16 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16P) | |
71 | ac->simd_f = ff_int16_to_float_a_sse2; | |
72 | if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLTP) | |
73 | ac->simd_f = ff_float_to_int32_a_sse2; | |
74 | if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_FLTP) | |
75 | ac->simd_f = ff_float_to_int16_a_sse2; | |
76 | ||
77 | if(channels == 2) { | |
78 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P) | |
79 | ac->simd_f = ff_pack_2ch_int32_to_int32_a_sse2; | |
80 | if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S16P) | |
81 | ac->simd_f = ff_pack_2ch_int16_to_int16_a_sse2; | |
82 | if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S16P) | |
83 | ac->simd_f = ff_pack_2ch_int16_to_int32_a_sse2; | |
84 | if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S32P) | |
85 | ac->simd_f = ff_pack_2ch_int32_to_int16_a_sse2; | |
86 | ||
87 | if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S32) | |
88 | ac->simd_f = ff_unpack_2ch_int32_to_int32_a_sse2; | |
89 | if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S16) | |
90 | ac->simd_f = ff_unpack_2ch_int16_to_int16_a_sse2; | |
91 | if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16) | |
92 | ac->simd_f = ff_unpack_2ch_int16_to_int32_a_sse2; | |
93 | if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S32) | |
94 | ac->simd_f = ff_unpack_2ch_int32_to_int16_a_sse2; | |
95 | ||
96 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P) | |
97 | ac->simd_f = ff_pack_2ch_int32_to_float_a_sse2; | |
98 | if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP) | |
99 | ac->simd_f = ff_pack_2ch_float_to_int32_a_sse2; | |
100 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S16P) | |
101 | ac->simd_f = ff_pack_2ch_int16_to_float_a_sse2; | |
102 | if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLTP) | |
103 | ac->simd_f = ff_pack_2ch_float_to_int16_a_sse2; | |
104 | if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32) | |
105 | ac->simd_f = ff_unpack_2ch_int32_to_float_a_sse2; | |
106 | if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT) | |
107 | ac->simd_f = ff_unpack_2ch_float_to_int32_a_sse2; | |
108 | if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16) | |
109 | ac->simd_f = ff_unpack_2ch_int16_to_float_a_sse2; | |
110 | if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_FLT) | |
111 | ac->simd_f = ff_unpack_2ch_float_to_int16_a_sse2; | |
112 | } | |
f6fa7814 DM |
113 | if(channels == 6) { |
114 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P) | |
115 | ac->simd_f = ff_pack_6ch_int32_to_float_a_sse2; | |
116 | if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP) | |
117 | ac->simd_f = ff_pack_6ch_float_to_int32_a_sse2; | |
118 | } | |
2ba45a60 DM |
119 | } |
120 | if(EXTERNAL_SSSE3(mm_flags)) { | |
121 | if(channels == 2) { | |
122 | if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S16) | |
123 | ac->simd_f = ff_unpack_2ch_int16_to_int16_a_ssse3; | |
124 | if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16) | |
125 | ac->simd_f = ff_unpack_2ch_int16_to_int32_a_ssse3; | |
126 | if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16) | |
127 | ac->simd_f = ff_unpack_2ch_int16_to_float_a_ssse3; | |
128 | } | |
129 | } | |
2ba45a60 DM |
130 | if(EXTERNAL_AVX(mm_flags)) { |
131 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32P) | |
132 | ac->simd_f = ff_int32_to_float_a_avx; | |
133 | if(channels == 6) { | |
134 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P) | |
135 | ac->simd_f = ff_pack_6ch_float_to_float_a_avx; | |
136 | if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P) | |
137 | ac->simd_f = ff_pack_6ch_int32_to_float_a_avx; | |
138 | if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP) | |
139 | ac->simd_f = ff_pack_6ch_float_to_int32_a_avx; | |
140 | } | |
141 | } | |
f6fa7814 DM |
142 | if(EXTERNAL_AVX2(mm_flags)) { |
143 | if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLTP) | |
144 | ac->simd_f = ff_float_to_int32_a_avx2; | |
145 | } | |
2ba45a60 | 146 | } |