Ralf Wildenhues <[EMAIL PROTECTED]> wrote: > Hi Jim, > > sorry for not looking earier.
Hi Ralf, Thanks for looking. > * 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. Sure, but why bother? Since any decent compiler will optimize that function to "return 12;", I prefer to leave the function right next to the code that uses it. Of course, if there is ever a second place where we need to map d_type to the type in stat.st_mode, I'll factor it into a new module.