diff options
author | Chris Robinson <[email protected]> | 2018-09-29 18:48:28 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-09-29 18:48:28 -0700 |
commit | d5a78f0843571c55d9c7671c49c4b5a092ae951f (patch) | |
tree | 0a28374d9e723613d6424ee9326ad9a229d8b35f | |
parent | 32494e72a55569b5de1d899663f0c76160e85cd9 (diff) |
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.
-rw-r--r-- | Alc/mastering.c | 22 |
1 files 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; } |