blob: 9206465c770079525d5663d3833026853b0ccee0 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001#ifndef I386_BITOPS_H
2#define I386_BITOPS_H
3
4/**
5 * log2 - Find the truncated log base 2 of x
6 */
7
8static inline unsigned long log2(unsigned long x)
9{
10 unsigned long r = 0;
11 __asm__(
12 "bsrl %1, %0\n\t"
13 "jnz 1f\n\t"
14 "movl $-1, %0\n\t"
15 "1:\n\t"
16 : "=r" (r) : "r" (x));
17 return r;
Stefan Reinauer14e22772010-04-27 06:56:47 +000018
Eric Biederman8ca8d762003-04-22 19:02:15 +000019}
20#endif /* I386_BITOPS_H */