[XviD-devel] Don't do " signed /= unsigned "
Christoph Lampert
xvid-devel@xvid.org
Sat, 11 Jan 2003 15:21:37 +0100 (CET)
On Sun, 12 Jan 2003, Radek Czyz wrote:
> Hi,
>
> gruel wrote
>
> > In branch motion_comp.c there is a line
>
> > dx /= (1+quarterpel)
>
> > and this gives me wrong results if dx is signed int (which it is)
> > and quarterpel is unsigned (which I declared that way, since it's a 0 or
> > 1 flag). Division is then done unsigned!
>
> now you know why I made this signed ;)
Yes, I found it out the hard way...
And btw. I just changed 'quarterpel' in decoder-struct to signed, too.
> I think that division is faster than if - am I correct?
I'm not so sure. In theory, division is better than branch, but
since qpel is a constant for the whole sequence, branch prediction might
kick in and the if be faster in the end. We can simply measure it and
decide then.
> 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?
Not really, maybe with an extra if ;-)
if (dx<0) dx++;
dx >>= qpel;
;-p
> PS: @gruel, how's your GME going? :)
Will be commited any minute.
gruel