On Sunday 24 February 2013 03:00, Nicolas Pomarède wrote: > On 24/02/2013 08:33, David Savinkoff wrote: > > Hi, > > > > version 2 dmaSnd.c.saturation.2.diff patch enclosed > > > > David > > Hello > > thanks for the patch, I will apply it later ; but I think it would be > more efficient to do : > > sample = DmaSnd_IIRfilterL( Subsonic_IIR_HPF_Left( MixBuffer[nBufIdx][0])) > > if ( sample < -32767 ) > sample = -32767; > else if ( sample > 32767 ) > sample = 32767; > > This remove the "< 0" test and "speed up" (very slightly :) ) the code. > > Statistically, half of sample will be <0 or >0, but only a very small > part will be <-32767 or >32767, so comparing only with these 2 values > should be more efficient. > > Nicolas
Hi
The code above must check for both (< -32767) and (> 32767); = two compares.
My code assumes that the compiler does not actually do a test for (< 0) because the cpu status register notes that a number is negative or zero whenever a number is being accessed.
My code 'efficiently' checks for (< 0), then checks for either (< -32767) or (> 32767): = one compare.