Always declare a native-tools build target
[openal-soft.git] / Alc / mixer_sse3.c
blobd60fed5f8f2eb80a1667a378c2c6796c89967bb0
1 /**
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
24 #include "config.h"
26 #include <xmmintrin.h>
27 #include <emmintrin.h>
28 #include <pmmintrin.h>
30 #include "alu.h"
31 #include "mixer_defs.h"
34 const ALfloat *Resample_fir4_SSE3(const InterpState *state,
35 const ALfloat *restrict src, ALsizei frac, ALint increment,
36 ALfloat *restrict dst, ALsizei numsamples)
38 const ALfloat (*restrict filter)[4] = ASSUME_ALIGNED(state->sinc4.filter, 16);
39 const __m128i increment4 = _mm_set1_epi32(increment*4);
40 const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
41 union { alignas(16) ALint i[4]; float f[4]; } pos_;
42 union { alignas(16) ALsizei i[4]; float f[4]; } frac_;
43 __m128i frac4, pos4;
44 ALint pos;
45 ALsizei i;
47 InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4);
49 frac4 = _mm_castps_si128(_mm_load_ps(frac_.f));
50 pos4 = _mm_castps_si128(_mm_load_ps(pos_.f));
52 --src;
53 for(i = 0;numsamples-i > 3;i += 4)
55 const __m128 val0 = _mm_loadu_ps(&src[pos_.i[0]]);
56 const __m128 val1 = _mm_loadu_ps(&src[pos_.i[1]]);
57 const __m128 val2 = _mm_loadu_ps(&src[pos_.i[2]]);
58 const __m128 val3 = _mm_loadu_ps(&src[pos_.i[3]]);
59 __m128 k0 = _mm_load_ps(filter[frac_.i[0]]);
60 __m128 k1 = _mm_load_ps(filter[frac_.i[1]]);
61 __m128 k2 = _mm_load_ps(filter[frac_.i[2]]);
62 __m128 k3 = _mm_load_ps(filter[frac_.i[3]]);
63 __m128 out;
65 k0 = _mm_mul_ps(k0, val0);
66 k1 = _mm_mul_ps(k1, val1);
67 k2 = _mm_mul_ps(k2, val2);
68 k3 = _mm_mul_ps(k3, val3);
69 k0 = _mm_hadd_ps(k0, k1);
70 k2 = _mm_hadd_ps(k2, k3);
71 out = _mm_hadd_ps(k0, k2);
73 _mm_store_ps(&dst[i], out);
75 frac4 = _mm_add_epi32(frac4, increment4);
76 pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
77 frac4 = _mm_and_si128(frac4, fracMask4);
79 _mm_store_ps(pos_.f, _mm_castsi128_ps(pos4));
80 _mm_store_ps(frac_.f, _mm_castsi128_ps(frac4));
83 /* NOTE: These four elements represent the position *after* the last four
84 * samples, so the lowest element is the next position to resample.
86 pos = pos_.i[0];
87 frac = frac_.i[0];
89 for(;i < numsamples;i++)
91 dst[i] = resample_fir4(src[pos], src[pos+1], src[pos+2], src[pos+3], filter[frac]);
93 frac += increment;
94 pos += frac>>FRACTIONBITS;
95 frac &= FRACTIONMASK;
97 return dst;