[XviD-devel] Decoder performance

Christoph Lampert chl at math.uni-bonn.de
Sun Aug 10 20:58:54 CEST 2003


On Sun, 10 Aug 2003, Christoph Lampert wrote:

> On Sun, 10 Aug 2003, Edouard Gomez wrote:
> > Oh,  i had  a  nicer  solution than  the  ? operator  for  that (on  the
> > paper). Completely branchless.
> > 
> > #define IS_SET_FLAG(a, flag) \
> >  (!!((a)&(flag)))
> 
> Yes, '!!' is the usual way to make an arithmetic value in to a logical
> "true" or "false". 
> 
> But if I remember correctly, "true" and "false" are not necessarily equal
> to 1 and 0 on all machines, they might be -1 and 0 or just anything
> and 0. So !! is just helpful to compare truthness by '==', but not by
> doing calculations with the result (even though it works on all compilers
> I know of...)

I looked it up: !!x can only have values 0 or 1, so !! is correct, sorry.
(ISO C, 6.5.3.3)

Btw. you can also simulate !!x by shifts:

(((unsigned int) (x | -x)) >> (WORDBITS - 1))

More tricks of this kind can be found at 
http://aggregate.org/MAGIC/

gruel





More information about the XviD-devel mailing list