[ovs-dev] [PATCH 02/10] flow: Define MINIFLOW_GET__() to simplify code.

Jarno Rajahalme jrajahalme at nicira.com
Fri Nov 21 00:42:49 UTC 2014


Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
---
 lib/flow.c |    9 ++++-----
 lib/flow.h |    6 ++++++
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/flow.c b/lib/flow.c
index 8c379f6..f1bcad6 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -1976,10 +1976,8 @@ miniflow_expand(const struct miniflow *src, struct flow *dst)
 static uint32_t
 miniflow_get(const struct miniflow *flow, unsigned int u32_ofs)
 {
-    return (flow->map & UINT64_C(1) << u32_ofs)
-        ? *(miniflow_get_u32_values(flow) +
-            count_1bits(flow->map & ((UINT64_C(1) << u32_ofs) - 1)))
-        : 0;
+    return flow->map & (UINT64_C(1) << u32_ofs)
+        ? MINIFLOW_GET__(flow, u32_ofs) : 0;
 }
 
 /* Returns true if 'a' and 'b' are the equal miniflow, false otherwise. */
@@ -2100,7 +2098,8 @@ minimask_combine(struct minimask *dst_,
     dst->map = 0;
     for (map = a->map & b->map; map; map = zero_rightmost_1bit(map)) {
         int ofs = raw_ctz(map);
-        uint32_t mask = miniflow_get(a, ofs) & miniflow_get(b, ofs);
+        /* Both 'a' and 'b' have non-zero data at 'idx'. */
+        uint32_t mask = MINIFLOW_GET__(a, ofs) & MINIFLOW_GET__(b, ofs);
 
         if (mask) {
             dst->map |= rightmost_1bit(map);
diff --git a/lib/flow.h b/lib/flow.h
index 2dcc7be..3e0ac28 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -551,6 +551,12 @@ mf_get_next_in_map(struct mf_for_each_in_map_aux *aux, uint32_t *value)
          mf_get_next_in_map(&aux__, &(VALUE));                          \
         )
 
+/* This macro can be used when it is known that the 'U32_IDX' is set in the
+ * map of 'MF'. */
+#define MINIFLOW_GET__(MF, U32_IDX)                                     \
+    (miniflow_get_u32_values(MF)                                        \
+     [count_1bits((MF)->map & ((UINT64_C(1) << (U32_IDX)) - 1))])
+
 /* Get the value of 'FIELD' of an up to 4 byte wide integer type 'TYPE' of
  * a miniflow. */
 #define MINIFLOW_GET_TYPE(MF, TYPE, OFS)                                \
-- 
1.7.10.4




More information about the dev mailing list