[XviD-devel] Re: Don't do " signed /= unsigned "
Felix von Leitner
xvid-devel@xvid.org
Sun, 19 Jan 2003 04:50:14 +0100
Thus spake Radek Czyz (radoslaw@syskin.cjb.net):
> I think that division is faster than if - am I correct?
No!
I have a VIA C3 CPU here, which is the CPU that needs optimization most,
because it is kind of slow but it is a CPU that is in the stores right
now (unlike ancient K6 or Celeron stuff).
On the C3, a division takes 42 (!) cycles. A branch takes 12 cycles if
it is mispredicted -- and still 5 cycles if it is correctly predicted!
So avoid branches if you can.
> However, I'm sure that some kind of bitshift would be even faster...
> do you know a way to make it a bitshift, but dividing negative values
> correctly?
dx >>= quarterpel;
should do it. -- 1 cycle on all modern CPUs.
Felix