-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitfield-internals.h
28 lines (27 loc) · 971 Bytes
/
bitfield-internals.h
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
#ifndef CHAR_BIT
#include <limits.h>
#endif
#ifndef SHORT_BIT
#define SHORT_BIT (unsigned int) (sizeof(unsigned short) * CHAR_BIT)
#endif
#ifndef INT_BIT
#define INT_BIT (unsigned int) (sizeof(unsigned int) * CHAR_BIT)
#endif
#ifndef LONG_BIT
#define LONG_BIT (unsigned int) (sizeof(unsigned long) * CHAR_BIT)
#endif
#ifndef LONG_LONG_BIT
#define LONG_LONG_BIT (unsigned int) (sizeof(unsigned long long) * CHAR_BIT)
#endif
#define BITMASK(b) (1UL << ((b) % LONG_BIT))
#define BITSLOT(b) ((b) / LONG_BIT)
#define BITGET(a, b) (((a)->field[BITSLOT(b)] >> ((b) % LONG_BIT)) & 1UL)
#define BITSET(a, b) ((a)->field[BITSLOT(b)] |= BITMASK(b))
#define BITCLEAR(a, b) ((a)->field[BITSLOT(b)] &= ~BITMASK(b))
#define BITTEST(a, b) ((a)->field[BITSLOT(b)] & BITMASK(b))
#define BITTOGGLE(a, b) ((a)->field[BITSLOT(b)] ^= BITMASK(b))
#define BITNSLOTS(nb) ((nb + LONG_BIT - 1) / LONG_BIT)
struct bitfield { /* defines a bitfield */
unsigned long *field;
unsigned int size;
};