Re: [AD] Allegro's mixer

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Wednesday 17 March 2004 18:44, Chris wrote:
> Ben Davis wrote:
> >DUMB manages to combine 24-bit samples with a 16-bit volume:
> >
> >#define MULSC(a, b) ((int)((LONG_LONG)((a) << 4) * ((b) << 12) >> 32))
>
> Wouldn't ((int)((LONG_LONG)(a) * (b) >> 16)) be faster?

Nope. It uses shrdl, an instruction for shifting EAX right and copying bits 
from EDX into the top of it, and this instruction is slow. The code DUMB uses 
only shifts 32-bit registers, because the ">> 32" translates into simply 
using the value in EDX after the multiply. (At least that's what GCC 3.x 
does. I haven't investigated other x86 compilers.)

> And that code 
> uses LONG_LONG, which is 64-bit. Those are dangerous to use in
> interrupts/timers.

Nope. It's only GCC's division helper routine that's dangerous, because the 
memory it resides in can't be locked. The above code compiles only to 
instructions, no calls to routines anywhere, so it's perfectly safe.

Ben




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