[U-Boot-Users] [PATCH v2] ppc: Added fls, fls64, __ilog2_u64, and ffs64 to bitops

Haavard Skinnemoen haavard.skinnemoen at atmel.com
Wed Jun 11 16:51:58 CEST 2008


Kumar Gala <galak at kernel.crashing.org> wrote:
> +/*
> + * fls: find last (most-significant) bit set.
> + * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
> + */
> +static __inline__ int fls(unsigned int x)
> +{
> +	return __ilog2(x) + 1;

I was sort of hoping you'd add a comment here explaining why it's safe
to rely on undefined behaviour in this particular case. Something like

/* On powerpc, __ilog2(0) returns -1, but this is not safe in general */

Haavard




More information about the U-Boot mailing list