From d5a78f0843571c55d9c7671c49c4b5a092ae951f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 29 Sep 2018 18:48:28 -0700 Subject: Improve a couple loops Avoid masking the index with each iteration, and instead do up to when the mask would apply. This allows for better optimizations, in particular fewer instructions and better chances for vectorization. --- Alc/mastering.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Alc/mastering.c b/Alc/mastering.c index 285f2f6d..fb831f46 100644 --- a/Alc/mastering.c +++ b/Alc/mastering.c @@ -18,7 +18,7 @@ extern inline ALuint GetCompressorSampleRate(const Compressor *Comp); * * http://www.richardhartersworld.com/cri/2001/slidingmin.html */ -static ALfloat UpdateSlidingHold(SlidingHold *Hold, const ALsizei i, const ALfloat in) +ALfloat UpdateSlidingHold(SlidingHold *Hold, const ALsizei i, const ALfloat in) { const ALsizei mask = BUFFERSIZE - 1; const ALsizei length = Hold->Length; @@ -38,8 +38,14 @@ static ALfloat UpdateSlidingHold(SlidingHold *Hold, const ALsizei i, const ALflo } else { - while(in >= values[lowerIndex]) - lowerIndex = (lowerIndex - 1) & mask; + do { + do { + if(!(in >= values[lowerIndex])) + goto found_place; + } while(lowerIndex--); + lowerIndex = mask; + } while(1); + found_place: lowerIndex = (lowerIndex + 1) & mask; values[lowerIndex] = in; @@ -54,16 +60,18 @@ static ALfloat UpdateSlidingHold(SlidingHold *Hold, const ALsizei i, const ALflo static void ShiftSlidingHold(SlidingHold *Hold, const ALsizei n) { - const ALsizei mask = BUFFERSIZE - 1; const ALsizei lowerIndex = Hold->LowerIndex; ALsizei *restrict expiries = Hold->Expiries; ALsizei i = Hold->UpperIndex; - while(i != lowerIndex) + if(lowerIndex < i) { - expiries[i] -= n; - i = (i + 1) & mask; + for(;i != BUFFERSIZE;i++) + expiries[i] -= n; + i = 0; } + for(;i != lowerIndex;i++) + expiries[i] -= n; expiries[i] -= n; } -- cgit v1.2.3