[XviD-devel] Coding tricks...

Christoph Lampert chl at math.uni-bonn.de
Mon Aug 18 17:12:34 CEST 2003


On 18 Aug 2003, skal wrote:
> On Sun, 2003-08-10 at 20:22, Christoph Lampert wrote:
> > A branchless, lookup-free, alternative to code like if (a<b) x=c; else x=d; 
> > is 
> > 
> > ((((a-b) >> (WORDBITS-1)) & (c^d)) ^ d)
> > 
> 
> 	i'm a big fan of such tricks, BUT they should nevertheless
> 	be used with care, coz:

Don't be so humble, Skal, you're the _master_ of such tricks ;-) 

> 	a) instruction count is higher
> 	b) more important: both 'c' and 'd' expressions
> 	are evaluated, no matter what. This can be a severe
> 	trap if hidden inside a macro...

Yes, very true... you always have to be careful. 
Also, for PIII and Athlon none of those seem to be better than 
compiler-optimization of 'if' using CMOV etc. But for P4 with very long
pipeline it might be worth testing. 

gruel 




More information about the XviD-devel mailing list