Skip to content

Commit

Permalink
bitmap: Convert single bitmap functions to 64-bit.
Browse files Browse the repository at this point in the history
Currently the functions to set, clear, and iterate over bitmaps
only operate over 32 bit values. If we convert them to handle
64 bit bitmaps, they can be used in more places.

Suggested-by: Ben Pfaff <[email protected]>
Signed-off-by: Jesse Gross <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
jessegross committed Jun 25, 2015
1 parent 099772c commit 3ee6026
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions lib/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ bitmap_is_all_zeros(const unsigned long *bitmap, size_t n)
#define BITMAP_FOR_EACH_1(IDX, SIZE, BITMAP) \
BITMAP_FOR_EACH_1_RANGE(IDX, 0, SIZE, BITMAP)

/* More efficient access to a map of single ulong. */
#define ULONG_FOR_EACH_1(IDX, MAP) \
for (unsigned long map__ = (MAP); \
/* More efficient access to a map of single ullong. */
#define ULLONG_FOR_EACH_1(IDX, MAP) \
for (uint64_t map__ = (MAP); \
map__ && (((IDX) = raw_ctz(map__)), true); \
map__ = zero_rightmost_1bit(map__))

#define ULONG_SET0(MAP, OFFSET) ((MAP) &= ~(1UL << (OFFSET)))
#define ULONG_SET1(MAP, OFFSET) ((MAP) |= 1UL << (OFFSET))
#define ULLONG_SET0(MAP, OFFSET) ((MAP) &= ~(1ULL << (OFFSET)))
#define ULLONG_SET1(MAP, OFFSET) ((MAP) |= 1ULL << (OFFSET))

#endif /* bitmap.h */
10 changes: 5 additions & 5 deletions lib/cmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,13 @@ cmap_find_batch(const struct cmap *cmap, unsigned long map,
uint32_t c1s[sizeof map * CHAR_BIT];

/* Compute hashes and prefetch 1st buckets. */
ULONG_FOR_EACH_1(i, map) {
ULLONG_FOR_EACH_1(i, map) {
h1s[i] = rehash(impl, hashes[i]);
b1s[i] = &impl->buckets[h1s[i] & impl->mask];
OVS_PREFETCH(b1s[i]);
}
/* Lookups, Round 1. Only look up at the first bucket. */
ULONG_FOR_EACH_1(i, map) {
ULLONG_FOR_EACH_1(i, map) {
uint32_t c1;
const struct cmap_bucket *b1 = b1s[i];
const struct cmap_node *node;
Expand All @@ -414,12 +414,12 @@ cmap_find_batch(const struct cmap *cmap, unsigned long map,
continue;
}
/* Found. */
ULONG_SET0(map, i); /* Ignore this on round 2. */
ULLONG_SET0(map, i); /* Ignore this on round 2. */
OVS_PREFETCH(node);
nodes[i] = node;
}
/* Round 2. Look into the 2nd bucket, if needed. */
ULONG_FOR_EACH_1(i, map) {
ULLONG_FOR_EACH_1(i, map) {
uint32_t c2;
const struct cmap_bucket *b2 = b2s[i];
const struct cmap_node *node;
Expand All @@ -445,7 +445,7 @@ cmap_find_batch(const struct cmap *cmap, unsigned long map,
}
}
/* Not found. */
ULONG_SET0(result, i); /* Fix the result. */
ULLONG_SET0(result, i); /* Fix the result. */
continue;
}
found:
Expand Down
6 changes: 3 additions & 3 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -3916,14 +3916,14 @@ dpcls_lookup(const struct dpcls *cls, const struct netdev_flow_key keys[],
}

/* Compute hashes for the remaining keys. */
ULONG_FOR_EACH_1(i, map) {
ULLONG_FOR_EACH_1(i, map) {
hashes[i] = netdev_flow_key_hash_in_mask(&mkeys[i],
&subtable->mask);
}
/* Lookup. */
map = cmap_find_batch(&subtable->rules, map, hashes, nodes);
/* Check results. */
ULONG_FOR_EACH_1(i, map) {
ULLONG_FOR_EACH_1(i, map) {
struct dpcls_rule *rule;

CMAP_NODE_FOR_EACH (rule, cmap_node, nodes[i]) {
Expand All @@ -3932,7 +3932,7 @@ dpcls_lookup(const struct dpcls *cls, const struct netdev_flow_key keys[],
goto next;
}
}
ULONG_SET0(map, i); /* Did not match. */
ULLONG_SET0(map, i); /* Did not match. */
next:
; /* Keep Sparse happy. */
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test-cmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ check_cmap(struct cmap *cmap, const int values[], size_t n,
}
map = cmap_find_batch(cmap, map, hashes, nodes);

ULONG_FOR_EACH_1(k, map) {
ULLONG_FOR_EACH_1(k, map) {
struct element *e;

CMAP_NODE_FOR_EACH (e, node, nodes[k]) {
Expand Down Expand Up @@ -435,7 +435,7 @@ find_batch(const struct cmap *cmap, const int value)
map >>= BITMAP_ULONG_BITS - i; /* Clear excess bits. */
map = cmap_find_batch(cmap, map, hashes, nodes);

ULONG_FOR_EACH_1(i, map) {
ULLONG_FOR_EACH_1(i, map) {
struct element *e;

CMAP_NODE_FOR_EACH (e, node, nodes[i]) {
Expand Down

0 comments on commit 3ee6026

Please sign in to comment.