SAF
Loading...
Searching...
No Matches
resample_sse.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2008 Jean-Marc Valin
2 * Copyright (C) 2008 Thorvald Natvig
3 */
9/*
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions
12 are met:
13
14 - Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer.
16
17 - Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20
21 - Neither the name of the Xiph.org Foundation nor the names of its
22 contributors may be used to endorse or promote products derived from
23 this software without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
29 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36*/
37
38#include <xmmintrin.h>
39
40#define OVERRIDE_INNER_PRODUCT_SINGLE
41static inline float inner_product_single(const float *a, const float *b, unsigned int len)
42{
43 int i;
44 float ret;
45 __m128 sum = _mm_setzero_ps();
46 for (i=0;i<(int)len;i+=8)
47 {
48 sum = _mm_add_ps(sum, _mm_mul_ps(_mm_loadu_ps(a+i), _mm_loadu_ps(b+i)));
49 sum = _mm_add_ps(sum, _mm_mul_ps(_mm_loadu_ps(a+i+4), _mm_loadu_ps(b+i+4)));
50 }
51 sum = _mm_add_ps(sum, _mm_movehl_ps(sum, sum));
52 sum = _mm_add_ss(sum, _mm_shuffle_ps(sum, sum, 0x55));
53 _mm_store_ss(&ret, sum);
54 return ret;
55}
56
57#define OVERRIDE_INTERPOLATE_PRODUCT_SINGLE
58static inline float interpolate_product_single(const float *a, const float *b, unsigned int len, const spx_uint32_t oversample, float *frac) {
59 int i;
60 float ret;
61 __m128 sum = _mm_setzero_ps();
62 __m128 f = _mm_loadu_ps(frac);
63 for(i=0;i<(int)len;i+=2)
64 {
65 sum = _mm_add_ps(sum, _mm_mul_ps(_mm_load1_ps(a+i), _mm_loadu_ps(b+i*oversample)));
66 sum = _mm_add_ps(sum, _mm_mul_ps(_mm_load1_ps(a+i+1), _mm_loadu_ps(b+(i+1)*oversample)));
67 }
68 sum = _mm_mul_ps(f, sum);
69 sum = _mm_add_ps(sum, _mm_movehl_ps(sum, sum));
70 sum = _mm_add_ss(sum, _mm_shuffle_ps(sum, sum, 0x55));
71 _mm_store_ss(&ret, sum);
72 return ret;
73}
74
75#ifdef USE_SSE2
76#include <emmintrin.h>
77#define OVERRIDE_INNER_PRODUCT_DOUBLE
78
79static inline double inner_product_double(const float *a, const float *b, unsigned int len)
80{
81 int i;
82 double ret;
83 __m128d sum = _mm_setzero_pd();
84 __m128 t;
85 for (i=0;i<len;i+=8)
86 {
87 t = _mm_mul_ps(_mm_loadu_ps(a+i), _mm_loadu_ps(b+i));
88 sum = _mm_add_pd(sum, _mm_cvtps_pd(t));
89 sum = _mm_add_pd(sum, _mm_cvtps_pd(_mm_movehl_ps(t, t)));
90
91 t = _mm_mul_ps(_mm_loadu_ps(a+i+4), _mm_loadu_ps(b+i+4));
92 sum = _mm_add_pd(sum, _mm_cvtps_pd(t));
93 sum = _mm_add_pd(sum, _mm_cvtps_pd(_mm_movehl_ps(t, t)));
94 }
95 sum = _mm_add_sd(sum, _mm_unpackhi_pd(sum, sum));
96 _mm_store_sd(&ret, sum);
97 return ret;
98}
99
100#define OVERRIDE_INTERPOLATE_PRODUCT_DOUBLE
101static inline double interpolate_product_double(const float *a, const float *b, unsigned int len, const spx_uint32_t oversample, float *frac) {
102 int i;
103 double ret;
104 __m128d sum;
105 __m128d sum1 = _mm_setzero_pd();
106 __m128d sum2 = _mm_setzero_pd();
107 __m128 f = _mm_loadu_ps(frac);
108 __m128d f1 = _mm_cvtps_pd(f);
109 __m128d f2 = _mm_cvtps_pd(_mm_movehl_ps(f,f));
110 __m128 t;
111 for(i=0;i<len;i+=2)
112 {
113 t = _mm_mul_ps(_mm_load1_ps(a+i), _mm_loadu_ps(b+i*oversample));
114 sum1 = _mm_add_pd(sum1, _mm_cvtps_pd(t));
115 sum2 = _mm_add_pd(sum2, _mm_cvtps_pd(_mm_movehl_ps(t, t)));
116
117 t = _mm_mul_ps(_mm_load1_ps(a+i+1), _mm_loadu_ps(b+(i+1)*oversample));
118 sum1 = _mm_add_pd(sum1, _mm_cvtps_pd(t));
119 sum2 = _mm_add_pd(sum2, _mm_cvtps_pd(_mm_movehl_ps(t, t)));
120 }
121 sum1 = _mm_mul_pd(f1, sum1);
122 sum2 = _mm_mul_pd(f2, sum2);
123 sum = _mm_add_pd(sum1, sum2);
124 sum = _mm_add_sd(sum, _mm_unpackhi_pd(sum, sum));
125 _mm_store_sd(&ret, sum);
126 return ret;
127}
128
129#endif