bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fts: expose dirent.d_type data when possible


From: Ralf Wildenhues
Subject: Re: fts: expose dirent.d_type data when possible
Date: Sat, 29 Nov 2008 12:55:49 +0100
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

Hi Jim,

sorry for not looking earier.

* Jim Meyering wrote on Sat, Nov 29, 2008 at 12:00:34PM CET:
> +/* Return the number of bits by which a d_type value must be shifted
> +   left in order to put it into the S_IFMT bits of stat.st_mode.  */
> +static int
> +s_ifmt_shift_bits (void)
> +{
> +  unsigned int v = S_IFMT; /* usually, 0170000 */
> +  static const int MultiplyDeBruijnBitPosition[32] =
> +    {
> +      0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
> +      31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
> +    };
> +
> +  /* Find the smallest power of two, P (e.g., 0010000) such that P & V == P. 
> */
> +  unsigned int p = v ^ (v & (v - 1));
> +
> +  /* Compute and return r = log2 (p), using code from
> +     http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn 
> */
> +  return MultiplyDeBruijnBitPosition[(uint32_t) (p * 0x077CB531UL) >> 27];
> +}

This is a constant you could compute at configure time, no?
See AC_COMPUTE_INT.

Cheers,
Ralf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]