[XviD-devel] qpel - problems I found

Christoph Lampert xvid-devel@xvid.org
Sat, 12 Oct 2002 16:21:34 +0200 (CEST)


On Sat, 12 Oct 2002, Michael Militzer wrote:

Standard says: dx>>1 for negative dx is "implementation defined", so 
it will always give the same value (it's not "undefined"), but which value
depends on the compiler. However, I have never met a C-compiler with
didn't simply shift everything to the negative values to the right, adding
the correct sign bit (so   0xFFFF >>1   = 0xFFFF) 

> vectors are not simply halfed but rounded to the next halfpel value using
> this table:
> 
> fourth pixel position    0    1    2    3
> resulting position        0    1    1    1

Which means _what_ for negative values? I guess -1 qpel is in fact a 3? 
Then we would have to round  

-4 => -2 
-3 => -1  
-2 => -1 
-1 => -1
 0 =>  0 
 1 =>  1
 2 =>  1
 3 =>  1
 4 =>  2


> so:
>     dx = (dx / 2) | (dx & 1);
>     dy = (dy / 2) | (dy & 1);
> 
> should be ok then...

NO! That surely isn't, because / might change the sign bit from 1 to 0,
which doesn't fit to the | afterwards. 

(-1)/2  = 0     (-1)&1 = 1     -> total result +1 (!!!)
(-1)>>1 = -1    (-1)&1 = 1     -> total result -1

(-2)/2  = -1    (-2)&1 = 0     -> total result -1
(-1)>>1 = -1    (-2)&1 = 0     -> total result -1 

(-3)/2  = -1    (-3)&1 = 1     -> total result -1
(-3)>>1 = -1    (-3)&1 = 1     -> total result -1

(-4)/2  = -2    (-4)&1 = 0     -> total result -2 
(-4)>>1 = -2    (-4)&1 = 0     -> total result -2

To me, the shift method seems correct... 

gruel