From ad77e3c52a0e4513d96e27de916776070cc88fbf Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Thu, 9 May 2013 19:14:20 -0700 Subject: [PATCH] flow: Add new flow_wildcards_fold_minimask() function. This function will be useful in a future commit. Signed-off-by: Ethan Jackson Co-authored-by: Justin Pettit Signed-off-by: Justin Pettit --- lib/flow.c | 43 +++++++++++++++++++++++++++++-------------- lib/flow.h | 3 +++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lib/flow.c b/lib/flow.c index 3c12984cf..647602944 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -622,6 +622,33 @@ flow_wildcards_combine(struct flow_wildcards *dst, } } +/* Perform a bitwise OR of miniflow 'src' flow data with the equivalent + * fields in 'dst', storing the result in 'dst'. */ +static void +flow_union_with_miniflow(struct flow *dst, const struct miniflow *src) +{ + uint32_t *dst_u32 = (uint32_t *) dst; + int ofs; + int i; + + ofs = 0; + for (i = 0; i < MINI_N_MAPS; i++) { + uint32_t map; + + for (map = src->map[i]; map; map = zero_rightmost_1bit(map)) { + dst_u32[raw_ctz(map) + i * 32] |= src->values[ofs++]; + } + } +} + +/* Fold minimask 'mask''s wildcard mask into 'wc's wildcard mask. */ +void +flow_wildcards_fold_minimask(struct flow_wildcards *wc, + const struct minimask *mask) +{ + flow_union_with_miniflow(&wc->masks, &mask->masks); +} + /* Returns a hash of the wildcards in 'wc'. */ uint32_t flow_wildcards_hash(const struct flow_wildcards *wc, uint32_t basis) @@ -1024,20 +1051,8 @@ miniflow_destroy(struct miniflow *flow) void miniflow_expand(const struct miniflow *src, struct flow *dst) { - uint32_t *dst_u32 = (uint32_t *) dst; - int ofs; - int i; - - memset(dst_u32, 0, sizeof *dst); - - ofs = 0; - for (i = 0; i < MINI_N_MAPS; i++) { - uint32_t map; - - for (map = src->map[i]; map; map = zero_rightmost_1bit(map)) { - dst_u32[raw_ctz(map) + i * 32] = src->values[ofs++]; - } - } + memset(dst, 0, sizeof *dst); + flow_union_with_miniflow(dst, src); } static const uint32_t * diff --git a/lib/flow.h b/lib/flow.h index 0fdf4ef97..e52b633c9 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -196,6 +196,9 @@ void flow_wildcards_combine(struct flow_wildcards *dst, bool flow_wildcards_has_extra(const struct flow_wildcards *, const struct flow_wildcards *); +void flow_wildcards_fold_minimask(struct flow_wildcards *, + const struct minimask *); + uint32_t flow_wildcards_hash(const struct flow_wildcards *, uint32_t basis); bool flow_wildcards_equal(const struct flow_wildcards *, const struct flow_wildcards *); -- 2.43.0