2 #ifdef JEMALLOC_H_TYPES
5 #define LG_BITMAP_MAXBITS LG_RUN_MAXREGS
7 typedef struct bitmap_level_s bitmap_level_t;
8 typedef struct bitmap_info_s bitmap_info_t;
9 typedef unsigned long bitmap_t;
10 #define LG_SIZEOF_BITMAP LG_SIZEOF_LONG
13 #define LG_BITMAP_GROUP_NBITS (LG_SIZEOF_BITMAP + 3)
14 #define BITMAP_GROUP_NBITS (ZU(1) << LG_BITMAP_GROUP_NBITS)
15 #define BITMAP_GROUP_NBITS_MASK (BITMAP_GROUP_NBITS-1)
18 #define BITMAP_MAX_LEVELS \
19 (LG_BITMAP_MAXBITS / LG_SIZEOF_BITMAP) \
20 + !!(LG_BITMAP_MAXBITS % LG_SIZEOF_BITMAP)
24 #ifdef JEMALLOC_H_STRUCTS
26 struct bitmap_level_s {
31 struct bitmap_info_s {
42 bitmap_level_t levels[BITMAP_MAX_LEVELS+1];
47 #ifdef JEMALLOC_H_EXTERNS
52 void bitmap_init(bitmap_t *bitmap,
const bitmap_info_t *binfo);
56 #ifdef JEMALLOC_H_INLINES
58 #ifndef JEMALLOC_ENABLE_INLINE
59 bool bitmap_full(bitmap_t *bitmap,
const bitmap_info_t *binfo);
60 bool bitmap_get(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit);
61 void bitmap_set(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit);
62 size_t bitmap_sfu(bitmap_t *bitmap,
const bitmap_info_t *binfo);
63 void bitmap_unset(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit);
66 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_BITMAP_C_))
68 bitmap_full(bitmap_t *bitmap,
const bitmap_info_t *binfo)
70 unsigned rgoff = binfo->levels[binfo->nlevels].group_offset - 1;
71 bitmap_t rg = bitmap[rgoff];
77 bitmap_get(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit)
82 assert(bit < binfo->nbits);
83 goff = bit >> LG_BITMAP_GROUP_NBITS;
85 return (!(g & (1LU << (bit & BITMAP_GROUP_NBITS_MASK))));
89 bitmap_set(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit)
95 assert(bit < binfo->nbits);
96 assert(
bitmap_get(bitmap, binfo, bit) ==
false);
97 goff = bit >> LG_BITMAP_GROUP_NBITS;
100 assert(g & (1LU << (bit & BITMAP_GROUP_NBITS_MASK)));
101 g ^= 1LU << (bit & BITMAP_GROUP_NBITS_MASK);
107 for (i = 1; i < binfo->nlevels; i++) {
109 goff = bit >> LG_BITMAP_GROUP_NBITS;
110 gp = &bitmap[binfo->levels[i].group_offset + goff];
112 assert(g & (1LU << (bit & BITMAP_GROUP_NBITS_MASK)));
113 g ^= 1LU << (bit & BITMAP_GROUP_NBITS_MASK);
123 bitmap_sfu(bitmap_t *bitmap,
const bitmap_info_t *binfo)
131 i = binfo->nlevels - 1;
132 g = bitmap[binfo->levels[i].group_offset];
136 g = bitmap[binfo->levels[i].group_offset + bit];
137 bit = (bit << LG_BITMAP_GROUP_NBITS) + (
ffsl(g) - 1);
145 bitmap_unset(bitmap_t *bitmap,
const bitmap_info_t *binfo,
size_t bit)
152 assert(bit < binfo->nbits);
154 goff = bit >> LG_BITMAP_GROUP_NBITS;
157 propagate = (g == 0);
158 assert((g & (1LU << (bit & BITMAP_GROUP_NBITS_MASK))) == 0);
159 g ^= 1LU << (bit & BITMAP_GROUP_NBITS_MASK);
161 assert(
bitmap_get(bitmap, binfo, bit) ==
false);
165 for (i = 1; i < binfo->nlevels; i++) {
167 goff = bit >> LG_BITMAP_GROUP_NBITS;
168 gp = &bitmap[binfo->levels[i].group_offset + goff];
170 propagate = (g == 0);
171 assert((g & (1LU << (bit & BITMAP_GROUP_NBITS_MASK)))
173 g ^= 1LU << (bit & BITMAP_GROUP_NBITS_MASK);
175 if (propagate ==
false)
#define JEMALLOC_INLINE
Definition: jemalloc_internal.h:259
static __forceinline int ffsl(long x)
Definition: strings.h:8
#define bitmap_info_init
Definition: private_namespace.h:95
#define bitmap_sfu
Definition: private_namespace.h:99
#define bitmap_get
Definition: private_namespace.h:94
#define bitmap_info_ngroups
Definition: private_namespace.h:96
#define bitmap_full
Definition: private_namespace.h:93
#define bitmap_size
Definition: private_namespace.h:100
#define bitmap_init
Definition: private_namespace.h:97
#define bitmap_set
Definition: private_namespace.h:98
#define bitmap_unset
Definition: private_namespace.h:101