Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | #ifndef I386_BITOPS_H |
2 | #define I386_BITOPS_H | ||||
3 | |||||
4 | /** | ||||
5 | * log2 - Find the truncated log base 2 of x | ||||
6 | */ | ||||
7 | |||||
8 | static 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 Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 18 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 19 | } |
20 | #endif /* I386_BITOPS_H */ |