Jim Meyering wrote:
> + /* Find the smallest power of two, P (e.g., 0010000) such that P & V == P.
> */
> + unsigned int p = v ^ (v & (v - 1));
This is equivalent to
unsigned int p = v & ~(v - 1);
This latter expression may be clearer (depending on the reader's mental model of
bitwise expressions).
> + /* Compute and return r = log2 (p), using code from
> + http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
> */
> + return MultiplyDeBruijnBitPosition[(uint32_t) (p * 0x077CB531UL) >> 27];
Why is this done at runtime? Is S_IFMT not guaranteed to be a compile-time
constant?
Bruno