Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux...
[deliverable/linux.git] / tools / include / linux / bitops.h
CommitLineData
88bcea43
ACM
1#ifndef _TOOLS_LINUX_BITOPS_H_
2#define _TOOLS_LINUX_BITOPS_H_
5a116dd2 3
25cd480e 4#include <asm/types.h>
fb72014d 5#include <linux/kernel.h>
a860a608 6#include <linux/compiler.h>
5a116dd2 7
3f34f6c0
IT
8#ifndef __WORDSIZE
9#define __WORDSIZE (__SIZEOF_LONG__ * 8)
10#endif
11
7b39cafb
IM
12#ifndef BITS_PER_LONG
13# define BITS_PER_LONG __WORDSIZE
14#endif
93c49b3e
ACM
15
16#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
17#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
18#define BITS_PER_BYTE 8
19#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
20#define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64))
21#define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32))
22#define BITS_TO_BYTES(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE)
ee3d2504 23
25cd480e
ACM
24extern unsigned int __sw_hweight8(unsigned int w);
25extern unsigned int __sw_hweight16(unsigned int w);
26extern unsigned int __sw_hweight32(unsigned int w);
27extern unsigned long __sw_hweight64(__u64 w);
28
88bcea43
ACM
29/*
30 * Include this here because some architectures need generic_ffs/fls in
31 * scope
32 *
33 * XXX: this needs to be asm/bitops.h, when we get to per arch optimizations
34 */
35#include <asm-generic/bitops.h>
36
b1e5a9be
RR
37#define for_each_set_bit(bit, addr, size) \
38 for ((bit) = find_first_bit((addr), (size)); \
39 (bit) < (size); \
40 (bit) = find_next_bit((addr), (size), (bit) + 1))
41
42/* same as for_each_set_bit() but use bit as value to start with */
307b1cd7 43#define for_each_set_bit_from(bit, addr, size) \
b1e5a9be
RR
44 for ((bit) = find_next_bit((addr), (size), (bit)); \
45 (bit) < (size); \
46 (bit) = find_next_bit((addr), (size), (bit) + 1))
47
fb72014d
ACM
48static inline unsigned long hweight_long(unsigned long w)
49{
50 return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
51}
5a116dd2 52
afcd4f62
ACM
53static inline unsigned fls_long(unsigned long l)
54{
55 if (sizeof(l) == 4)
56 return fls(l);
57 return fls64(l);
58}
59
5a116dd2 60#endif
This page took 0.431387 seconds and 5 git commands to generate.