trying to simplify an algorithm

Ian Molton spyro at
Mon Feb 28 03:42:15 PST 2005

Johan V. wrote:

> I know it's very obscured. Think about the wasted clock cycles for a minute,
> the above can be implemented without conditional jumps ...

More to the point though I think technically its broken. Im fairly sure 
C only defines 0 to be false. *all* other values are true, therefore you 
are relying on the compiler to use 1.

also from an assembler standpoint, some CPUs may not be able to 
implement reg = (a>0) without a branch.

best to use conditionals and let the compiler work out how best to fit 
them around the target CPU. (even better to go fix gcc so it does that well)

More information about the lfs-chat mailing list