Subversion Repositories HelenOS

Rev

Rev 1702 | Rev 1787 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1702 Rev 1780
Line 40... Line 40...
40
 
40
 
41
/** Return position of first non-zero bit from left (i.e. [log_2(arg)]).
41
/** Return position of first non-zero bit from left (i.e. [log_2(arg)]).
42
 *
42
 *
43
 * If number is zero, it returns 0
43
 * If number is zero, it returns 0
44
 */
44
 */
45
static inline int fnzb32(__u32 arg)
45
static inline int fnzb32(uint32_t arg)
46
{
46
{
47
    int n = 0;
47
    int n = 0;
48
 
48
 
49
    if (arg >> 16) { arg >>= 16;n += 16;}
49
    if (arg >> 16) { arg >>= 16;n += 16;}
50
    if (arg >> 8) { arg >>= 8; n += 8;}
50
    if (arg >> 8) { arg >>= 8; n += 8;}
Line 52... Line 52...
52
    if (arg >> 2) { arg >>= 2; n+=2;}
52
    if (arg >> 2) { arg >>= 2; n+=2;}
53
    if (arg >> 1) { arg >>= 1; n+=1;}
53
    if (arg >> 1) { arg >>= 1; n+=1;}
54
    return n;
54
    return n;
55
}
55
}
56
 
56
 
57
static inline int fnzb64(__u64 arg)
57
static inline int fnzb64(uint64_t arg)
58
{
58
{
59
    int n = 0;
59
    int n = 0;
60
 
60
 
61
    if (arg >> 32) { arg >>= 32;n += 32;}
61
    if (arg >> 32) { arg >>= 32;n += 32;}
62
    return n + fnzb32((__u32) arg);
62
    return n + fnzb32((uint32_t) arg);
63
}
63
}
64
 
64
 
65
#define fnzb(x) fnzb32(x)
65
#define fnzb(x) fnzb32(x)
66
 
66
 
67
#endif
67
#endif