FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswresample/x86/rematrix_init.c
Date: 2024-05-03 15:42:48
Exec Total Coverage
Lines: 36 40 90.0%
Functions: 1 1 100.0%
Branches: 19 26 73.1%

Line Branch Exec Source
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/mem.h"
23 #include "libavutil/x86/cpu.h"
24 #include "libswresample/swresample_internal.h"
25
26 #define D(type, simd) \
27 mix_1_1_func_type ff_mix_1_1_a_## type ## _ ## simd;\
28 mix_2_1_func_type ff_mix_2_1_a_## type ## _ ## simd;
29
30 D(float, sse)
31 D(float, avx)
32 D(int16, sse2)
33
34 25 av_cold int swri_rematrix_init_x86(struct SwrContext *s){
35 #if HAVE_X86ASM
36 25 int mm_flags = av_get_cpu_flags();
37 25 int nb_in = s->used_ch_layout.nb_channels;
38 25 int nb_out = s->out.ch_count;
39 25 int num = nb_in * nb_out;
40 int i,j;
41
42 25 s->mix_1_1_simd = NULL;
43 25 s->mix_2_1_simd = NULL;
44
45
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 7 times.
25 if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
46
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(EXTERNAL_SSE2(mm_flags)) {
47 s->mix_1_1_simd = ff_mix_1_1_a_int16_sse2;
48 s->mix_2_1_simd = ff_mix_2_1_a_int16_sse2;
49 }
50 18 s->native_simd_matrix = av_calloc(num, 2 * sizeof(int16_t));
51 18 s->native_simd_one = av_mallocz(2 * sizeof(int16_t));
52
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 if (!s->native_simd_matrix || !s->native_simd_one)
53 return AVERROR(ENOMEM);
54
55
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 18 times.
58 for(i=0; i<nb_out; i++){
56 40 int sh = 0;
57
2/2
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 40 times.
190 for(j=0; j<nb_in; j++)
58 150 sh = FFMAX(sh, FFABS(((int*)s->native_matrix)[i * nb_in + j]));
59 40 sh = FFMAX(av_log2(sh) - 14, 0);
60
2/2
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 40 times.
190 for(j=0; j<nb_in; j++) {
61 150 ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)+1] = 15 - sh;
62 150 ((int16_t*)s->native_simd_matrix)[2*(i * nb_in + j)] =
63 150 ((((int*)s->native_matrix)[i * nb_in + j]) + (1<<sh>>1)) >> sh;
64 }
65 }
66 18 ((int16_t*)s->native_simd_one)[1] = 14;
67 18 ((int16_t*)s->native_simd_one)[0] = 16384;
68
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 } else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
69
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if(EXTERNAL_SSE(mm_flags)) {
70 1 s->mix_1_1_simd = ff_mix_1_1_a_float_sse;
71 1 s->mix_2_1_simd = ff_mix_2_1_a_float_sse;
72 }
73
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
7 if(EXTERNAL_AVX_FAST(mm_flags)) {
74 1 s->mix_1_1_simd = ff_mix_1_1_a_float_avx;
75 1 s->mix_2_1_simd = ff_mix_2_1_a_float_avx;
76 }
77 7 s->native_simd_matrix = av_calloc(num, sizeof(float));
78 7 s->native_simd_one = av_mallocz(sizeof(float));
79
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
7 if (!s->native_simd_matrix || !s->native_simd_one)
80 return AVERROR(ENOMEM);
81 7 memcpy(s->native_simd_matrix, s->native_matrix, num * sizeof(float));
82 7 memcpy(s->native_simd_one, s->native_one, sizeof(float));
83 }
84 #endif
85
86 25 return 0;
87 }
88