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 InterpState
* UNUSED(state
),
35 const ALfloat
*restrict src
, ALsizei frac
, ALint increment
,
36 ALfloat
*restrict dst
, ALsizei numsamples
)
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) ALsizei 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(sinc4Tab
[frac_
.i
[0]]);
59 __m128 k1
= _mm_load_ps(sinc4Tab
[frac_
.i
[1]]);
60 __m128 k2
= _mm_load_ps(sinc4Tab
[frac_
.i
[2]]);
61 __m128 k3
= _mm_load_ps(sinc4Tab
[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
;