aboutsummaryrefslogtreecommitdiffstats
path: root/utils/keytable/bpf_protocols/bitmap.h
blob: e3d731ad7ab167a6facad6b05c8fb92da4246ce3 (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
#ifndef __BITMAP_H__
#define __BITMAP_H__

#include "string.h"

#define BITS_PER_LONG 64
#define BITS_TO_LONG(n) \
	(((n) + BITS_PER_LONG - 1) / BITS_PER_LONG)


#define DECLARE_BITMAP(name, bits) \
	unsigned long name[BITS_TO_LONG(bits)]

static void inline bitmap_zero(unsigned long *bitmap, int bits)
{
	for (int i = 0; i < BITS_TO_LONG(bits); i++)
		bitmap[i] = 0;
}

static void inline bitmap_fill(unsigned long *bitmap, int bits)
{
	for (int i = 0; i < BITS_TO_LONG(bits); i++)
		bitmap[i] = ~0;
}

#define bitmap_set(b, n) \
	b[n / BITS_PER_LONG] |= 1 << (n % BITS_PER_LONG)

#define bitmap_clear(b, n) \
	b[n / BITS_PER_LONG] &= ~(1 << (n % BITS_PER_LONG))

#define bitmap_test(b, n) \
	(b[n / BITS_PER_LONG] & (1 << (n % BITS_PER_LONG))) != 0

#endif

Privacy Policy