Currently all bit indices used in the bitmap module are represented as
'int'. These conceptually should be unsigned. In additional limiting
these to ints potentially prevents use of very large bitmaps. So, change
these all to unsigned long.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
#define BITMAP_DECLARE(_name, _nbits) \
bitmap (_name)[BITMAP_NWORDS(_nbits)]
#define BITMAP_DECLARE(_name, _nbits) \
bitmap (_name)[BITMAP_NWORDS(_nbits)]
-static inline size_t bitmap_sizeof(int nbits)
+static inline size_t bitmap_sizeof(unsigned long nbits)
{
return BITMAP_NWORDS(nbits) * sizeof(bitmap_word);
}
{
return BITMAP_NWORDS(nbits) * sizeof(bitmap_word);
}
-static inline bitmap *bitmap_alloc(int nbits)
+static inline bitmap *bitmap_alloc(unsigned long nbits)
{
return malloc(bitmap_sizeof(nbits));
}
{
return malloc(bitmap_sizeof(nbits));
}
#define BITMAP_TAIL(_bm, _nbits) \
(BITMAP_TAILWORD(_bm, _nbits) & BITMAP_TAILBITS(_nbits))
#define BITMAP_TAIL(_bm, _nbits) \
(BITMAP_TAILWORD(_bm, _nbits) & BITMAP_TAILBITS(_nbits))
-static inline void bitmap_set_bit(bitmap *bitmap, int n)
+static inline void bitmap_set_bit(bitmap *bitmap, unsigned long n)
{
BITMAP_WORD(bitmap, n) |= BITMAP_WORDBIT(n);
}
{
BITMAP_WORD(bitmap, n) |= BITMAP_WORDBIT(n);
}
-static inline void bitmap_clear_bit(bitmap *bitmap, int n)
+static inline void bitmap_clear_bit(bitmap *bitmap, unsigned long n)
{
BITMAP_WORD(bitmap, n) &= ~BITMAP_WORDBIT(n);
}
{
BITMAP_WORD(bitmap, n) &= ~BITMAP_WORDBIT(n);
}
-static inline void bitmap_change_bit(bitmap *bitmap, int n)
+static inline void bitmap_change_bit(bitmap *bitmap, unsigned long n)
{
BITMAP_WORD(bitmap, n) ^= BITMAP_WORDBIT(n);
}
{
BITMAP_WORD(bitmap, n) ^= BITMAP_WORDBIT(n);
}
-static inline bool bitmap_test_bit(const bitmap *bitmap, int n)
+static inline bool bitmap_test_bit(const bitmap *bitmap, unsigned long n)
{
return !!(BITMAP_WORD(bitmap, n) & BITMAP_WORDBIT(n));
}
{
return !!(BITMAP_WORD(bitmap, n) & BITMAP_WORDBIT(n));
}
-static inline void bitmap_zero(bitmap *bitmap, int nbits)
+static inline void bitmap_zero(bitmap *bitmap, unsigned long nbits)
{
memset(bitmap, 0, bitmap_sizeof(nbits));
}
{
memset(bitmap, 0, bitmap_sizeof(nbits));
}
-static inline void bitmap_fill(bitmap *bitmap, int nbits)
+static inline void bitmap_fill(bitmap *bitmap, unsigned long nbits)
{
memset(bitmap, 0xff, bitmap_sizeof(nbits));
}
{
memset(bitmap, 0xff, bitmap_sizeof(nbits));
}
-static inline void bitmap_copy(bitmap *dst, const bitmap *src, int nbits)
+static inline void bitmap_copy(bitmap *dst, const bitmap *src,
+ unsigned long nbits)
{
memcpy(dst, src, bitmap_sizeof(nbits));
}
#define BITMAP_DEF_BINOP(_name, _op) \
static inline void bitmap_##_name(bitmap *dst, bitmap *src1, bitmap *src2, \
{
memcpy(dst, src, bitmap_sizeof(nbits));
}
#define BITMAP_DEF_BINOP(_name, _op) \
static inline void bitmap_##_name(bitmap *dst, bitmap *src1, bitmap *src2, \
for (i = 0; i < BITMAP_NWORDS(nbits); i++) { \
dst[i].w = src1[i].w _op src2[i].w; \
} \
for (i = 0; i < BITMAP_NWORDS(nbits); i++) { \
dst[i].w = src1[i].w _op src2[i].w; \
} \
-static inline void bitmap_complement(bitmap *dst, const bitmap *src, int nbits)
+static inline void bitmap_complement(bitmap *dst, const bitmap *src,
+ unsigned long nbits)
for (i = 0; i < BITMAP_NWORDS(nbits); i++)
dst[i].w = ~src[i].w;
}
static inline bool bitmap_equal(const bitmap *src1, const bitmap *src2,
for (i = 0; i < BITMAP_NWORDS(nbits); i++)
dst[i].w = ~src[i].w;
}
static inline bool bitmap_equal(const bitmap *src1, const bitmap *src2,
{
return (memcmp(src1, src2, BITMAP_HEADBYTES(nbits)) == 0)
&& (!BITMAP_HASTAIL(nbits)
{
return (memcmp(src1, src2, BITMAP_HEADBYTES(nbits)) == 0)
&& (!BITMAP_HASTAIL(nbits)
}
static inline bool bitmap_intersects(const bitmap *src1, const bitmap *src2,
}
static inline bool bitmap_intersects(const bitmap *src1, const bitmap *src2,
for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
if (src1[i].w & src2[i].w)
for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
if (src1[i].w & src2[i].w)
}
static inline bool bitmap_subset(const bitmap *src1, const bitmap *src2,
}
static inline bool bitmap_subset(const bitmap *src1, const bitmap *src2,
for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
if (src1[i].w & ~src2[i].w)
for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
if (src1[i].w & ~src2[i].w)
-static inline bool bitmap_full(const bitmap *bitmap, int nbits)
+static inline bool bitmap_full(const bitmap *bitmap, unsigned long nbits)
for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
if (bitmap[i].w != -1UL)
for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
if (bitmap[i].w != -1UL)
-static inline bool bitmap_empty(const bitmap *bitmap, int nbits)
+static inline bool bitmap_empty(const bitmap *bitmap, unsigned long nbits)
for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
if (bitmap[i].w != 0)
for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
if (bitmap[i].w != 0)