FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rematrix_init.c
Go to the documentation of this file.
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"
23 
24 #define D(type, simd) \
25 mix_1_1_func_type ff_mix_1_1_a_## type ## _ ## simd;\
26 mix_2_1_func_type ff_mix_2_1_a_## type ## _ ## simd;
27 
28 D(float, sse)
29 D(float, avx)
30 D(int16, mmx)
31 D(int16, sse2)
32 
34 #if HAVE_YASM
35  int mm_flags = av_get_cpu_flags();
36  int nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout);
37  int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout);
38  int num = nb_in * nb_out;
39  int i,j;
40 
41  s->mix_1_1_simd = NULL;
42  s->mix_2_1_simd = NULL;
43 
44  if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
45  if(EXTERNAL_MMX(mm_flags)) {
46  s->mix_1_1_simd = ff_mix_1_1_a_int16_mmx;
47  s->mix_2_1_simd = ff_mix_2_1_a_int16_mmx;
48  }
49  if(EXTERNAL_SSE2(mm_flags)) {
50  s->mix_1_1_simd = ff_mix_1_1_a_int16_sse2;
51  s->mix_2_1_simd = ff_mix_2_1_a_int16_sse2;
52  }
53  s->native_simd_matrix = av_mallocz_array(num, 2 * sizeof(int16_t));
54  s->native_simd_one = av_mallocz(2 * sizeof(int16_t));
55  if (!s->native_simd_matrix || !s->native_simd_one)
56  return AVERROR(ENOMEM);
57 
58  for(i=0; i<nb_out; i++){
59  int sh = 0;
60  for(j=0; j<nb_in; j++)
61  sh = FFMAX(sh, FFABS(((int*)s->native_matrix)[i * nb_in + j]));
62  sh = FFMAX(av_log2(sh) - 14, 0);
63  for(j=0; j<nb_in; j++) {
64  ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)+1] = 15 - sh;
65  ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)] =
66  ((((int*)s->native_matrix)[i * nb_in + j]) + (1<<sh>>1)) >> sh;
67  }
68  }
69  ((int16_t*)s->native_simd_one)[1] = 14;
70  ((int16_t*)s->native_simd_one)[0] = 16384;
71  } else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
72  if(EXTERNAL_SSE(mm_flags)) {
73  s->mix_1_1_simd = ff_mix_1_1_a_float_sse;
74  s->mix_2_1_simd = ff_mix_2_1_a_float_sse;
75  }
76  if(EXTERNAL_AVX_FAST(mm_flags)) {
77  s->mix_1_1_simd = ff_mix_1_1_a_float_avx;
78  s->mix_2_1_simd = ff_mix_2_1_a_float_avx;
79  }
80  s->native_simd_matrix = av_mallocz_array(num, sizeof(float));
81  s->native_simd_one = av_mallocz(sizeof(float));
82  if (!s->native_simd_matrix || !s->native_simd_one)
83  return AVERROR(ENOMEM);
84  memcpy(s->native_simd_matrix, s->native_matrix, num * sizeof(float));
85  memcpy(s->native_simd_one, s->native_one, sizeof(float));
86  }
87 #endif
88 
89  return 0;
90 }
#define EXTERNAL_MMX(flags)
Definition: cpu.h:54
float, planar
Definition: samplefmt.h:69
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
int av_log2(unsigned v)
Definition: intmath.c:26
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
#define EXTERNAL_SSE(flags)
Definition: cpu.h:56
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
#define av_cold
Definition: attributes.h:82
#define EXTERNAL_AVX_FAST(flags)
Definition: cpu.h:67
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:57
#define AVERROR(e)
Definition: error.h:43
The libswresample context.
int swri_rematrix_init_x86(struct SwrContext *s)
#define FFMAX(a, b)
Definition: common.h:94
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define D(type, simd)
Definition: rematrix_init.c:24
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:76
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
signed 16 bits, planar
Definition: samplefmt.h:67
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:252