1 /* Spa
2 *
3 * Copyright © 2019 Wim Taymans
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "resample-native-impl.h"
26
27 #include <xmmintrin.h>
28
inner_product_sse(float * d,const float * SPA_RESTRICT s,const float * SPA_RESTRICT taps,uint32_t n_taps)29 static void inner_product_sse(float *d, const float * SPA_RESTRICT s,
30 const float * SPA_RESTRICT taps, uint32_t n_taps)
31 {
32 __m128 sum = _mm_setzero_ps();
33 uint32_t i = 0;
34 #if 0
35 uint32_t unrolled = n_taps & ~15;
36
37 for (i = 0; i < unrolled; i += 16) {
38 sum = _mm_add_ps(sum,
39 _mm_mul_ps(
40 _mm_loadu_ps(s + i + 0),
41 _mm_load_ps(taps + i + 0)));
42 sum = _mm_add_ps(sum,
43 _mm_mul_ps(
44 _mm_loadu_ps(s + i + 4),
45 _mm_load_ps(taps + i + 4)));
46 sum = _mm_add_ps(sum,
47 _mm_mul_ps(
48 _mm_loadu_ps(s + i + 8),
49 _mm_load_ps(taps + i + 8)));
50 sum = _mm_add_ps(sum,
51 _mm_mul_ps(
52 _mm_loadu_ps(s + i + 12),
53 _mm_load_ps(taps + i + 12)));
54 }
55 #endif
56 for (; i < n_taps; i += 8) {
57 sum = _mm_add_ps(sum,
58 _mm_mul_ps(
59 _mm_loadu_ps(s + i + 0),
60 _mm_load_ps(taps + i + 0)));
61 sum = _mm_add_ps(sum,
62 _mm_mul_ps(
63 _mm_loadu_ps(s + i + 4),
64 _mm_load_ps(taps + i + 4)));
65 }
66 sum = _mm_add_ps(sum, _mm_movehl_ps(sum, sum));
67 sum = _mm_add_ss(sum, _mm_shuffle_ps(sum, sum, 0x55));
68 _mm_store_ss(d, sum);
69 }
70
inner_product_ip_sse(float * d,const float * SPA_RESTRICT s,const float * SPA_RESTRICT t0,const float * SPA_RESTRICT t1,float x,uint32_t n_taps)71 static void inner_product_ip_sse(float *d, const float * SPA_RESTRICT s,
72 const float * SPA_RESTRICT t0, const float * SPA_RESTRICT t1, float x,
73 uint32_t n_taps)
74 {
75 __m128 sum[2] = { _mm_setzero_ps (), _mm_setzero_ps () }, t;
76 uint32_t i;
77
78 for (i = 0; i < n_taps; i += 8) {
79 t = _mm_loadu_ps(s + i + 0);
80 sum[0] = _mm_add_ps(sum[0], _mm_mul_ps(t, _mm_load_ps(t0 + i + 0)));
81 sum[1] = _mm_add_ps(sum[1], _mm_mul_ps(t, _mm_load_ps(t1 + i + 0)));
82 t = _mm_loadu_ps(s + i + 4);
83 sum[0] = _mm_add_ps(sum[0], _mm_mul_ps(t, _mm_load_ps(t0 + i + 4)));
84 sum[1] = _mm_add_ps(sum[1], _mm_mul_ps(t, _mm_load_ps(t1 + i + 4)));
85 }
86 sum[1] = _mm_mul_ps(_mm_sub_ps(sum[1], sum[0]), _mm_load1_ps(&x));
87 sum[0] = _mm_add_ps(sum[0], sum[1]);
88 sum[0] = _mm_add_ps(sum[0], _mm_movehl_ps(sum[0], sum[0]));
89 sum[0] = _mm_add_ss(sum[0], _mm_shuffle_ps(sum[0], sum[0], 0x55));
90 _mm_store_ss(d, sum[0]);
91 }
92
93 MAKE_RESAMPLER_FULL(sse);
94 MAKE_RESAMPLER_INTER(sse);
95