aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/mixer
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-01-23 11:11:41 -0800
committerChris Robinson <[email protected]>2019-01-23 11:11:41 -0800
commit23179d0bcdd27d2b5ab5ddf0e38b180e2d6969e6 (patch)
treef42d1323eada3d1f2a1f9c053eba6d6784a0a1ee /Alc/mixer
parente332ac852892327d913ce8adfbb85bf30c8ccd24 (diff)
Use a template declaration for the resampler functions
Diffstat (limited to 'Alc/mixer')
-rw-r--r--Alc/mixer/defs.h47
-rw-r--r--Alc/mixer/mixer_c.cpp49
-rw-r--r--Alc/mixer/mixer_neon.cpp19
-rw-r--r--Alc/mixer/mixer_sse.cpp6
-rw-r--r--Alc/mixer/mixer_sse2.cpp13
-rw-r--r--Alc/mixer/mixer_sse41.cpp13
6 files changed, 70 insertions, 77 deletions
diff --git a/Alc/mixer/defs.h b/Alc/mixer/defs.h
index 649e6d44..4b1e0303 100644
--- a/Alc/mixer/defs.h
+++ b/Alc/mixer/defs.h
@@ -12,12 +12,22 @@ struct MixHrtfParams;
struct HrtfState;
struct DirectHrtfState;
-/* C resamplers */
-const ALfloat *Resample_copy_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen);
-const ALfloat *Resample_point_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen);
-const ALfloat *Resample_lerp_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen);
-const ALfloat *Resample_cubic_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen);
-const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen);
+
+struct CTag { };
+struct SSETag { };
+struct SSE2Tag { };
+struct SSE3Tag { };
+struct SSE4Tag { };
+struct NEONTag { };
+
+struct CopyTag { };
+struct PointTag { };
+struct LerpTag { };
+struct CubicTag { };
+struct BSincTag { };
+
+template<typename TypeTag, typename InstTag>
+const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen);
/* C mixers */
@@ -58,14 +68,12 @@ void Mix_SSE(const ALfloat *data, const ALsizei OutChans, ALfloat (*OutBuffer)[B
void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*data)[BUFFERSIZE],
const ALsizei InChans, const ALsizei InPos, const ALsizei BufferSize);
-/* SSE resamplers */
+/* Vectorized resampler helpers */
inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *RESTRICT frac_arr, ALsizei *RESTRICT pos_arr, ALsizei size)
{
- ALsizei i;
-
pos_arr[0] = 0;
frac_arr[0] = frac;
- for(i = 1;i < size;i++)
+ for(ALsizei i{1};i < size;i++)
{
ALint frac_tmp = frac_arr[i-1] + increment;
pos_arr[i] = pos_arr[i-1] + (frac_tmp>>FRACTIONBITS);
@@ -73,17 +81,6 @@ inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *RESTR
}
}
-const ALfloat *Resample_lerp_SSE2(const InterpState *state, const ALfloat *RESTRICT src,
- ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
- ALsizei numsamples);
-const ALfloat *Resample_lerp_SSE41(const InterpState *state, const ALfloat *RESTRICT src,
- ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
- ALsizei numsamples);
-
-const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *RESTRICT src,
- ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
- ALsizei dstlen);
-
/* Neon mixers */
void MixHrtf_Neon(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut,
const ALfloat *data, ALsizei Offset, const ALsizei OutPos,
@@ -103,12 +100,4 @@ void Mix_Neon(const ALfloat *data, const ALsizei OutChans, ALfloat (*OutBuffer)[
void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*data)[BUFFERSIZE],
const ALsizei InChans, const ALsizei InPos, const ALsizei BufferSize);
-/* Neon resamplers */
-const ALfloat *Resample_lerp_Neon(const InterpState *state, const ALfloat *RESTRICT src,
- ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
- ALsizei numsamples);
-const ALfloat *Resample_bsinc_Neon(const InterpState *state, const ALfloat *RESTRICT src,
- ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
- ALsizei dstlen);
-
#endif /* MIXER_DEFS_H */
diff --git a/Alc/mixer/mixer_c.cpp b/Alc/mixer/mixer_c.cpp
index 0d8b1d5f..5f9f45a2 100644
--- a/Alc/mixer/mixer_c.cpp
+++ b/Alc/mixer/mixer_c.cpp
@@ -39,17 +39,18 @@ static inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRIC
return r;
}
-const ALfloat *Resample_copy_C(const InterpState* UNUSED(state),
- const ALfloat *RESTRICT src, ALsizei UNUSED(frac), ALint UNUSED(increment),
- ALfloat *RESTRICT dst, ALsizei numsamples)
+template<>
+const ALfloat *Resample_<CopyTag,CTag>(const InterpState* UNUSED(state),
+ const ALfloat *RESTRICT src, ALsizei UNUSED(frac), ALint UNUSED(increment),
+ ALfloat *RESTRICT dst, ALsizei dstlen)
{
- ASSUME(numsamples > 0);
+ ASSUME(dstlen > 0);
#if defined(HAVE_SSE) || defined(HAVE_NEON)
/* Avoid copying the source data if it's aligned like the destination. */
if((reinterpret_cast<intptr_t>(src)&15) == (reinterpret_cast<intptr_t>(dst)&15))
return src;
#endif
- std::copy_n(src, numsamples, dst);
+ std::copy_n(src, dstlen, dst);
return dst;
}
@@ -78,25 +79,25 @@ static const ALfloat *DoResample(const InterpState *state, const ALfloat *RESTRI
return dst;
}
-const ALfloat *Resample_point_C(const InterpState *state, const ALfloat *RESTRICT src,
- ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
- ALsizei numsamples)
-{ return DoResample<do_point>(state, src, frac, increment, dst, numsamples); }
-
-const ALfloat *Resample_lerp_C(const InterpState *state, const ALfloat *RESTRICT src,
- ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
- ALsizei numsamples)
-{ return DoResample<do_lerp>(state, src, frac, increment, dst, numsamples); }
-
-const ALfloat *Resample_cubic_C(const InterpState *state, const ALfloat *RESTRICT src,
- ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
- ALsizei numsamples)
-{ return DoResample<do_cubic>(state, src-1, frac, increment, dst, numsamples); }
-
-const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *RESTRICT src,
- ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
- ALsizei numsamples)
-{ return DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst, numsamples); }
+template<>
+const ALfloat *Resample_<PointTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{ return DoResample<do_point>(state, src, frac, increment, dst, dstlen); }
+
+template<>
+const ALfloat *Resample_<LerpTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{ return DoResample<do_lerp>(state, src, frac, increment, dst, dstlen); }
+
+template<>
+const ALfloat *Resample_<CubicTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{ return DoResample<do_cubic>(state, src-1, frac, increment, dst, dstlen); }
+
+template<>
+const ALfloat *Resample_<BSincTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{ return DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst, dstlen); }
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (&Values)[HRIR_LENGTH][2],
diff --git a/Alc/mixer/mixer_neon.cpp b/Alc/mixer/mixer_neon.cpp
index 8d70d979..d9eac59c 100644
--- a/Alc/mixer/mixer_neon.cpp
+++ b/Alc/mixer/mixer_neon.cpp
@@ -12,9 +12,10 @@
#include "defs.h"
-const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state),
+template<>
+const ALfloat *Resample_<LerpTag,NEONTag>(const InterpState* UNUSED(state),
const ALfloat *RESTRICT src, ALsizei frac, ALint increment,
- ALfloat *RESTRICT dst, ALsizei numsamples)
+ ALfloat *RESTRICT dst, ALsizei dstlen)
{
const int32x4_t increment4 = vdupq_n_s32(increment*4);
const float32x4_t fracOne4 = vdupq_n_f32(1.0f/FRACTIONONE);
@@ -23,15 +24,15 @@ const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state),
int32x4_t pos4, frac4;
ALsizei todo, pos, i;
- ASSUME(numsamples > 0);
- ASSUME(increment > 0);
ASSUME(frac >= 0);
+ ASSUME(increment > 0);
+ ASSUME(dstlen > 0);
InitiatePositionArrays(frac, increment, frac_, pos_, 4);
frac4 = vld1q_s32(frac_);
pos4 = vld1q_s32(pos_);
- todo = numsamples & ~3;
+ todo = dstlen & ~3;
for(i = 0;i < todo;i += 4)
{
const int pos0 = vgetq_lane_s32(pos4, 0);
@@ -59,7 +60,7 @@ const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state),
pos = vgetq_lane_s32(pos4, 0);
frac = vgetq_lane_s32(frac4, 0);
- for(;i < numsamples;++i)
+ for(;i < dstlen;++i)
{
dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
@@ -70,9 +71,9 @@ const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state),
return dst;
}
-const ALfloat *Resample_bsinc_Neon(const InterpState *state,
- const ALfloat *RESTRICT src, ALsizei frac, ALint increment,
- ALfloat *RESTRICT dst, ALsizei dstlen)
+template<>
+const ALfloat *Resample_<BSincTag,NEONTag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
{
const ALfloat *const filter = state->bsinc.filter;
const float32x4_t sf4 = vdupq_n_f32(state->bsinc.sf);
diff --git a/Alc/mixer/mixer_sse.cpp b/Alc/mixer/mixer_sse.cpp
index d18af086..ec0fbfc5 100644
--- a/Alc/mixer/mixer_sse.cpp
+++ b/Alc/mixer/mixer_sse.cpp
@@ -14,9 +14,9 @@
#include "defs.h"
-const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *RESTRICT src,
- ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
- ALsizei dstlen)
+template<>
+const ALfloat *Resample_<BSincTag,SSETag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
{
const ALfloat *const filter{state->bsinc.filter};
const __m128 sf4{_mm_set1_ps(state->bsinc.sf)};
diff --git a/Alc/mixer/mixer_sse2.cpp b/Alc/mixer/mixer_sse2.cpp
index 6408c8f9..2b594d90 100644
--- a/Alc/mixer/mixer_sse2.cpp
+++ b/Alc/mixer/mixer_sse2.cpp
@@ -27,24 +27,25 @@
#include "defs.h"
-const ALfloat *Resample_lerp_SSE2(const InterpState* UNUSED(state),
+template<>
+const ALfloat *Resample_<LerpTag,SSE2Tag>(const InterpState* UNUSED(state),
const ALfloat *RESTRICT src, ALsizei frac, ALint increment,
- ALfloat *RESTRICT dst, ALsizei numsamples)
+ ALfloat *RESTRICT dst, ALsizei dstlen)
{
const __m128i increment4{_mm_set1_epi32(increment*4)};
const __m128 fracOne4{_mm_set1_ps(1.0f/FRACTIONONE)};
const __m128i fracMask4{_mm_set1_epi32(FRACTIONMASK)};
- ASSUME(numsamples > 0);
+ ASSUME(frac > 0);
ASSUME(increment > 0);
- ASSUME(frac >= 0);
+ ASSUME(dstlen >= 0);
alignas(16) ALsizei pos_[4], frac_[4];
InitiatePositionArrays(frac, increment, frac_, pos_, 4);
__m128i frac4{_mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3])};
__m128i pos4{_mm_setr_epi32(pos_[0], pos_[1], pos_[2], pos_[3])};
- const ALsizei todo{numsamples & ~3};
+ const ALsizei todo{dstlen & ~3};
for(ALsizei i{0};i < todo;i += 4)
{
const int pos0{_mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(0, 0, 0, 0)))};
@@ -72,7 +73,7 @@ const ALfloat *Resample_lerp_SSE2(const InterpState* UNUSED(state),
ALsizei pos{_mm_cvtsi128_si32(pos4)};
frac = _mm_cvtsi128_si32(frac4);
- for(ALsizei i{todo};i < numsamples;++i)
+ for(ALsizei i{todo};i < dstlen;++i)
{
dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
diff --git a/Alc/mixer/mixer_sse41.cpp b/Alc/mixer/mixer_sse41.cpp
index fea03764..55639f11 100644
--- a/Alc/mixer/mixer_sse41.cpp
+++ b/Alc/mixer/mixer_sse41.cpp
@@ -28,24 +28,25 @@
#include "defs.h"
-const ALfloat *Resample_lerp_SSE41(const InterpState* UNUSED(state),
+template<>
+const ALfloat *Resample_<LerpTag,SSE4Tag>(const InterpState* UNUSED(state),
const ALfloat *RESTRICT src, ALsizei frac, ALint increment,
- ALfloat *RESTRICT dst, ALsizei numsamples)
+ ALfloat *RESTRICT dst, ALsizei dstlen)
{
const __m128i increment4{_mm_set1_epi32(increment*4)};
const __m128 fracOne4{_mm_set1_ps(1.0f/FRACTIONONE)};
const __m128i fracMask4{_mm_set1_epi32(FRACTIONMASK)};
- ASSUME(numsamples > 0);
+ ASSUME(frac > 0);
ASSUME(increment > 0);
- ASSUME(frac >= 0);
+ ASSUME(dstlen >= 0);
alignas(16) ALsizei pos_[4], frac_[4];
InitiatePositionArrays(frac, increment, frac_, pos_, 4);
__m128i frac4{_mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3])};
__m128i pos4{_mm_setr_epi32(pos_[0], pos_[1], pos_[2], pos_[3])};
- const ALsizei todo{numsamples & ~3};
+ const ALsizei todo{dstlen & ~3};
for(ALsizei i{0};i < todo;i += 4)
{
const int pos0{_mm_extract_epi32(pos4, 0)};
@@ -73,7 +74,7 @@ const ALfloat *Resample_lerp_SSE41(const InterpState* UNUSED(state),
ALsizei pos{_mm_cvtsi128_si32(pos4)};
frac = _mm_cvtsi128_si32(frac4);
- for(ALsizei i{todo};i < numsamples;++i)
+ for(ALsizei i{todo};i < dstlen;++i)
{
dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));