libavresample/x86/audio_mix_init.c
c8af852b
 /*
  * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
  *
d814a839
  * This file is part of FFmpeg.
c8af852b
  *
d814a839
  * FFmpeg is free software; you can redistribute it and/or
c8af852b
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
d814a839
  * FFmpeg is distributed in the hope that it will be useful,
c8af852b
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
d814a839
  * License along with FFmpeg; if not, write to the Free Software
c8af852b
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include "config.h"
 #include "libavutil/cpu.h"
e0c6cce4
 #include "libavutil/x86/cpu.h"
c8af852b
 #include "libavresample/audio_mix.h"
 
b6649ab5
 void ff_mix_2_to_1_fltp_flt_sse(float **src, float **matrix, int len,
                                 int out_ch, int in_ch);
 void ff_mix_2_to_1_fltp_flt_avx(float **src, float **matrix, int len,
                                 int out_ch, int in_ch);
c8af852b
 
b6649ab5
 void ff_mix_2_to_1_s16p_flt_sse2(int16_t **src, float **matrix, int len,
                                  int out_ch, int in_ch);
 void ff_mix_2_to_1_s16p_flt_sse4(int16_t **src, float **matrix, int len,
                                  int out_ch, int in_ch);
c140fb2c
 
b6649ab5
 void ff_mix_2_to_1_s16p_q8_sse2(int16_t **src, int16_t **matrix,
                                 int len, int out_ch, int in_ch);
b75726cb
 
b6649ab5
 void ff_mix_1_to_2_fltp_flt_sse(float **src, float **matrix, int len,
                                 int out_ch, int in_ch);
 void ff_mix_1_to_2_fltp_flt_avx(float **src, float **matrix, int len,
                                 int out_ch, int in_ch);
29f7490c
 
b6649ab5
 void ff_mix_1_to_2_s16p_flt_sse2(int16_t **src, float **matrix, int len,
                                  int out_ch, int in_ch);
 void ff_mix_1_to_2_s16p_flt_sse4(int16_t **src, float **matrix, int len,
                                  int out_ch, int in_ch);
 void ff_mix_1_to_2_s16p_flt_avx (int16_t **src, float **matrix, int len,
                                  int out_ch, int in_ch);
f61ce90c
 
b6649ab5
 #define DEFINE_MIX_3_8_TO_1_2(chan)                                     \
 void ff_mix_ ## chan ## _to_1_fltp_flt_sse(float **src,                 \
                                            float **matrix, int len,     \
                                            int out_ch, int in_ch);      \
 void ff_mix_ ## chan ## _to_2_fltp_flt_sse(float **src,                 \
                                            float **matrix, int len,     \
                                            int out_ch, int in_ch);      \
                                                                         \
 void ff_mix_ ## chan ## _to_1_s16p_flt_sse2(int16_t **src,              \
                                             float **matrix, int len,    \
                                             int out_ch, int in_ch);     \
 void ff_mix_ ## chan ## _to_2_s16p_flt_sse2(int16_t **src,              \
                                             float **matrix, int len,    \
                                             int out_ch, int in_ch);     \
                                                                         \
 void ff_mix_ ## chan ## _to_1_s16p_flt_sse4(int16_t **src,              \
                                             float **matrix, int len,    \
                                             int out_ch, int in_ch);     \
 void ff_mix_ ## chan ## _to_2_s16p_flt_sse4(int16_t **src,              \
                                             float **matrix, int len,    \
                                             int out_ch, int in_ch);     \
                                                                         \
 void ff_mix_ ## chan ## _to_1_fltp_flt_avx(float **src,                 \
                                            float **matrix, int len,     \
                                            int out_ch, int in_ch);      \
 void ff_mix_ ## chan ## _to_2_fltp_flt_avx(float **src,                 \
                                            float **matrix, int len,     \
                                            int out_ch, int in_ch);      \
                                                                         \
 void ff_mix_ ## chan ## _to_1_s16p_flt_avx(int16_t **src,               \
                                            float **matrix, int len,     \
                                            int out_ch, int in_ch);      \
 void ff_mix_ ## chan ## _to_2_s16p_flt_avx(int16_t **src,               \
                                            float **matrix, int len,     \
                                            int out_ch, int in_ch);      \
                                                                         \
 void ff_mix_ ## chan ## _to_1_fltp_flt_fma4(float **src,                \
                                             float **matrix, int len,    \
                                             int out_ch, int in_ch);     \
 void ff_mix_ ## chan ## _to_2_fltp_flt_fma4(float **src,                \
                                             float **matrix, int len,    \
                                             int out_ch, int in_ch);     \
                                                                         \
 void ff_mix_ ## chan ## _to_1_s16p_flt_fma4(int16_t **src,              \
                                             float **matrix, int len,    \
                                             int out_ch, int in_ch);     \
 void ff_mix_ ## chan ## _to_2_s16p_flt_fma4(int16_t **src,              \
                                             float **matrix, int len,    \
                                             int out_ch, int in_ch);
2f096bb1
 
 DEFINE_MIX_3_8_TO_1_2(3)
 DEFINE_MIX_3_8_TO_1_2(4)
 DEFINE_MIX_3_8_TO_1_2(5)
 DEFINE_MIX_3_8_TO_1_2(6)
 DEFINE_MIX_3_8_TO_1_2(7)
 DEFINE_MIX_3_8_TO_1_2(8)
 
 #define SET_MIX_3_8_TO_1_2(chan)                                            \
3ac7fa81
     if (EXTERNAL_SSE(cpu_flags)) {                                          \
2f096bb1
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 1, 16, 4, "SSE",                        \
                               ff_mix_ ## chan ## _to_1_fltp_flt_sse);       \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 2, 16, 4, "SSE",                        \
                               ff_mix_## chan ##_to_2_fltp_flt_sse);         \
     }                                                                       \
3ac7fa81
     if (EXTERNAL_SSE2(cpu_flags)) {                                         \
2f096bb1
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 1, 16, 8, "SSE2",                       \
                               ff_mix_ ## chan ## _to_1_s16p_flt_sse2);      \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 2, 16, 8, "SSE2",                       \
                               ff_mix_ ## chan ## _to_2_s16p_flt_sse2);      \
     }                                                                       \
3ac7fa81
     if (EXTERNAL_SSE4(cpu_flags)) {                                         \
2f096bb1
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 1, 16, 8, "SSE4",                       \
                               ff_mix_ ## chan ## _to_1_s16p_flt_sse4);      \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 2, 16, 8, "SSE4",                       \
                               ff_mix_ ## chan ## _to_2_s16p_flt_sse4);      \
     }                                                                       \
3ac7fa81
     if (EXTERNAL_AVX(cpu_flags)) {                                          \
2f096bb1
         int ptr_align = 32;                                                 \
         int smp_align = 8;                                                  \
         if (ARCH_X86_32 || chan >= 6) {                                     \
             ptr_align = 16;                                                 \
             smp_align = 4;                                                  \
         }                                                                   \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 1, ptr_align, smp_align, "AVX",         \
                               ff_mix_ ## chan ## _to_1_fltp_flt_avx);       \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 2, ptr_align, smp_align, "AVX",         \
                               ff_mix_ ## chan ## _to_2_fltp_flt_avx);       \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 1, 16, 8, "AVX",                        \
                               ff_mix_ ## chan ## _to_1_s16p_flt_avx);       \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 2, 16, 8, "AVX",                        \
                               ff_mix_ ## chan ## _to_2_s16p_flt_avx);       \
     }                                                                       \
3ac7fa81
     if (EXTERNAL_FMA4(cpu_flags)) {                                         \
2f096bb1
         int ptr_align = 32;                                                 \
         int smp_align = 8;                                                  \
         if (ARCH_X86_32 || chan >= 6) {                                     \
             ptr_align = 16;                                                 \
             smp_align = 4;                                                  \
         }                                                                   \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 1, ptr_align, smp_align, "FMA4",        \
                               ff_mix_ ## chan ## _to_1_fltp_flt_fma4);      \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 2, ptr_align, smp_align, "FMA4",        \
                               ff_mix_ ## chan ## _to_2_fltp_flt_fma4);      \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 1, 16, 8, "FMA4",                       \
                               ff_mix_ ## chan ## _to_1_s16p_flt_fma4);      \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 2, 16, 8, "FMA4",                       \
                               ff_mix_ ## chan ## _to_2_s16p_flt_fma4);      \
     }
 
c8af852b
 av_cold void ff_audio_mix_init_x86(AudioMix *am)
 {
3ac7fa81
     int cpu_flags = av_get_cpu_flags();
c8af852b
 
3ac7fa81
     if (EXTERNAL_SSE(cpu_flags)) {
c8af852b
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
                               2, 1, 16, 8, "SSE", ff_mix_2_to_1_fltp_flt_sse);
29f7490c
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
                               1, 2, 16, 4, "SSE", ff_mix_1_to_2_fltp_flt_sse);
c8af852b
     }
3ac7fa81
     if (EXTERNAL_SSE2(cpu_flags)) {
c140fb2c
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
                               2, 1, 16, 8, "SSE2", ff_mix_2_to_1_s16p_flt_sse2);
b75726cb
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_Q8,
                               2, 1, 16, 8, "SSE2", ff_mix_2_to_1_s16p_q8_sse2);
f61ce90c
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
                               1, 2, 16, 8, "SSE2", ff_mix_1_to_2_s16p_flt_sse2);
c140fb2c
     }
3ac7fa81
     if (EXTERNAL_SSE4(cpu_flags)) {
c140fb2c
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
                               2, 1, 16, 8, "SSE4", ff_mix_2_to_1_s16p_flt_sse4);
f61ce90c
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
                               1, 2, 16, 8, "SSE4", ff_mix_1_to_2_s16p_flt_sse4);
c140fb2c
     }
d68c0538
     if (EXTERNAL_AVX_FAST(cpu_flags)) {
c8af852b
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
                               2, 1, 32, 16, "AVX", ff_mix_2_to_1_fltp_flt_avx);
29f7490c
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
                               1, 2, 32, 8, "AVX", ff_mix_1_to_2_fltp_flt_avx);
d68c0538
     }
     if (EXTERNAL_AVX(cpu_flags)) {
f61ce90c
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
                               1, 2, 16, 8, "AVX", ff_mix_1_to_2_s16p_flt_avx);
c8af852b
     }
2f096bb1
 
     SET_MIX_3_8_TO_1_2(3)
     SET_MIX_3_8_TO_1_2(4)
     SET_MIX_3_8_TO_1_2(5)
     SET_MIX_3_8_TO_1_2(6)
     SET_MIX_3_8_TO_1_2(7)
     SET_MIX_3_8_TO_1_2(8)
c8af852b
 }