summaryrefslogtreecommitdiffstats
path: root/include/internal/bitops.h
blob: 0c1fde8d7e7e9bb521cbbd84bb84917aec6b62e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * WARNING: Do *NOT* ever include this file, only for internal use!
 */
#ifndef _NFCT_BITOPS_H_
#define _NFCT_BITOPS_H_

static inline void set_bit(int nr, u_int32_t *addr)
{
	addr[nr >> 5] |= (1UL << (nr & 31));
}

static inline void unset_bit(int nr, u_int32_t *addr)
{
	addr[nr >> 5] &= ~(1UL << (nr & 31));
}

static inline void set_bit_u16(int nr, u_int16_t *addr)
{
	addr[nr >> 4] |= (1UL << (nr & 15));
}

static inline void unset_bit_u16(int nr, u_int16_t *addr)
{
	addr[nr >> 4] &= ~(1UL << (nr & 15));
}

static inline void
set_bitmask_u32(u_int32_t *buf1, const u_int32_t *buf2, int len)
{
	int i;

	for (i=0; i<len; i++)
		buf1[i] |= buf2[i];
}

static inline void
unset_bitmask_u32(u_int32_t *buf1, const u_int32_t *buf2, int len)
{
	int i;

	for (i=0; i<len; i++)
		buf1[i] &= ~buf2[i];
}

static inline int test_bit(int nr, const u_int32_t *addr)
{
	return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
}

static inline int 
test_bitmask_u32(const uint32_t *buf1, const uint32_t *buf2, int len)
{
	int i;

	for (i=0; i<len; i++) {
		if ((buf1[i] & buf2[i]) != buf2[i]) {
			return 0;
		}
	}
	return 1;
}

#endif