[XviD-devel] Re: Quality optimization
Christoph Lampert
xvid-devel@xvid.org
Sat, 25 Jan 2003 11:41:55 +0100 (CET)
On Sat, 25 Jan 2003, Felix von Leitner wrote:
> Here is a small piece of code for your consideration:
>
> static inline int abs(int x) { return x<0?-x:x; }
>
> static inline int newabs(int x) {
> return (((x>>(sizeof(int)*8-1)) & (x^(-x))) ^ x);
> }
>
> newabs calculates the absolute of a signed integer without branches.
>
> ...
> The good thing about this algorithm is that it can be done in parallel
> using MMX, so we can theoretically do abs(X) and abs(Y) simultaneously.
Since MMX can subtract with saturation, calcuting several abs with MMX
is very
simple and fast already.
gruel