2 * Copyright (C) 2012 Michael Niedermayer (michaelni@gmx.at)
4 * This file is part of libswresample
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.
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.
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
21 #include "libavutil/attributes.h"
22 #include "libavutil/x86/cpu.h"
23 #include "libswresample/swresample_internal.h"
25 #define D(type, simd) \
26 mix_1_1_func_type ff_mix_1_1_a_## type ## _ ## simd;\
27 mix_2_1_func_type ff_mix_2_1_a_## type ## _ ## simd;
34 av_cold int swri_rematrix_init_x86(struct SwrContext *s){
36 int mm_flags = av_get_cpu_flags();
37 int nb_in = s->used_ch_count;
38 int nb_out = s->out.ch_count;
39 int num = nb_in * nb_out;
42 s->mix_1_1_simd = NULL;
43 s->mix_2_1_simd = NULL;
45 if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
46 if(EXTERNAL_MMX(mm_flags)) {
47 s->mix_1_1_simd = ff_mix_1_1_a_int16_mmx;
48 s->mix_2_1_simd = ff_mix_2_1_a_int16_mmx;
50 if(EXTERNAL_SSE2(mm_flags)) {
51 s->mix_1_1_simd = ff_mix_1_1_a_int16_sse2;
52 s->mix_2_1_simd = ff_mix_2_1_a_int16_sse2;
54 s->native_simd_matrix = av_mallocz_array(num, 2 * sizeof(int16_t));
55 s->native_simd_one = av_mallocz(2 * sizeof(int16_t));
56 if (!s->native_simd_matrix || !s->native_simd_one)
57 return AVERROR(ENOMEM);
59 for(i=0; i<nb_out; i++){
61 for(j=0; j<nb_in; j++)
62 sh = FFMAX(sh, FFABS(((int*)s->native_matrix)[i * nb_in + j]));
63 sh = FFMAX(av_log2(sh) - 14, 0);
64 for(j=0; j<nb_in; j++) {
65 ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)+1] = 15 - sh;
66 ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)] =
67 ((((int*)s->native_matrix)[i * nb_in + j]) + (1<<sh>>1)) >> sh;
70 ((int16_t*)s->native_simd_one)[1] = 14;
71 ((int16_t*)s->native_simd_one)[0] = 16384;
72 } else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
73 if(EXTERNAL_SSE(mm_flags)) {
74 s->mix_1_1_simd = ff_mix_1_1_a_float_sse;
75 s->mix_2_1_simd = ff_mix_2_1_a_float_sse;
77 if(EXTERNAL_AVX_FAST(mm_flags)) {
78 s->mix_1_1_simd = ff_mix_1_1_a_float_avx;
79 s->mix_2_1_simd = ff_mix_2_1_a_float_avx;
81 s->native_simd_matrix = av_mallocz_array(num, sizeof(float));
82 s->native_simd_one = av_mallocz(sizeof(float));
83 if (!s->native_simd_matrix || !s->native_simd_one)
84 return AVERROR(ENOMEM);
85 memcpy(s->native_simd_matrix, s->native_matrix, num * sizeof(float));
86 memcpy(s->native_simd_one, s->native_one, sizeof(float));