diff options
Diffstat (limited to 'include/qemu/bitops.h')
-rw-r--r-- | include/qemu/bitops.h | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index 90ca8df..8abdcf9 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -20,10 +20,10 @@ #define BITS_PER_BYTE CHAR_BIT #define BITS_PER_LONG (sizeof (unsigned long) * BITS_PER_BYTE) -#define BIT(nr) (1UL << (nr)) -#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) -#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) -#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) +#define BIT(nr) (1UL << (nr)) +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) /** * set_bit - Set a bit in memory @@ -32,10 +32,10 @@ */ static inline void set_bit(long nr, unsigned long *addr) { - unsigned long mask = BIT_MASK(nr); - unsigned long *p = addr + BIT_WORD(nr); + unsigned long mask = BIT_MASK(nr); + unsigned long *p = addr + BIT_WORD(nr); - *p |= mask; + *p |= mask; } /** @@ -45,10 +45,10 @@ static inline void set_bit(long nr, unsigned long *addr) */ static inline void clear_bit(long nr, unsigned long *addr) { - unsigned long mask = BIT_MASK(nr); - unsigned long *p = addr + BIT_WORD(nr); + unsigned long mask = BIT_MASK(nr); + unsigned long *p = addr + BIT_WORD(nr); - *p &= ~mask; + *p &= ~mask; } /** @@ -58,10 +58,10 @@ static inline void clear_bit(long nr, unsigned long *addr) */ static inline void change_bit(long nr, unsigned long *addr) { - unsigned long mask = BIT_MASK(nr); - unsigned long *p = addr + BIT_WORD(nr); + unsigned long mask = BIT_MASK(nr); + unsigned long *p = addr + BIT_WORD(nr); - *p ^= mask; + *p ^= mask; } /** @@ -71,12 +71,12 @@ static inline void change_bit(long nr, unsigned long *addr) */ static inline int test_and_set_bit(long nr, unsigned long *addr) { - unsigned long mask = BIT_MASK(nr); - unsigned long *p = addr + BIT_WORD(nr); - unsigned long old = *p; + unsigned long mask = BIT_MASK(nr); + unsigned long *p = addr + BIT_WORD(nr); + unsigned long old = *p; - *p = old | mask; - return (old & mask) != 0; + *p = old | mask; + return (old & mask) != 0; } /** @@ -86,12 +86,12 @@ static inline int test_and_set_bit(long nr, unsigned long *addr) */ static inline int test_and_clear_bit(long nr, unsigned long *addr) { - unsigned long mask = BIT_MASK(nr); - unsigned long *p = addr + BIT_WORD(nr); - unsigned long old = *p; + unsigned long mask = BIT_MASK(nr); + unsigned long *p = addr + BIT_WORD(nr); + unsigned long old = *p; - *p = old & ~mask; - return (old & mask) != 0; + *p = old & ~mask; + return (old & mask) != 0; } /** @@ -101,12 +101,12 @@ static inline int test_and_clear_bit(long nr, unsigned long *addr) */ static inline int test_and_change_bit(long nr, unsigned long *addr) { - unsigned long mask = BIT_MASK(nr); - unsigned long *p = addr + BIT_WORD(nr); - unsigned long old = *p; + unsigned long mask = BIT_MASK(nr); + unsigned long *p = addr + BIT_WORD(nr); + unsigned long old = *p; - *p = old ^ mask; - return (old & mask) != 0; + *p = old ^ mask; + return (old & mask) != 0; } /** @@ -116,7 +116,7 @@ static inline int test_and_change_bit(long nr, unsigned long *addr) */ static inline int test_bit(long nr, const unsigned long *addr) { - return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); + return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); } /** @@ -136,7 +136,8 @@ unsigned long find_last_bit(const unsigned long *addr, * @size: The bitmap size in bits */ unsigned long find_next_bit(const unsigned long *addr, - unsigned long size, unsigned long offset); + unsigned long size, + unsigned long offset); /** * find_next_zero_bit - find the next cleared bit in a memory region |