Bit twiddling builtins

Richard Henderson rth@redhat.com
Tue Feb 4 21:21:00 GMT 2003


On Tue, Feb 04, 2003 at 10:22:33AM +0000, Richard Earnshaw wrote:
> My personal opinion is that the "user-visible" function __builtin_clz(x) 
> should be well-defined for all values of x, with x=0 resulting in the 
> answer MODE_SIZE(x).  That means that the *default* expansion of the 
> builtin would have to be
> 
> 	if (x == 0)
> 		(set (result) (const_int MODE_SIZE))
> 	else
> 		(set (result) (clz:M x))

I think this would be a mistake.  I think more often than not the
context in which this gets used the programmer will already know
that the value is non-zero, but that won't necessarily be apparent
to the compiler.

I would be willing to attempt to recognize this pattern *in source*
and replace with just clz, as appropriate.


r~



More information about the Gcc-patches mailing list