Re: [hatari-devel] Cracks in the sound (YM+DMA)

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


On 24/02/2013 17:41, David Savinkoff wrote:
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.


Yes, I thought about this implied "<0 or >0 test" after giving a value to "sample", but I think it depends on the cpu architecture and the compiler level of optimisation.

I agree this is the kind of optimisation I would have made when coding directly in asm ; but in the context of a C program, I think it doesn't improve readability and I'd rather let the compiler do the job (even if it's slightly less efficient).

Nicolas



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/