diff options
author | Chris Robinson <[email protected]> | 2019-01-06 21:09:21 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-01-06 21:16:08 -0800 |
commit | 20a5306bdf8128019748a2d66d2431537714badb (patch) | |
tree | 48df9c1f648cdb9cb9f5e4802c6ff8a6ed78c48f | |
parent | fababe76c4f0482fb2527ef931b84681dd133ca6 (diff) |
Clean up some initializers and use of C methods
-rw-r--r-- | Alc/mixer/hrtf_inc.cpp | 2 | ||||
-rw-r--r-- | Alc/mixer/mixer_c.cpp | 70 | ||||
-rw-r--r-- | Alc/mixer/mixer_sse.cpp | 106 | ||||
-rw-r--r-- | Alc/mixer/mixer_sse2.cpp | 40 | ||||
-rw-r--r-- | Alc/mixer/mixer_sse41.cpp | 40 |
5 files changed, 118 insertions, 140 deletions
diff --git a/Alc/mixer/hrtf_inc.cpp b/Alc/mixer/hrtf_inc.cpp index 6c0824dc..594c6119 100644 --- a/Alc/mixer/hrtf_inc.cpp +++ b/Alc/mixer/hrtf_inc.cpp @@ -155,7 +155,7 @@ void MixDirectHrtf(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat (*data)[BUFFERSIZE], DirectHrtfState *State, const ALsizei NumChans, const ALsizei BufferSize) { - ASSUME(NumChans >= 0); + ASSUME(NumChans > 0); ASSUME(BufferSize > 0); const ALsizei IrSize{State->IrSize}; diff --git a/Alc/mixer/mixer_c.cpp b/Alc/mixer/mixer_c.cpp index 22d3642e..31a5cee4 100644 --- a/Alc/mixer/mixer_c.cpp +++ b/Alc/mixer/mixer_c.cpp @@ -11,35 +11,31 @@ #include "defs.h" -static inline ALfloat do_point(const InterpState*, const ALfloat *RESTRICT vals, ALsizei) noexcept +static inline ALfloat do_point(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei) noexcept { return vals[0]; } -static inline ALfloat do_lerp(const InterpState*, const ALfloat *RESTRICT vals, ALsizei frac) noexcept +static inline ALfloat do_lerp(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei frac) noexcept { return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); } -static inline ALfloat do_cubic(const InterpState*, const ALfloat *RESTRICT vals, ALsizei frac) noexcept +static inline ALfloat do_cubic(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei frac) noexcept { return cubic(vals[0], vals[1], vals[2], vals[3], frac * (1.0f/FRACTIONONE)); } -static inline ALfloat do_bsinc(const InterpState *state, const ALfloat *RESTRICT vals, ALsizei frac) noexcept +static inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, const ALsizei frac) noexcept { - const ALfloat *fil, *scd, *phd, *spd; - ALsizei j_f, pi; - ALfloat pf, r; - - ASSUME(state->bsinc.m > 0); + ASSUME(istate.bsinc.m > 0); // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) - pi = frac >> FRAC_PHASE_BITDIFF; - pf = (frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF)); + const ALsizei pi{frac >> FRAC_PHASE_BITDIFF}; + const ALfloat pf{(frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF))}; #undef FRAC_PHASE_BITDIFF - fil = state->bsinc.filter + state->bsinc.m*pi*4; - scd = fil + state->bsinc.m; - phd = scd + state->bsinc.m; - spd = phd + state->bsinc.m; + const ALfloat *fil{istate.bsinc.filter + istate.bsinc.m*pi*4}; + const ALfloat *scd{fil + istate.bsinc.m}; + const ALfloat *phd{scd + istate.bsinc.m}; + const ALfloat *spd{phd + istate.bsinc.m}; // Apply the scale and phase interpolated filter. - r = 0.0f; - for(j_f = 0;j_f < state->bsinc.m;j_f++) - r += (fil[j_f] + state->bsinc.sf*scd[j_f] + pf*(phd[j_f] + state->bsinc.sf*spd[j_f])) * vals[j_f]; + ALfloat r{0.0f}; + for(ALsizei j_f{0};j_f < istate.bsinc.m;j_f++) + r += (fil[j_f] + istate.bsinc.sf*scd[j_f] + pf*(phd[j_f] + istate.bsinc.sf*spd[j_f])) * vals[j_f]; return r; } @@ -57,7 +53,7 @@ const ALfloat *Resample_copy_C(const InterpState* UNUSED(state), return dst; } -template<ALfloat Sampler(const InterpState*, const ALfloat*RESTRICT, ALsizei) noexcept> +template<ALfloat Sampler(const InterpState&, const ALfloat*RESTRICT, const ALsizei) noexcept> static const ALfloat *DoResample(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei numsamples) @@ -66,11 +62,11 @@ static const ALfloat *DoResample(const InterpState *state, const ALfloat *RESTRI ASSUME(increment > 0); ASSUME(frac >= 0); - const InterpState istate = *state; + const InterpState istate{*state}; std::generate_n<ALfloat*RESTRICT>(dst, numsamples, [&src,&frac,istate,increment]() noexcept -> ALfloat { - ALfloat ret{Sampler(&istate, src, frac)}; + ALfloat ret{Sampler(istate, src, frac)}; frac += increment; src += frac>>FRACTIONBITS; @@ -138,23 +134,21 @@ void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos, ALsizei BufferSize) { - const ALfloat delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f; - ALsizei c; - ASSUME(OutChans > 0); ASSUME(BufferSize > 0); - for(c = 0;c < OutChans;c++) + const ALfloat delta{(Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f}; + for(ALsizei c{0};c < OutChans;c++) { - ALsizei pos = 0; - ALfloat gain = CurrentGains[c]; - const ALfloat diff = TargetGains[c] - gain; + ALsizei pos{0}; + ALfloat gain{CurrentGains[c]}; - if(fabsf(diff) > std::numeric_limits<float>::epsilon()) + const ALfloat diff{TargetGains[c] - gain}; + if(std::fabs(diff) > std::numeric_limits<float>::epsilon()) { - ALsizei minsize = mini(BufferSize, Counter); - const ALfloat step = diff * delta; - ALfloat step_count = 0.0f; + ALsizei minsize{mini(BufferSize, Counter)}; + const ALfloat step{diff * delta}; + ALfloat step_count{0.0f}; for(;pos < minsize;pos++) { OutBuffer[c][OutPos+pos] += data[pos] * (gain + step*step_count); @@ -167,7 +161,7 @@ void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[ CurrentGains[c] = gain; } - if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD)) + if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; for(;pos < BufferSize;pos++) OutBuffer[c][OutPos+pos] += data[pos]*gain; @@ -182,18 +176,16 @@ void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[ */ void MixRow_C(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*RESTRICT data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize) { - ALsizei c, i; - ASSUME(InChans > 0); ASSUME(BufferSize > 0); - for(c = 0;c < InChans;c++) + for(ALsizei c{0};c < InChans;c++) { - const ALfloat gain = Gains[c]; - if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD)) + const ALfloat gain{Gains[c]}; + if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; - for(i = 0;i < BufferSize;i++) + for(ALsizei i{0};i < BufferSize;i++) OutBuffer[i] += data[c][InPos+i] * gain; } } diff --git a/Alc/mixer/mixer_sse.cpp b/Alc/mixer/mixer_sse.cpp index 2637883b..df5270e7 100644 --- a/Alc/mixer/mixer_sse.cpp +++ b/Alc/mixer/mixer_sse.cpp @@ -18,13 +18,9 @@ const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *RESTR 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); - const ALsizei m = state->bsinc.m; - const __m128 *fil, *scd, *phd, *spd; - ALsizei pi, i, j, offset; - ALfloat pf; - __m128 r4; + const ALfloat *const filter{state->bsinc.filter}; + const __m128 sf4{_mm_set1_ps(state->bsinc.sf)}; + const ALsizei m{state->bsinc.m}; ASSUME(m > 0); ASSUME(dstlen > 0); @@ -32,30 +28,30 @@ const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *RESTR ASSUME(frac >= 0); src -= state->bsinc.l; - for(i = 0;i < dstlen;i++) + for(ALsizei i{0};i < dstlen;i++) { // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) - pi = frac >> FRAC_PHASE_BITDIFF; - pf = (frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF)); + const ALsizei pi{frac >> FRAC_PHASE_BITDIFF}; + const ALfloat pf{(frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF))}; #undef FRAC_PHASE_BITDIFF - offset = m*pi*4; - fil = (const __m128*)(filter + offset); offset += m; - scd = (const __m128*)(filter + offset); offset += m; - phd = (const __m128*)(filter + offset); offset += m; - spd = (const __m128*)(filter + offset); + ALsizei offset{m*pi*4}; + const __m128 *fil{(const __m128*)(filter + offset)}; offset += m; + const __m128 *scd{(const __m128*)(filter + offset)}; offset += m; + const __m128 *phd{(const __m128*)(filter + offset)}; offset += m; + const __m128 *spd{(const __m128*)(filter + offset)}; // Apply the scale and phase interpolated filter. - r4 = _mm_setzero_ps(); + __m128 r4{_mm_setzero_ps()}; { - const ALsizei count = m >> 2; - const __m128 pf4 = _mm_set1_ps(pf); + const ALsizei count{m >> 2}; + const __m128 pf4{_mm_set1_ps(pf)}; ASSUME(count > 0); #define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z)) - for(j = 0;j < count;j++) + for(ALsizei j{0};j < count;j++) { /* f = ((fil + sf*scd) + pf*(phd + sf*spd)) */ const __m128 f4 = MLA4( @@ -83,9 +79,7 @@ static inline void ApplyCoeffs(ALsizei Offset, ALfloat (&Values)[HRIR_LENGTH][2] const ALsizei IrSize, const ALfloat (&Coeffs)[HRIR_LENGTH][2], const ALfloat left, const ALfloat right) { - const __m128 lrlr = _mm_setr_ps(left, right, left, right); - __m128 vals = _mm_setzero_ps(); - __m128 coeffs; + const __m128 lrlr{_mm_setr_ps(left, right, left, right)}; ASSUME(IrSize >= 2); ASSUME(&Values != &Coeffs); @@ -97,8 +91,8 @@ static inline void ApplyCoeffs(ALsizei Offset, ALfloat (&Values)[HRIR_LENGTH][2] ASSUME(count >= 1); __m128 imp0, imp1; - coeffs = _mm_load_ps(&Coeffs[0][0]); - vals = _mm_loadl_pi(vals, (__m64*)&Values[Offset][0]); + __m128 coeffs{_mm_load_ps(&Coeffs[0][0])}; + __m128 vals{_mm_loadl_pi(_mm_setzero_ps(), (__m64*)&Values[Offset][0])}; imp0 = _mm_mul_ps(lrlr, coeffs); vals = _mm_add_ps(imp0, vals); _mm_storel_pi((__m64*)&Values[Offset][0], vals); @@ -135,8 +129,8 @@ static inline void ApplyCoeffs(ALsizei Offset, ALfloat (&Values)[HRIR_LENGTH][2] { for(;i < count;i += 2) { - coeffs = _mm_load_ps(&Coeffs[i][0]); - vals = _mm_load_ps(&Values[Offset][0]); + __m128 coeffs{_mm_load_ps(&Coeffs[i][0])}; + __m128 vals{_mm_load_ps(&Values[Offset][0])}; vals = _mm_add_ps(vals, _mm_mul_ps(lrlr, coeffs)); _mm_store_ps(&Values[Offset][0], vals); Offset += 2; @@ -159,34 +153,32 @@ void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos, ALsizei BufferSize) { - const ALfloat delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f; - ALsizei c; - ASSUME(OutChans > 0); ASSUME(BufferSize > 0); - for(c = 0;c < OutChans;c++) + const ALfloat delta{(Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f}; + for(ALsizei c{0};c < OutChans;c++) { - ALsizei pos = 0; - ALfloat gain = CurrentGains[c]; - const ALfloat diff = TargetGains[c] - gain; + ALsizei pos{0}; + ALfloat gain{CurrentGains[c]}; + const ALfloat diff{TargetGains[c] - gain}; - if(fabsf(diff) > std::numeric_limits<float>::epsilon()) + if(std::fabs(diff) > std::numeric_limits<float>::epsilon()) { - ALsizei minsize = mini(BufferSize, Counter); - const ALfloat step = diff * delta; - ALfloat step_count = 0.0f; + ALsizei minsize{mini(BufferSize, Counter)}; + const ALfloat step{diff * delta}; + ALfloat step_count{0.0f}; /* Mix with applying gain steps in aligned multiples of 4. */ if(LIKELY(minsize > 3)) { - const __m128 four4 = _mm_set1_ps(4.0f); - const __m128 step4 = _mm_set1_ps(step); - const __m128 gain4 = _mm_set1_ps(gain); - __m128 step_count4 = _mm_setr_ps(0.0f, 1.0f, 2.0f, 3.0f); - ALsizei todo = minsize >> 2; + const __m128 four4{_mm_set1_ps(4.0f)}; + const __m128 step4{_mm_set1_ps(step)}; + const __m128 gain4{_mm_set1_ps(gain)}; + __m128 step_count4{_mm_setr_ps(0.0f, 1.0f, 2.0f, 3.0f)}; + ALsizei todo{minsize >> 2}; do { - const __m128 val4 = _mm_load_ps(&data[pos]); - __m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]); + const __m128 val4{_mm_load_ps(&data[pos])}; + __m128 dry4{_mm_load_ps(&OutBuffer[c][OutPos+pos])}; #define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z)) /* dry += val * (gain + step*step_count) */ dry4 = MLA4(dry4, val4, MLA4(gain4, step4, step_count4)); @@ -219,15 +211,15 @@ void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer OutBuffer[c][OutPos+pos] += data[pos]*gain; } - if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD)) + if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; if(LIKELY(BufferSize-pos > 3)) { - ALsizei todo = (BufferSize-pos) >> 2; - const __m128 gain4 = _mm_set1_ps(gain); + ALsizei todo{(BufferSize-pos) >> 2}; + const __m128 gain4{_mm_set1_ps(gain)}; do { - const __m128 val4 = _mm_load_ps(&data[pos]); - __m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]); + const __m128 val4{_mm_load_ps(&data[pos])}; + __m128 dry4{_mm_load_ps(&OutBuffer[c][OutPos+pos])}; dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4)); _mm_store_ps(&OutBuffer[c][OutPos+pos], dry4); pos += 4; @@ -240,25 +232,23 @@ void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*RESTRICT data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize) { - ALsizei c; - ASSUME(InChans > 0); ASSUME(BufferSize > 0); - for(c = 0;c < InChans;c++) + for(ALsizei c{0};c < InChans;c++) { - ALsizei pos = 0; - const ALfloat gain = Gains[c]; - if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD)) + const ALfloat gain{Gains[c]}; + if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; + ALsizei pos{0}; if(LIKELY(BufferSize > 3)) { - ALsizei todo = BufferSize >> 2; + ALsizei todo{BufferSize >> 2}; const __m128 gain4 = _mm_set1_ps(gain); do { - const __m128 val4 = _mm_load_ps(&data[c][InPos+pos]); - __m128 dry4 = _mm_load_ps(&OutBuffer[pos]); + const __m128 val4{_mm_load_ps(&data[c][InPos+pos])}; + __m128 dry4{_mm_load_ps(&OutBuffer[pos])}; dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4)); _mm_store_ps(&OutBuffer[pos], dry4); pos += 4; diff --git a/Alc/mixer/mixer_sse2.cpp b/Alc/mixer/mixer_sse2.cpp index 26fe26ba..6408c8f9 100644 --- a/Alc/mixer/mixer_sse2.cpp +++ b/Alc/mixer/mixer_sse2.cpp @@ -31,35 +31,33 @@ const ALfloat *Resample_lerp_SSE2(const InterpState* UNUSED(state), const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei numsamples) { - const __m128i increment4 = _mm_set1_epi32(increment*4); - const __m128 fracOne4 = _mm_set1_ps(1.0f/FRACTIONONE); - const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK); - alignas(16) ALsizei pos_[4], frac_[4]; - __m128i frac4, pos4; - ALsizei todo, pos, i; + 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(increment > 0); ASSUME(frac >= 0); + alignas(16) ALsizei pos_[4], frac_[4]; InitiatePositionArrays(frac, increment, frac_, pos_, 4); - frac4 = _mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3]); - pos4 = _mm_setr_epi32(pos_[0], pos_[1], pos_[2], pos_[3]); + __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])}; - todo = numsamples & ~3; - for(i = 0;i < todo;i += 4) + const ALsizei todo{numsamples & ~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))); - const int pos1 = _mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(1, 1, 1, 1))); - const int pos2 = _mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(2, 2, 2, 2))); - const int pos3 = _mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(3, 3, 3, 3))); - const __m128 val1 = _mm_setr_ps(src[pos0 ], src[pos1 ], src[pos2 ], src[pos3 ]); - const __m128 val2 = _mm_setr_ps(src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1]); + const int pos0{_mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(0, 0, 0, 0)))}; + const int pos1{_mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(1, 1, 1, 1)))}; + const int pos2{_mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(2, 2, 2, 2)))}; + const int pos3{_mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(3, 3, 3, 3)))}; + const __m128 val1{_mm_setr_ps(src[pos0 ], src[pos1 ], src[pos2 ], src[pos3 ])}; + const __m128 val2{_mm_setr_ps(src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1])}; /* val1 + (val2-val1)*mu */ - const __m128 r0 = _mm_sub_ps(val2, val1); - const __m128 mu = _mm_mul_ps(_mm_cvtepi32_ps(frac4), fracOne4); - const __m128 out = _mm_add_ps(val1, _mm_mul_ps(mu, r0)); + const __m128 r0{_mm_sub_ps(val2, val1)}; + const __m128 mu{_mm_mul_ps(_mm_cvtepi32_ps(frac4), fracOne4)}; + const __m128 out{_mm_add_ps(val1, _mm_mul_ps(mu, r0))}; _mm_store_ps(&dst[i], out); @@ -71,10 +69,10 @@ const ALfloat *Resample_lerp_SSE2(const InterpState* UNUSED(state), /* NOTE: These four elements represent the position *after* the last four * samples, so the lowest element is the next position to resample. */ - pos = _mm_cvtsi128_si32(pos4); + ALsizei pos{_mm_cvtsi128_si32(pos4)}; frac = _mm_cvtsi128_si32(frac4); - for(;i < numsamples;++i) + for(ALsizei i{todo};i < numsamples;++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 cfda905b..fea03764 100644 --- a/Alc/mixer/mixer_sse41.cpp +++ b/Alc/mixer/mixer_sse41.cpp @@ -32,35 +32,33 @@ const ALfloat *Resample_lerp_SSE41(const InterpState* UNUSED(state), const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei numsamples) { - const __m128i increment4 = _mm_set1_epi32(increment*4); - const __m128 fracOne4 = _mm_set1_ps(1.0f/FRACTIONONE); - const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK); - alignas(16) ALsizei pos_[4], frac_[4]; - __m128i frac4, pos4; - ALsizei todo, pos, i; + 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(increment > 0); ASSUME(frac >= 0); + alignas(16) ALsizei pos_[4], frac_[4]; InitiatePositionArrays(frac, increment, frac_, pos_, 4); - frac4 = _mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3]); - pos4 = _mm_setr_epi32(pos_[0], pos_[1], pos_[2], pos_[3]); + __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])}; - todo = numsamples & ~3; - for(i = 0;i < todo;i += 4) + const ALsizei todo{numsamples & ~3}; + for(ALsizei i{0};i < todo;i += 4) { - const int pos0 = _mm_extract_epi32(pos4, 0); - const int pos1 = _mm_extract_epi32(pos4, 1); - const int pos2 = _mm_extract_epi32(pos4, 2); - const int pos3 = _mm_extract_epi32(pos4, 3); - const __m128 val1 = _mm_setr_ps(src[pos0 ], src[pos1 ], src[pos2 ], src[pos3 ]); - const __m128 val2 = _mm_setr_ps(src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1]); + const int pos0{_mm_extract_epi32(pos4, 0)}; + const int pos1{_mm_extract_epi32(pos4, 1)}; + const int pos2{_mm_extract_epi32(pos4, 2)}; + const int pos3{_mm_extract_epi32(pos4, 3)}; + const __m128 val1{_mm_setr_ps(src[pos0 ], src[pos1 ], src[pos2 ], src[pos3 ])}; + const __m128 val2{_mm_setr_ps(src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1])}; /* val1 + (val2-val1)*mu */ - const __m128 r0 = _mm_sub_ps(val2, val1); - const __m128 mu = _mm_mul_ps(_mm_cvtepi32_ps(frac4), fracOne4); - const __m128 out = _mm_add_ps(val1, _mm_mul_ps(mu, r0)); + const __m128 r0{_mm_sub_ps(val2, val1)}; + const __m128 mu{_mm_mul_ps(_mm_cvtepi32_ps(frac4), fracOne4)}; + const __m128 out{_mm_add_ps(val1, _mm_mul_ps(mu, r0))}; _mm_store_ps(&dst[i], out); @@ -72,10 +70,10 @@ const ALfloat *Resample_lerp_SSE41(const InterpState* UNUSED(state), /* NOTE: These four elements represent the position *after* the last four * samples, so the lowest element is the next position to resample. */ - pos = _mm_cvtsi128_si32(pos4); + ALsizei pos{_mm_cvtsi128_si32(pos4)}; frac = _mm_cvtsi128_si32(frac4); - for(;i < numsamples;++i) + for(ALsizei i{todo};i < numsamples;++i) { dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE)); |