Signed-off-by: Jarno Rajahalme <jrajaha...@nicira.com> --- lib/classifier-private.h | 22 +++++++++++---------- lib/classifier.c | 4 ++-- lib/flow.c | 48 ++++++++++++++++++---------------------------- lib/flow.h | 6 +++--- lib/match.c | 6 +++--- 5 files changed, 39 insertions(+), 47 deletions(-)
diff --git a/lib/classifier-private.h b/lib/classifier-private.h index ae0657f..b498eea 100644 --- a/lib/classifier-private.h +++ b/lib/classifier-private.h @@ -132,11 +132,11 @@ flow_hash_in_minimask(const struct flow *flow, const struct minimask *mask, const uint32_t *flow_u32 = (const uint32_t *)flow; const uint32_t *p = mask_values; uint32_t hash; - uint64_t map; + int idx; hash = basis; - for (map = mask->masks.map; map; map = zero_rightmost_1bit(map)) { - hash = hash_add(hash, flow_u32[raw_ctz(map)] & *p++); + MAP_FOR_EACH_INDEX(idx, mask->masks.map) { + hash = hash_add(hash, flow_u32[idx] & *p++); } return hash_finish(hash, (p - mask_values) * 4); @@ -180,9 +180,10 @@ flow_hash_in_minimask_range(const struct flow *flow, &offset); const uint32_t *p = mask_values + offset; uint32_t hash = *basis; + int idx; - for (; map; map = zero_rightmost_1bit(map)) { - hash = hash_add(hash, flow_u32[raw_ctz(map)] & *p++); + MAP_FOR_EACH_INDEX(idx, map) { + hash = hash_add(hash, flow_u32[idx] & *p++); } *basis = hash; /* Allow continuation from the unfinished value. */ @@ -209,9 +210,10 @@ flow_wildcards_fold_minimask_range(struct flow_wildcards *wc, uint64_t map = miniflow_get_map_in_range(&mask->masks, start, end, &offset); const uint32_t *p = miniflow_get_u32_values(&mask->masks) + offset; + int idx; - for (; map; map = zero_rightmost_1bit(map)) { - dst_u32[raw_ctz(map)] |= *p++; + MAP_FOR_EACH_INDEX(idx, map) { + dst_u32[idx] |= *p++; } } @@ -223,12 +225,12 @@ miniflow_hash(const struct miniflow *flow, uint32_t basis) const uint32_t *p = values; uint32_t hash = basis; uint64_t hash_map = 0; - uint64_t map; + int idx; - for (map = flow->map; map; map = zero_rightmost_1bit(map)) { + MAP_FOR_EACH_INDEX(idx, flow->map) { if (*p) { hash = hash_add(hash, *p); - hash_map |= rightmost_1bit(map); + hash_map |= UINT64_C(1) << idx; } p++; } diff --git a/lib/classifier.c b/lib/classifier.c index b05d140..fe43bd1 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -1283,7 +1283,7 @@ miniflow_and_mask_matches_flow(const struct miniflow *flow, { const uint32_t *flowp = miniflow_get_u32_values(flow); const uint32_t *maskp = miniflow_get_u32_values(&mask->masks); - uint32_t idx; + int idx; MAP_FOR_EACH_INDEX(idx, mask->masks.map) { uint32_t diff = (*flowp++ ^ flow_u32_value(target, idx)) & *maskp++; @@ -1326,7 +1326,7 @@ miniflow_and_mask_matches_flow_wc(const struct miniflow *flow, { const uint32_t *flowp = miniflow_get_u32_values(flow); const uint32_t *maskp = miniflow_get_u32_values(&mask->masks); - uint32_t idx; + int idx; MAP_FOR_EACH_INDEX(idx, mask->masks.map) { uint32_t mask = *maskp++; diff --git a/lib/flow.c b/lib/flow.c index 141c3d8..40fa867 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -1853,10 +1853,10 @@ miniflow_init__(struct miniflow *dst, const struct flow *src, int n) { const uint32_t *src_u32 = (const uint32_t *) src; uint32_t *dst_u32 = miniflow_alloc_values(dst, n); - uint64_t map; + int idx; - for (map = dst->map; map; map = zero_rightmost_1bit(map)) { - *dst_u32++ = src_u32[raw_ctz(map)]; + MAP_FOR_EACH_INDEX(idx, dst->map) { + *dst_u32++ = src_u32[idx]; } } @@ -1986,22 +1986,18 @@ miniflow_equal(const struct miniflow *a, const struct miniflow *b) { const uint32_t *ap = miniflow_get_u32_values(a); const uint32_t *bp = miniflow_get_u32_values(b); - const uint64_t a_map = a->map; - const uint64_t b_map = b->map; - if (OVS_LIKELY(a_map == b_map)) { + if (OVS_LIKELY(a->map == b->map)) { int count = miniflow_n_values(a); return !memcmp(ap, bp, count * sizeof *ap); } else { - uint64_t map; + int idx; - for (map = a_map | b_map; map; map = zero_rightmost_1bit(map)) { - uint64_t bit = rightmost_1bit(map); - uint64_t a_value = a_map & bit ? *ap++ : 0; - uint64_t b_value = b_map & bit ? *bp++ : 0; + MAP_FOR_EACH_INDEX(idx, a->map | b->map) { + uint64_t bit = UINT64_C(1) << idx; - if (a_value != b_value) { + if ((a->map & bit ? *ap++ : 0) != (b->map & bit ? *bp++ : 0)) { return false; } } @@ -2017,12 +2013,10 @@ miniflow_equal_in_minimask(const struct miniflow *a, const struct miniflow *b, const struct minimask *mask) { const uint32_t *p = miniflow_get_u32_values(&mask->masks); - uint64_t map; - - for (map = mask->masks.map; map; map = zero_rightmost_1bit(map)) { - int ofs = raw_ctz(map); + int idx; - if ((miniflow_get(a, ofs) ^ miniflow_get(b, ofs)) & *p++) { + MAP_FOR_EACH_INDEX(idx, mask->masks.map) { + if ((miniflow_get(a, idx) ^ miniflow_get(b, idx)) & *p++) { return false; } } @@ -2038,12 +2032,10 @@ miniflow_equal_flow_in_minimask(const struct miniflow *a, const struct flow *b, { const uint32_t *b_u32 = (const uint32_t *) b; const uint32_t *p = miniflow_get_u32_values(&mask->masks); - uint64_t map; - - for (map = mask->masks.map; map; map = zero_rightmost_1bit(map)) { - int ofs = raw_ctz(map); + int idx; - if ((miniflow_get(a, ofs) ^ b_u32[ofs]) & *p++) { + MAP_FOR_EACH_INDEX(idx, mask->masks.map) { + if ((miniflow_get(a, idx) ^ b_u32[idx]) & *p++) { return false; } } @@ -2089,21 +2081,19 @@ minimask_combine(struct minimask *dst_, uint32_t *dst_values = storage; const struct miniflow *a = &a_->masks; const struct miniflow *b = &b_->masks; - uint64_t map; - int n = 0; + int idx; dst->values_inline = false; dst->offline_values = storage; dst->map = 0; - for (map = a->map & b->map; map; map = zero_rightmost_1bit(map)) { - int ofs = raw_ctz(map); + MAP_FOR_EACH_INDEX(idx, a->map & b->map) { /* Both 'a' and 'b' have non-zero data at 'idx'. */ - uint32_t mask = MINIFLOW_GET__(a, ofs) & MINIFLOW_GET__(b, ofs); + uint32_t mask = MINIFLOW_GET__(a, idx) & MINIFLOW_GET__(b, idx); if (mask) { - dst->map |= rightmost_1bit(map); - dst_values[n++] = mask; + dst->map |= UINT64_C(1) << idx; + *dst_values++ = mask; } } } diff --git a/lib/flow.h b/lib/flow.h index 2ef5c7b..2a0d390 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -697,10 +697,10 @@ flow_union_with_miniflow(struct flow *dst, const struct miniflow *src) { uint32_t *dst_u32 = (uint32_t *) dst; const uint32_t *p = miniflow_get_u32_values(src); - uint64_t map; + int idx; - for (map = src->map; map; map = zero_rightmost_1bit(map)) { - dst_u32[raw_ctz(map)] |= *p++; + MAP_FOR_EACH_INDEX(idx, src->map) { + dst_u32[idx] |= *p++; } } diff --git a/lib/match.c b/lib/match.c index bd3b13d..480b972 100644 --- a/lib/match.c +++ b/lib/match.c @@ -1203,10 +1203,10 @@ minimatch_matches_flow(const struct minimatch *match, const uint32_t *target_u32 = (const uint32_t *) target; const uint32_t *flowp = miniflow_get_u32_values(&match->flow); const uint32_t *maskp = miniflow_get_u32_values(&match->mask.masks); - uint64_t map; + int idx; - for (map = match->flow.map; map; map = zero_rightmost_1bit(map)) { - if ((*flowp++ ^ target_u32[raw_ctz(map)]) & *maskp++) { + MAP_FOR_EACH_INDEX(idx, match->flow.map) { + if ((*flowp++ ^ target_u32[idx]) & *maskp++) { return false; } } -- 1.7.10.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev