R: [Algorithms] non-branching zbuf code tricks?
Brought to you by:
vexxed72
|
From: Giovanni B. <ba...@pr...> - 2001-01-09 19:36:20
|
> > > >zbuf[x] = z < zbuf[x] ? z : zbuf[x]; [....] > No! There is a significant difference. In my code, I gave > the compile permission to evaluate both 'z' and 'zbuf[x]', > in the '?:' version, you are telling the compiler that it's > only ALLOWED to evaluate one or the other. Hence, in the '?:' > case, the compiler is logically required to generate a branch > but in my version, it *could* generate a SETxx sequence to > evaluate the conditional. Thinking well about it, in the expression above you are already forcing the compiler to evaluate both 'z' and 'zbuf[x]' just to executation the compare. So, the expression above *could* be assembled into a CMOV, just like GCC does on MIPS with MOVN, as Christer showed us. --- Giovanni Bajo Lead Programmer Protonic Interactive www.protonic.net - Black holes are generated when God divides by zero - |