Re: [PATCH] count-leading-zeros: new module

2012-08-13 Thread Bruno Haible
Hi Eric, > I needed gcc's clz to determine the most significant bit of a > number This new module is redundant w.r.t. the 'integer_length', 'integer_length_l', 'integer_length_ll' modules that are in gnulib already since last year: For x != 0: count_leading_zeros (x) = sizeof x * CHAR_BIT - int

Re: [PATCH] count-leading-zeros: new module

2012-08-11 Thread Eric Blake
On 08/11/2012 01:45 AM, Jim Meyering wrote: > Eric Blake wrote: >> I needed gcc's clz to determine the most significant bit of a >> number (useful for things like truncating to a power of 2), >> and was surprised it is not a standardized function > Did you consider using a variant of the following

Re: [PATCH] count-leading-zeros: new module

2012-08-11 Thread Eric Blake
On 08/11/2012 04:23 AM, Ondřej Bílka wrote: >> >> Did you consider using a variant of the following? >> It looks like it would be more efficient. The fallback code is only for non-gcc compilation in the first place, but yes, the de Bruijn table lookup does seem nicer; I'll switch over to using it.

Re: [PATCH] count-leading-zeros: new module

2012-08-11 Thread Eric Blake
On 08/10/2012 10:37 PM, Ben Pfaff wrote: > Eric Blake writes: > >> +/* Expand the code which computes the number of leading zeros of the local >> + variable 'x' of type TYPE (an unsigned integer type) and returns it >> + from the current function. */ >> +#if 0 && __GNUC__ > 3 || (__GNUC__ ==

Re: [PATCH] count-leading-zeros: new module

2012-08-11 Thread Ondřej Bílka
On Sat, Aug 11, 2012 at 09:45:16AM +0200, Jim Meyering wrote: > Eric Blake wrote: > > I needed gcc's clz to determine the most significant bit of a > > number (useful for things like truncating to a power of 2), > > and was surprised it is not a standardized function (the > > opposite direction of

Re: [PATCH] count-leading-zeros: new module

2012-08-11 Thread Jim Meyering
Eric Blake wrote: > I needed gcc's clz to determine the most significant bit of a > number (useful for things like truncating to a power of 2), > and was surprised it is not a standardized function (the > opposite direction of finding the least significant bit is ... > +/* Expand the code which com

Re: [PATCH] count-leading-zeros: new module

2012-08-10 Thread Ben Pfaff
Eric Blake writes: > +/* Expand the code which computes the number of leading zeros of the local > + variable 'x' of type TYPE (an unsigned integer type) and returns it > + from the current function. */ > +#if 0 && __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) Do you really want "0

[PATCH] count-leading-zeros: new module

2012-08-10 Thread Eric Blake
I needed gcc's clz to determine the most significant bit of a number (useful for things like truncating to a power of 2), and was surprised it is not a standardized function (the opposite direction of finding the least significant bit is given by ffs). This borrows heavily from the design of the c