RFC: Simplify rules for ctz/clz patterns and RTL

Segher Boessenkool segher@kernel.crashing.org
Mon Aug 13 00:13:00 GMT 2007


> I suppose you're using (assuming 32-bit)
>
> 	ctz(x) := 31 - clz(x & -x)
>
> now, which gives -1 for 0; and the version you're looking for is
>
> 	ctz(x) := 32 - clz(~x & (x-1))
>
> which gives 32 for 0.
>
> (Straight from the venerable PowerPC Compiler Writer's Guide, btw).
>
> What does the popcount version look like?  Never seen that before,
> but I think it will be really expensive on PowerPC.

Never mind, too trivial, given the second of the above.


Segher



More information about the Gcc mailing list