-/* flow/miniflow/minimask/minimatch utilities.
- * These are only used by the classifier, so place them here to allow
- * for better optimization. */
-
-static inline uint64_t
-miniflow_get_map_in_range(const struct miniflow *miniflow,
- uint8_t start, uint8_t end, unsigned int *offset)
-{
- uint64_t map = miniflow->map;
- *offset = 0;
-
- if (start > 0) {
- uint64_t msk = (UINT64_C(1) << start) - 1; /* 'start' LSBs set */
- *offset = count_1bits(map & msk);
- map &= ~msk;
- }
- if (end < FLOW_U32S) {
- uint64_t msk = (UINT64_C(1) << end) - 1; /* 'end' LSBs set */
- map &= msk;
- }
- return map;
-}
-
-/* Returns a hash value for the bits of 'flow' where there are 1-bits in
- * 'mask', given 'basis'.
- *
- * The hash values returned by this function are the same as those returned by
- * miniflow_hash_in_minimask(), only the form of the arguments differ. */
-static inline uint32_t
-flow_hash_in_minimask(const struct flow *flow, const struct minimask *mask,
- uint32_t basis)
-{
- const uint32_t *mask_values = miniflow_get_u32_values(&mask->masks);
- const uint32_t *flow_u32 = (const uint32_t *)flow;
- const uint32_t *p = mask_values;
- uint32_t hash;
- uint64_t map;
-
- hash = basis;
- for (map = mask->masks.map; map; map = zero_rightmost_1bit(map)) {
- hash = hash_add(hash, flow_u32[raw_ctz(map)] & *p++);
- }
-
- return hash_finish(hash, (p - mask_values) * 4);
-}
-
-/* Returns a hash value for the bits of 'flow' where there are 1-bits in
- * 'mask', given 'basis'.
- *
- * The hash values returned by this function are the same as those returned by
- * flow_hash_in_minimask(), only the form of the arguments differ. */
-static inline uint32_t
-miniflow_hash_in_minimask(const struct miniflow *flow,
- const struct minimask *mask, uint32_t basis)
-{
- const uint32_t *mask_values = miniflow_get_u32_values(&mask->masks);
- const uint32_t *p = mask_values;
- uint32_t hash = basis;
- uint32_t flow_u32;
-
- MINIFLOW_FOR_EACH_IN_MAP(flow_u32, flow, mask->masks.map) {
- hash = hash_add(hash, flow_u32 & *p++);
- }
-
- return hash_finish(hash, (p - mask_values) * 4);
-}
-
-/* Returns a hash value for the bits of range [start, end) in 'flow',
- * where there are 1-bits in 'mask', given 'hash'.
- *
- * The hash values returned by this function are the same as those returned by
- * minimatch_hash_range(), only the form of the arguments differ. */
-static inline uint32_t
-flow_hash_in_minimask_range(const struct flow *flow,
- const struct minimask *mask,
- uint8_t start, uint8_t end, uint32_t *basis)
-{
- const uint32_t *mask_values = miniflow_get_u32_values(&mask->masks);
- const uint32_t *flow_u32 = (const uint32_t *)flow;
- unsigned int offset;
- uint64_t map = miniflow_get_map_in_range(&mask->masks, start, end,
- &offset);
- const uint32_t *p = mask_values + offset;
- uint32_t hash = *basis;
-
- for (; map; map = zero_rightmost_1bit(map)) {
- hash = hash_add(hash, flow_u32[raw_ctz(map)] & *p++);
- }
-
- *basis = hash; /* Allow continuation from the unfinished value. */
- return hash_finish(hash, (p - mask_values) * 4);
-}
-
-/* Fold minimask 'mask''s wildcard mask into 'wc's wildcard mask. */
-static inline void
-flow_wildcards_fold_minimask(struct flow_wildcards *wc,
- const struct minimask *mask)
-{
- flow_union_with_miniflow(&wc->masks, &mask->masks);
-}