2 #ifdef JEMALLOC_H_TYPES
5 #define LG_BITMAP_MAXBITS LG_RUN_MAXREGS
6 #define BITMAP_MAXBITS (ZU(1) << LG_BITMAP_MAXBITS)
8 typedef struct bitmap_level_s bitmap_level_t;
9 typedef struct bitmap_info_s bitmap_info_t;
10 typedef unsigned long bitmap_t;
11 #define LG_SIZEOF_BITMAP LG_SIZEOF_LONG
14 #define LG_BITMAP_GROUP_NBITS (LG_SIZEOF_BITMAP + 3)
15 #define BITMAP_GROUP_NBITS (ZU(1) << LG_BITMAP_GROUP_NBITS)
16 #define BITMAP_GROUP_NBITS_MASK (BITMAP_GROUP_NBITS-1)
23 #if LG_BITMAP_MAXBITS - LG_BITMAP_GROUP_NBITS > 3
28 #define BITMAP_BITS2GROUPS(nbits) \
29 ((nbits + BITMAP_GROUP_NBITS_MASK) >> LG_BITMAP_GROUP_NBITS)
34 #define BITMAP_GROUPS_L0(nbits) \
35 BITMAP_BITS2GROUPS(nbits)
36 #define BITMAP_GROUPS_L1(nbits) \
37 BITMAP_BITS2GROUPS(BITMAP_BITS2GROUPS(nbits))
38 #define BITMAP_GROUPS_L2(nbits) \
39 BITMAP_BITS2GROUPS(BITMAP_BITS2GROUPS(BITMAP_BITS2GROUPS((nbits))))
40 #define BITMAP_GROUPS_L3(nbits) \
41 BITMAP_BITS2GROUPS(BITMAP_BITS2GROUPS(BITMAP_BITS2GROUPS( \
42 BITMAP_BITS2GROUPS((nbits)))))
48 #define BITMAP_GROUPS_1_LEVEL(nbits) \
49 BITMAP_GROUPS_L0(nbits)
50 #define BITMAP_GROUPS_2_LEVEL(nbits) \
51 (BITMAP_GROUPS_1_LEVEL(nbits) + BITMAP_GROUPS_L1(nbits))
52 #define BITMAP_GROUPS_3_LEVEL(nbits) \
53 (BITMAP_GROUPS_2_LEVEL(nbits) + BITMAP_GROUPS_L2(nbits))
54 #define BITMAP_GROUPS_4_LEVEL(nbits) \
55 (BITMAP_GROUPS_3_LEVEL(nbits) + BITMAP_GROUPS_L3(nbits))
62 #if LG_BITMAP_MAXBITS <= LG_BITMAP_GROUP_NBITS
63 # define BITMAP_GROUPS_MAX BITMAP_GROUPS_1_LEVEL(BITMAP_MAXBITS)
64 #elif LG_BITMAP_MAXBITS <= LG_BITMAP_GROUP_NBITS * 2
65 # define BITMAP_GROUPS_MAX BITMAP_GROUPS_2_LEVEL(BITMAP_MAXBITS)
66 #elif LG_BITMAP_MAXBITS <= LG_BITMAP_GROUP_NBITS * 3
67 # define BITMAP_GROUPS_MAX BITMAP_GROUPS_3_LEVEL(BITMAP_MAXBITS)
68 #elif LG_BITMAP_MAXBITS <= LG_BITMAP_GROUP_NBITS * 4
69 # define BITMAP_GROUPS_MAX BITMAP_GROUPS_4_LEVEL(BITMAP_MAXBITS)
71 # error "Unsupported bitmap size"
75 #define BITMAP_MAX_LEVELS \
76 (LG_BITMAP_MAXBITS / LG_SIZEOF_BITMAP) \
77 + !!(LG_BITMAP_MAXBITS % LG_SIZEOF_BITMAP)
81 #define BITMAP_GROUPS_MAX BITMAP_BITS2GROUPS(BITMAP_MAXBITS)
87 #ifdef JEMALLOC_H_STRUCTS
89 struct bitmap_level_s {
94 struct bitmap_info_s {
106 bitmap_level_t levels[BITMAP_MAX_LEVELS+1];
115 #ifdef JEMALLOC_H_EXTERNS
118 void bitmap_init(bitmap_t *bitmap,
const bitmap_info_t *binfo);
123 #ifdef JEMALLOC_H_INLINES
125 #ifndef JEMALLOC_ENABLE_INLINE
126 bool bitmap_full(bitmap_t *bitmap,
const bitmap_info_t *binfo);
127 bool bitmap_get(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit);
128 void bitmap_set(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit);
129 size_t bitmap_sfu(bitmap_t *bitmap,
const bitmap_info_t *binfo);
130 void bitmap_unset(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit);
133 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_BITMAP_C_))
135 bitmap_full(bitmap_t *bitmap,
const bitmap_info_t *binfo)
138 size_t rgoff = binfo->levels[binfo->nlevels].group_offset - 1;
139 bitmap_t rg = bitmap[rgoff];
145 for (
i = 0;
i < binfo->ngroups;
i++) {
154 bitmap_get(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit)
161 goff =
bit >> LG_BITMAP_GROUP_NBITS;
163 return (!(
g & (
ZU(1) << (
bit & BITMAP_GROUP_NBITS_MASK))));
167 bitmap_set(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit)
173 assert(bit < binfo->nbits);
175 goff =
bit >> LG_BITMAP_GROUP_NBITS;
179 g ^=
ZU(1) << (
bit & BITMAP_GROUP_NBITS_MASK);
186 for (
i = 1;
i < binfo->nlevels;
i++) {
188 goff =
bit >> LG_BITMAP_GROUP_NBITS;
189 gp = &bitmap[binfo->levels[
i].group_offset + goff];
192 g ^=
ZU(1) << (
bit & BITMAP_GROUP_NBITS_MASK);
203 bitmap_sfu(bitmap_t *bitmap,
const bitmap_info_t *binfo)
212 i = binfo->nlevels - 1;
213 g = bitmap[binfo->levels[
i].group_offset];
217 g = bitmap[binfo->levels[
i].group_offset +
bit];
227 bit = (
i << LG_BITMAP_GROUP_NBITS) + (
bit - 1);
241 assert(bit < binfo->nbits);
243 goff =
bit >> LG_BITMAP_GROUP_NBITS;
246 propagate = (
g == 0);
247 assert((
g & (
ZU(1) << (
bit & BITMAP_GROUP_NBITS_MASK))) == 0);
248 g ^=
ZU(1) << (
bit & BITMAP_GROUP_NBITS_MASK);
255 for (
i = 1;
i < binfo->nlevels;
i++) {
257 goff =
bit >> LG_BITMAP_GROUP_NBITS;
258 gp = &bitmap[binfo->levels[
i].group_offset + goff];
260 propagate = (
g == 0);
263 g ^=
ZU(1) << (
bit & BITMAP_GROUP_NBITS_MASK);
assert(limit<=UINT32_MAX/2)