]> git.sesse.net Git - ffmpeg/blob - libswresample/x86/audio_convert_init.c
hwcontext_vulkan: dlopen libvulkan
[ffmpeg] / libswresample / x86 / audio_convert_init.c
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/attributes.h"
22 #include "libavutil/x86/cpu.h"
23 #include "libswresample/swresample_internal.h"
24 #include "libswresample/audioconvert.h"
25
26 #define PROTO(pre, in, out, cap) void ff ## pre ## in## _to_ ##out## _a_ ##cap(uint8_t **dst, const uint8_t **src, int len);
27 #define PROTO2(pre, out, cap) PROTO(pre, int16, out, cap) PROTO(pre, int32, out, cap) PROTO(pre, float, out, cap)
28 #define PROTO3(pre, cap) PROTO2(pre, int16, cap) PROTO2(pre, int32, cap) PROTO2(pre, float, cap)
29 #define PROTO4(pre) PROTO3(pre, mmx) PROTO3(pre, sse) PROTO3(pre, sse2) PROTO3(pre, ssse3) PROTO3(pre, sse4) PROTO3(pre, avx) PROTO3(pre, avx2)
30 PROTO4(_)
31 PROTO4(_pack_2ch_)
32 PROTO4(_pack_6ch_)
33 PROTO4(_pack_8ch_)
34 PROTO4(_unpack_2ch_)
35 PROTO4(_unpack_6ch_)
36
37 av_cold void swri_audio_convert_init_x86(struct AudioConvert *ac,
38                                  enum AVSampleFormat out_fmt,
39                                  enum AVSampleFormat in_fmt,
40                                  int channels){
41     int mm_flags = av_get_cpu_flags();
42
43     ac->simd_f= NULL;
44
45 //FIXME add memcpy case
46
47 #define MULTI_CAPS_FUNC(flag, cap) \
48     if (EXTERNAL_##flag(mm_flags)) {\
49         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)\
50             ac->simd_f =  ff_int16_to_int32_a_ ## cap;\
51         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)\
52             ac->simd_f =  ff_int32_to_int16_a_ ## cap;\
53     }
54
55 MULTI_CAPS_FUNC(MMX, mmx)
56 MULTI_CAPS_FUNC(SSE2, sse2)
57
58     if(EXTERNAL_MMX(mm_flags)) {
59         if(channels == 6) {
60             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)
61                 ac->simd_f =  ff_pack_6ch_float_to_float_a_mmx;
62         }
63     }
64     if(EXTERNAL_SSE(mm_flags)) {
65         if(channels == 6) {
66             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)
67                 ac->simd_f =  ff_pack_6ch_float_to_float_a_sse;
68
69             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)
70                 ac->simd_f =  ff_unpack_6ch_float_to_float_a_sse;
71         }
72     }
73     if(EXTERNAL_SSE2(mm_flags)) {
74         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)
75             ac->simd_f =  ff_int32_to_float_a_sse2;
76         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)
77             ac->simd_f =  ff_int16_to_float_a_sse2;
78         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)
79             ac->simd_f =  ff_float_to_int32_a_sse2;
80         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)
81             ac->simd_f =  ff_float_to_int16_a_sse2;
82
83         if(channels == 2) {
84             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)
85                 ac->simd_f =  ff_pack_2ch_int32_to_int32_a_sse2;
86             if(   out_fmt == AV_SAMPLE_FMT_S16  && in_fmt == AV_SAMPLE_FMT_S16P)
87                 ac->simd_f =  ff_pack_2ch_int16_to_int16_a_sse2;
88             if(   out_fmt == AV_SAMPLE_FMT_S32  && in_fmt == AV_SAMPLE_FMT_S16P)
89                 ac->simd_f =  ff_pack_2ch_int16_to_int32_a_sse2;
90             if(   out_fmt == AV_SAMPLE_FMT_S16  && in_fmt == AV_SAMPLE_FMT_S32P)
91                 ac->simd_f =  ff_pack_2ch_int32_to_int16_a_sse2;
92
93             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)
94                 ac->simd_f =  ff_unpack_2ch_int32_to_int32_a_sse2;
95             if(   out_fmt == AV_SAMPLE_FMT_S16P  && in_fmt == AV_SAMPLE_FMT_S16)
96                 ac->simd_f =  ff_unpack_2ch_int16_to_int16_a_sse2;
97             if(   out_fmt == AV_SAMPLE_FMT_S32P  && in_fmt == AV_SAMPLE_FMT_S16)
98                 ac->simd_f =  ff_unpack_2ch_int16_to_int32_a_sse2;
99             if(   out_fmt == AV_SAMPLE_FMT_S16P  && in_fmt == AV_SAMPLE_FMT_S32)
100                 ac->simd_f =  ff_unpack_2ch_int32_to_int16_a_sse2;
101
102             if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_S32P)
103                 ac->simd_f =  ff_pack_2ch_int32_to_float_a_sse2;
104             if(   out_fmt == AV_SAMPLE_FMT_S32  && in_fmt == AV_SAMPLE_FMT_FLTP)
105                 ac->simd_f =  ff_pack_2ch_float_to_int32_a_sse2;
106             if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_S16P)
107                 ac->simd_f =  ff_pack_2ch_int16_to_float_a_sse2;
108             if(   out_fmt == AV_SAMPLE_FMT_S16  && in_fmt == AV_SAMPLE_FMT_FLTP)
109                 ac->simd_f =  ff_pack_2ch_float_to_int16_a_sse2;
110             if(   out_fmt == AV_SAMPLE_FMT_FLTP  && in_fmt == AV_SAMPLE_FMT_S32)
111                 ac->simd_f =  ff_unpack_2ch_int32_to_float_a_sse2;
112             if(   out_fmt == AV_SAMPLE_FMT_S32P  && in_fmt == AV_SAMPLE_FMT_FLT)
113                 ac->simd_f =  ff_unpack_2ch_float_to_int32_a_sse2;
114             if(   out_fmt == AV_SAMPLE_FMT_FLTP  && in_fmt == AV_SAMPLE_FMT_S16)
115                 ac->simd_f =  ff_unpack_2ch_int16_to_float_a_sse2;
116             if(   out_fmt == AV_SAMPLE_FMT_S16P  && in_fmt == AV_SAMPLE_FMT_FLT)
117                 ac->simd_f =  ff_unpack_2ch_float_to_int16_a_sse2;
118         }
119         if(channels == 6) {
120             if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_S32P)
121                 ac->simd_f =  ff_pack_6ch_int32_to_float_a_sse2;
122             if(   out_fmt == AV_SAMPLE_FMT_S32  && in_fmt == AV_SAMPLE_FMT_FLTP)
123                 ac->simd_f =  ff_pack_6ch_float_to_int32_a_sse2;
124
125             if(   out_fmt == AV_SAMPLE_FMT_FLTP  && in_fmt == AV_SAMPLE_FMT_S32)
126                 ac->simd_f =  ff_unpack_6ch_int32_to_float_a_sse2;
127             if(   out_fmt == AV_SAMPLE_FMT_S32P  && in_fmt == AV_SAMPLE_FMT_FLT)
128                 ac->simd_f =  ff_unpack_6ch_float_to_int32_a_sse2;
129         }
130         if(channels == 8) {
131             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)
132                 ac->simd_f =  ff_pack_8ch_float_to_float_a_sse2;
133             if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_S32P)
134                 ac->simd_f =  ff_pack_8ch_int32_to_float_a_sse2;
135             if(   out_fmt == AV_SAMPLE_FMT_S32  && in_fmt == AV_SAMPLE_FMT_FLTP)
136                 ac->simd_f =  ff_pack_8ch_float_to_int32_a_sse2;
137         }
138     }
139     if(EXTERNAL_SSSE3(mm_flags)) {
140         if(channels == 2) {
141             if(   out_fmt == AV_SAMPLE_FMT_S16P  && in_fmt == AV_SAMPLE_FMT_S16)
142                 ac->simd_f =  ff_unpack_2ch_int16_to_int16_a_ssse3;
143             if(   out_fmt == AV_SAMPLE_FMT_S32P  && in_fmt == AV_SAMPLE_FMT_S16)
144                 ac->simd_f =  ff_unpack_2ch_int16_to_int32_a_ssse3;
145             if(   out_fmt == AV_SAMPLE_FMT_FLTP  && in_fmt == AV_SAMPLE_FMT_S16)
146                 ac->simd_f =  ff_unpack_2ch_int16_to_float_a_ssse3;
147         }
148     }
149     if(EXTERNAL_AVX_FAST(mm_flags)) {
150         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)
151             ac->simd_f =  ff_int32_to_float_a_avx;
152     }
153     if(EXTERNAL_AVX(mm_flags)) {
154         if(channels == 6) {
155             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)
156                 ac->simd_f =  ff_pack_6ch_float_to_float_a_avx;
157             if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_S32P)
158                 ac->simd_f =  ff_pack_6ch_int32_to_float_a_avx;
159             if(   out_fmt == AV_SAMPLE_FMT_S32  && in_fmt == AV_SAMPLE_FMT_FLTP)
160                 ac->simd_f =  ff_pack_6ch_float_to_int32_a_avx;
161
162             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)
163                 ac->simd_f =  ff_unpack_6ch_float_to_float_a_avx;
164             if(   out_fmt == AV_SAMPLE_FMT_FLTP  && in_fmt == AV_SAMPLE_FMT_S32)
165                 ac->simd_f =  ff_unpack_6ch_int32_to_float_a_avx;
166             if(   out_fmt == AV_SAMPLE_FMT_S32P  && in_fmt == AV_SAMPLE_FMT_FLT)
167                 ac->simd_f =  ff_unpack_6ch_float_to_int32_a_avx;
168         }
169         if(channels == 8) {
170             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)
171                 ac->simd_f =  ff_pack_8ch_float_to_float_a_avx;
172             if(   out_fmt == AV_SAMPLE_FMT_FLT  && in_fmt == AV_SAMPLE_FMT_S32P)
173                 ac->simd_f =  ff_pack_8ch_int32_to_float_a_avx;
174             if(   out_fmt == AV_SAMPLE_FMT_S32  && in_fmt == AV_SAMPLE_FMT_FLTP)
175                 ac->simd_f =  ff_pack_8ch_float_to_int32_a_avx;
176         }
177     }
178     if(EXTERNAL_AVX2_FAST(mm_flags)) {
179         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)
180             ac->simd_f =  ff_float_to_int32_a_avx2;
181     }
182 }