+static inline uint32_t
+flow_get_next_in_map(const struct flow *flow, uint64_t map, uint32_t *value)
+{
+ if (map) {
+ *value = ((const uint32_t *)flow)[raw_ctz(map)];
+ return true;
+ }
+ return false;
+}
+
+/* Iterate through all flow u32 values specified by 'MAP'.
+ * This works as the first statement in a block.*/
+#define FLOW_FOR_EACH_IN_MAP(VALUE, FLOW, MAP) \
+ uint64_t map_; \
+ for (map_ = (MAP); \
+ flow_get_next_in_map(FLOW, map_, &(VALUE)); \
+ map_ = zero_rightmost_1bit(map_))
+
+#define FLOW_U32_SIZE(FIELD) \
+ DIV_ROUND_UP(sizeof(((struct flow *)0)->FIELD), sizeof(uint32_t))
+
+#define MINIFLOW_MAP(FIELD) \
+ (((UINT64_C(1) << FLOW_U32_SIZE(FIELD)) - 1) \
+ << (offsetof(struct flow, FIELD) / 4))
+
+static inline uint32_t
+mf_get_next_in_map(uint64_t *fmap, uint64_t rm1bit, const uint32_t **fp,
+ uint32_t *value)
+{
+ *value = 0;
+ if (*fmap & rm1bit) {
+ uint64_t trash = *fmap & (rm1bit - 1);
+
+ if (trash) {
+ *fmap -= trash;
+ *fp += count_1bits(trash);
+ }
+ *value = **fp;
+ }
+ return rm1bit != 0;
+}
+
+/* Iterate through all miniflow u32 values specified by 'MAP'.
+ * This works as the first statement in a block.*/
+#define MINIFLOW_FOR_EACH_IN_MAP(VALUE, FLOW, MAP) \
+ const uint32_t *fp_ = miniflow_get_u32_values(FLOW); \
+ uint64_t rm1bit_, fmap_, map_; \
+ for (fmap_ = (FLOW)->map, map_ = (MAP), rm1bit_ = rightmost_1bit(map_); \
+ mf_get_next_in_map(&fmap_, rm1bit_, &fp_, &(VALUE)); \
+ map_ -= rm1bit_, rm1bit_ = rightmost_1bit(map_))
+
+/* 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) \
+ (((MF)->map & (UINT64_C(1) << (OFS) / 4)) \
+ ? ((OVS_FORCE const TYPE *) \
+ (miniflow_get_u32_values(MF) \
+ + count_1bits((MF)->map & ((UINT64_C(1) << (OFS) / 4) - 1)))) \
+ [(OFS) % 4 / sizeof(TYPE)] \
+ : 0) \
+
+#define MINIFLOW_GET_U8(FLOW, FIELD) \
+ MINIFLOW_GET_TYPE(FLOW, uint8_t, offsetof(struct flow, FIELD))
+#define MINIFLOW_GET_U16(FLOW, FIELD) \
+ MINIFLOW_GET_TYPE(FLOW, uint16_t, offsetof(struct flow, FIELD))
+#define MINIFLOW_GET_BE16(FLOW, FIELD) \
+ MINIFLOW_GET_TYPE(FLOW, ovs_be16, offsetof(struct flow, FIELD))
+#define MINIFLOW_GET_U32(FLOW, FIELD) \
+ MINIFLOW_GET_TYPE(FLOW, uint32_t, offsetof(struct flow, FIELD))
+#define MINIFLOW_GET_BE32(FLOW, FIELD) \
+ MINIFLOW_GET_TYPE(FLOW, ovs_be32, offsetof(struct flow, FIELD))