Coverage Report

Created: 2026-11-23 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gstreamer/subprojects/gst-plugins-base/gst-libs/gst/audio/audio-resampler-x86-sse.c
Line
Count
Source
1
/* GStreamer
2
 * Copyright (C) <2016> Wim Taymans <wim.taymans@gmail.com>
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public
15
 * License along with this library; if not, write to the
16
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#ifdef HAVE_CONFIG_H
21
#  include "config.h"
22
#endif
23
24
#include "audio-resampler-x86-sse.h"
25
26
#include <immintrin.h>
27
28
static inline void
29
inner_product_gfloat_full_1_sse (gfloat * o, const gfloat * a,
30
    const gfloat * b, gint len, const gfloat * icoeff, gint bstride)
31
160M
{
32
160M
  gint i = 0;
33
160M
  __m128 sum = _mm_setzero_ps ();
34
35
1.09G
  for (; i < len; i += 8) {
36
939M
    sum =
37
939M
        _mm_add_ps (sum, _mm_mul_ps (_mm_loadu_ps (a + i + 0),
38
939M
            _mm_load_ps (b + i + 0)));
39
939M
    sum =
40
939M
        _mm_add_ps (sum, _mm_mul_ps (_mm_loadu_ps (a + i + 4),
41
939M
            _mm_load_ps (b + i + 4)));
42
939M
  }
43
160M
  sum = _mm_add_ps (sum, _mm_movehl_ps (sum, sum));
44
160M
  sum = _mm_add_ss (sum, _mm_shuffle_ps (sum, sum, 0x55));
45
160M
  _mm_store_ss (o, sum);
46
160M
}
47
48
static inline void
49
inner_product_gfloat_linear_1_sse (gfloat * o, const gfloat * a,
50
    const gfloat * b, gint len, const gfloat * icoeff, gint bstride)
51
0
{
52
0
  gint i = 0;
53
0
  __m128 sum[2], t;
54
0
  const gfloat *c[2] = { (gfloat *) ((gint8 *) b + 0 * bstride),
55
0
    (gfloat *) ((gint8 *) b + 1 * bstride)
56
0
  };
57
58
0
  sum[0] = sum[1] = _mm_setzero_ps ();
59
60
0
  for (; i < len; i += 8) {
61
0
    t = _mm_loadu_ps (a + i + 0);
62
0
    sum[0] = _mm_add_ps (sum[0], _mm_mul_ps (t, _mm_load_ps (c[0] + i + 0)));
63
0
    sum[1] = _mm_add_ps (sum[1], _mm_mul_ps (t, _mm_load_ps (c[1] + i + 0)));
64
0
    t = _mm_loadu_ps (a + i + 4);
65
0
    sum[0] = _mm_add_ps (sum[0], _mm_mul_ps (t, _mm_load_ps (c[0] + i + 4)));
66
0
    sum[1] = _mm_add_ps (sum[1], _mm_mul_ps (t, _mm_load_ps (c[1] + i + 4)));
67
0
  }
68
0
  sum[0] = _mm_mul_ps (_mm_sub_ps (sum[0], sum[1]), _mm_load1_ps (icoeff));
69
0
  sum[0] = _mm_add_ps (sum[0], sum[1]);
70
0
  sum[0] = _mm_add_ps (sum[0], _mm_movehl_ps (sum[0], sum[0]));
71
0
  sum[0] = _mm_add_ss (sum[0], _mm_shuffle_ps (sum[0], sum[0], 0x55));
72
0
  _mm_store_ss (o, sum[0]);
73
0
}
74
75
static inline void
76
inner_product_gfloat_cubic_1_sse (gfloat * o, const gfloat * a,
77
    const gfloat * b, gint len, const gfloat * icoeff, gint bstride)
78
77.8k
{
79
77.8k
  gint i = 0;
80
77.8k
  __m128 sum[4];
81
77.8k
  __m128 t, f = _mm_loadu_ps (icoeff);
82
77.8k
  const gfloat *c[4] = { (gfloat *) ((gint8 *) b + 0 * bstride),
83
77.8k
    (gfloat *) ((gint8 *) b + 1 * bstride),
84
77.8k
    (gfloat *) ((gint8 *) b + 2 * bstride),
85
77.8k
    (gfloat *) ((gint8 *) b + 3 * bstride)
86
77.8k
  };
87
88
77.8k
  sum[0] = sum[1] = sum[2] = sum[3] = _mm_setzero_ps ();
89
90
1.40M
  for (; i < len; i += 4) {
91
1.32M
    t = _mm_loadu_ps (a + i);
92
1.32M
    sum[0] = _mm_add_ps (sum[0], _mm_mul_ps (t, _mm_load_ps (c[0] + i)));
93
1.32M
    sum[1] = _mm_add_ps (sum[1], _mm_mul_ps (t, _mm_load_ps (c[1] + i)));
94
1.32M
    sum[2] = _mm_add_ps (sum[2], _mm_mul_ps (t, _mm_load_ps (c[2] + i)));
95
1.32M
    sum[3] = _mm_add_ps (sum[3], _mm_mul_ps (t, _mm_load_ps (c[3] + i)));
96
1.32M
  }
97
77.8k
  sum[0] = _mm_mul_ps (sum[0], _mm_shuffle_ps (f, f, 0x00));
98
77.8k
  sum[1] = _mm_mul_ps (sum[1], _mm_shuffle_ps (f, f, 0x55));
99
77.8k
  sum[2] = _mm_mul_ps (sum[2], _mm_shuffle_ps (f, f, 0xaa));
100
77.8k
  sum[3] = _mm_mul_ps (sum[3], _mm_shuffle_ps (f, f, 0xff));
101
77.8k
  sum[0] = _mm_add_ps (sum[0], sum[1]);
102
77.8k
  sum[2] = _mm_add_ps (sum[2], sum[3]);
103
77.8k
  sum[0] = _mm_add_ps (sum[0], sum[2]);
104
77.8k
  sum[0] = _mm_add_ps (sum[0], _mm_movehl_ps (sum[0], sum[0]));
105
77.8k
  sum[0] = _mm_add_ss (sum[0], _mm_shuffle_ps (sum[0], sum[0], 0x55));
106
77.8k
  _mm_store_ss (o, sum[0]);
107
77.8k
}
108
109
MAKE_RESAMPLE_FUNC (gfloat, full, 1, sse);
110
MAKE_RESAMPLE_FUNC (gfloat, linear, 1, sse);
111
MAKE_RESAMPLE_FUNC (gfloat, cubic, 1, sse);
112
113
void
114
interpolate_gfloat_linear_sse (gpointer op, const gpointer ap,
115
    gint len, const gpointer icp, gint astride)
116
0
{
117
0
  gint i;
118
0
  gfloat *o = op, *a = ap, *ic = icp;
119
0
  __m128 f[2], t1, t2;
120
0
  const gfloat *c[2] = { (gfloat *) ((gint8 *) a + 0 * astride),
121
0
    (gfloat *) ((gint8 *) a + 1 * astride)
122
0
  };
123
124
0
  f[0] = _mm_load1_ps (ic + 0);
125
0
  f[1] = _mm_load1_ps (ic + 1);
126
127
0
  for (i = 0; i < len; i += 8) {
128
0
    t1 = _mm_mul_ps (_mm_load_ps (c[0] + i + 0), f[0]);
129
0
    t2 = _mm_mul_ps (_mm_load_ps (c[1] + i + 0), f[1]);
130
0
    _mm_store_ps (o + i + 0, _mm_add_ps (t1, t2));
131
132
0
    t1 = _mm_mul_ps (_mm_load_ps (c[0] + i + 4), f[0]);
133
0
    t2 = _mm_mul_ps (_mm_load_ps (c[1] + i + 4), f[1]);
134
0
    _mm_store_ps (o + i + 4, _mm_add_ps (t1, t2));
135
0
  }
136
0
}
137
138
void
139
interpolate_gfloat_cubic_sse (gpointer op, const gpointer ap,
140
    gint len, const gpointer icp, gint astride)
141
8.23k
{
142
8.23k
  gint i;
143
8.23k
  gfloat *o = op, *a = ap, *ic = icp;
144
8.23k
  __m128 f[4], t[4];
145
8.23k
  const gfloat *c[4] = { (gfloat *) ((gint8 *) a + 0 * astride),
146
8.23k
    (gfloat *) ((gint8 *) a + 1 * astride),
147
8.23k
    (gfloat *) ((gint8 *) a + 2 * astride),
148
8.23k
    (gfloat *) ((gint8 *) a + 3 * astride)
149
8.23k
  };
150
151
8.23k
  f[0] = _mm_load1_ps (ic + 0);
152
8.23k
  f[1] = _mm_load1_ps (ic + 1);
153
8.23k
  f[2] = _mm_load1_ps (ic + 2);
154
8.23k
  f[3] = _mm_load1_ps (ic + 3);
155
156
145k
  for (i = 0; i < len; i += 4) {
157
137k
    t[0] = _mm_mul_ps (_mm_load_ps (c[0] + i + 0), f[0]);
158
137k
    t[1] = _mm_mul_ps (_mm_load_ps (c[1] + i + 0), f[1]);
159
137k
    t[2] = _mm_mul_ps (_mm_load_ps (c[2] + i + 0), f[2]);
160
137k
    t[3] = _mm_mul_ps (_mm_load_ps (c[3] + i + 0), f[3]);
161
137k
    t[0] = _mm_add_ps (t[0], t[1]);
162
137k
    t[2] = _mm_add_ps (t[2], t[3]);
163
137k
    _mm_store_ps (o + i + 0, _mm_add_ps (t[0], t[2]));
164
137k
  }
165
8.23k
}