| 1 |
/* |
| 2 |
* WARNING: Do *NOT* ever include this file, only for internal use! |
| 3 |
*/ |
| 4 |
#ifndef _NFCT_BITOPS_H_ |
| 5 |
#define _NFCT_BITOPS_H_ |
| 6 |
|
| 7 |
static inline void set_bit(int nr, uint32_t *addr) |
| 8 |
{ |
| 9 |
addr[nr >> 5] |= (1UL << (nr & 31)); |
| 10 |
} |
| 11 |
|
| 12 |
static inline void unset_bit(int nr, uint32_t *addr) |
| 13 |
{ |
| 14 |
addr[nr >> 5] &= ~(1UL << (nr & 31)); |
| 15 |
} |
| 16 |
|
| 17 |
static inline void set_bit_u16(int nr, uint16_t *addr) |
| 18 |
{ |
| 19 |
addr[nr >> 4] |= (1UL << (nr & 15)); |
| 20 |
} |
| 21 |
|
| 22 |
static inline void unset_bit_u16(int nr, uint16_t *addr) |
| 23 |
{ |
| 24 |
addr[nr >> 4] &= ~(1UL << (nr & 15)); |
| 25 |
} |
| 26 |
|
| 27 |
static inline void |
| 28 |
set_bitmask_u32(uint32_t *buf1, const uint32_t *buf2, int len) |
| 29 |
{ |
| 30 |
int i; |
| 31 |
|
| 32 |
for (i=0; i<len; i++) |
| 33 |
buf1[i] |= buf2[i]; |
| 34 |
} |
| 35 |
|
| 36 |
static inline void |
| 37 |
unset_bitmask_u32(uint32_t *buf1, const uint32_t *buf2, int len) |
| 38 |
{ |
| 39 |
int i; |
| 40 |
|
| 41 |
for (i=0; i<len; i++) |
| 42 |
buf1[i] &= ~buf2[i]; |
| 43 |
} |
| 44 |
|
| 45 |
static inline int test_bit(int nr, const uint32_t *addr) |
| 46 |
{ |
| 47 |
return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0; |
| 48 |
} |
| 49 |
|
| 50 |
static inline int |
| 51 |
test_bitmask_u32(const uint32_t *buf1, const uint32_t *buf2, int len) |
| 52 |
{ |
| 53 |
int i; |
| 54 |
|
| 55 |
for (i=0; i<len; i++) { |
| 56 |
if ((buf1[i] & buf2[i]) != buf2[i]) { |
| 57 |
return 0; |
| 58 |
} |
| 59 |
} |
| 60 |
return 1; |
| 61 |
} |
| 62 |
|
| 63 |
static inline int |
| 64 |
test_bitmask_u32_or(const uint32_t *buf1, const uint32_t *buf2, int len) |
| 65 |
{ |
| 66 |
int i; |
| 67 |
|
| 68 |
for (i=0; i<len; i++) { |
| 69 |
if (buf1[i] & buf2[i]) { |
| 70 |
return 1; |
| 71 |
} |
| 72 |
} |
| 73 |
return 0; |
| 74 |
} |
| 75 |
|
| 76 |
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
| 77 |
|
| 78 |
#endif |