2 * OpenAL cross platform audio library, SSE3 mixer functions
4 * Copyright (C) 2014 by Timothy Arceri <t_arceri@yahoo.com.au>.
5 * Copyright (C) 2015 by Chris Robinson <chris.kcat@gmail.com>.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Or go to http://www.gnu.org/copyleft/lgpl.html
26 #include <xmmintrin.h>
27 #include <emmintrin.h>
28 #include <pmmintrin.h>
31 #include "mixer_defs.h"
34 const ALfloat
*Resample_fir4_32_SSE3(const BsincState
* UNUSED(state
), const ALfloat
*restrict src
,
35 ALuint frac
, ALint increment
, ALfloat
*restrict dst
,
38 const __m128i increment4
= _mm_set1_epi32(increment
*4);
39 const __m128i fracMask4
= _mm_set1_epi32(FRACTIONMASK
);
40 union { alignas(16) ALint i
[4]; float f
[4]; } pos_
;
41 union { alignas(16) ALuint i
[4]; float f
[4]; } frac_
;
46 InitiatePositionArrays(frac
, increment
, frac_
.i
, pos_
.i
, 4);
48 frac4
= _mm_castps_si128(_mm_load_ps(frac_
.f
));
49 pos4
= _mm_castps_si128(_mm_load_ps(pos_
.f
));
52 for(i
= 0;numsamples
-i
> 3;i
+= 4)
54 const __m128 val0
= _mm_loadu_ps(&src
[pos_
.i
[0]]);
55 const __m128 val1
= _mm_loadu_ps(&src
[pos_
.i
[1]]);
56 const __m128 val2
= _mm_loadu_ps(&src
[pos_
.i
[2]]);
57 const __m128 val3
= _mm_loadu_ps(&src
[pos_
.i
[3]]);
58 __m128 k0
= _mm_load_ps(ResampleCoeffs
.FIR4
[frac_
.i
[0]]);
59 __m128 k1
= _mm_load_ps(ResampleCoeffs
.FIR4
[frac_
.i
[1]]);
60 __m128 k2
= _mm_load_ps(ResampleCoeffs
.FIR4
[frac_
.i
[2]]);
61 __m128 k3
= _mm_load_ps(ResampleCoeffs
.FIR4
[frac_
.i
[3]]);
64 k0
= _mm_mul_ps(k0
, val0
);
65 k1
= _mm_mul_ps(k1
, val1
);
66 k2
= _mm_mul_ps(k2
, val2
);
67 k3
= _mm_mul_ps(k3
, val3
);
68 k0
= _mm_hadd_ps(k0
, k1
);
69 k2
= _mm_hadd_ps(k2
, k3
);
70 out
= _mm_hadd_ps(k0
, k2
);
72 _mm_store_ps(&dst
[i
], out
);
74 frac4
= _mm_add_epi32(frac4
, increment4
);
75 pos4
= _mm_add_epi32(pos4
, _mm_srli_epi32(frac4
, FRACTIONBITS
));
76 frac4
= _mm_and_si128(frac4
, fracMask4
);
78 _mm_store_ps(pos_
.f
, _mm_castsi128_ps(pos4
));
79 _mm_store_ps(frac_
.f
, _mm_castsi128_ps(frac4
));
82 /* NOTE: These four elements represent the position *after* the last four
83 * samples, so the lowest element is the next position to resample.
88 for(;i
< numsamples
;i
++)
90 dst
[i
] = resample_fir4(src
[pos
], src
[pos
+1], src
[pos
+2], src
[pos
+3], frac
);
93 pos
+= frac
>>FRACTIONBITS
;
99 const ALfloat
*Resample_fir8_32_SSE3(const BsincState
* UNUSED(state
), const ALfloat
*restrict src
,
100 ALuint frac
, ALint increment
, ALfloat
*restrict dst
,
103 const __m128i increment4
= _mm_set1_epi32(increment
*4);
104 const __m128i fracMask4
= _mm_set1_epi32(FRACTIONMASK
);
105 union { alignas(16) ALint i
[4]; float f
[4]; } pos_
;
106 union { alignas(16) ALuint i
[4]; float f
[4]; } frac_
;
111 InitiatePositionArrays(frac
, increment
, frac_
.i
, pos_
.i
, 4);
113 frac4
= _mm_castps_si128(_mm_load_ps(frac_
.f
));
114 pos4
= _mm_castps_si128(_mm_load_ps(pos_
.f
));
117 for(i
= 0;numsamples
-i
> 3;i
+= 4)
120 for(j
= 0;j
< 8;j
+=4)
122 const __m128 val0
= _mm_loadu_ps(&src
[pos_
.i
[0]+j
]);
123 const __m128 val1
= _mm_loadu_ps(&src
[pos_
.i
[1]+j
]);
124 const __m128 val2
= _mm_loadu_ps(&src
[pos_
.i
[2]+j
]);
125 const __m128 val3
= _mm_loadu_ps(&src
[pos_
.i
[3]+j
]);
126 __m128 k0
= _mm_load_ps(&ResampleCoeffs
.FIR8
[frac_
.i
[0]][j
]);
127 __m128 k1
= _mm_load_ps(&ResampleCoeffs
.FIR8
[frac_
.i
[1]][j
]);
128 __m128 k2
= _mm_load_ps(&ResampleCoeffs
.FIR8
[frac_
.i
[2]][j
]);
129 __m128 k3
= _mm_load_ps(&ResampleCoeffs
.FIR8
[frac_
.i
[3]][j
]);
131 k0
= _mm_mul_ps(k0
, val0
);
132 k1
= _mm_mul_ps(k1
, val1
);
133 k2
= _mm_mul_ps(k2
, val2
);
134 k3
= _mm_mul_ps(k3
, val3
);
135 k0
= _mm_hadd_ps(k0
, k1
);
136 k2
= _mm_hadd_ps(k2
, k3
);
137 out
[j
>>2] = _mm_hadd_ps(k0
, k2
);
140 out
[0] = _mm_add_ps(out
[0], out
[1]);
141 _mm_store_ps(&dst
[i
], out
[0]);
143 frac4
= _mm_add_epi32(frac4
, increment4
);
144 pos4
= _mm_add_epi32(pos4
, _mm_srli_epi32(frac4
, FRACTIONBITS
));
145 frac4
= _mm_and_si128(frac4
, fracMask4
);
147 _mm_store_ps(pos_
.f
, _mm_castsi128_ps(pos4
));
148 _mm_store_ps(frac_
.f
, _mm_castsi128_ps(frac4
));
154 for(;i
< numsamples
;i
++)
156 dst
[i
] = resample_fir8(src
[pos
], src
[pos
+1], src
[pos
+2], src
[pos
+3],
157 src
[pos
+4], src
[pos
+5], src
[pos
+6], src
[pos
+7], frac
);
160 pos
+= frac
>>FRACTIONBITS
;
161 frac
&= FRACTIONMASK
;