Good riddance to FLOW_SIG_SIZE. Looks good to me. Ethan
On Fri, Jul 20, 2012 at 4:25 PM, Ben Pfaff <b...@nicira.com> wrote: > Since we know these bytes are always 0 in both structures, we can use > faster functions that only work with full words. > > Signed-off-by: Ben Pfaff <b...@nicira.com> > --- > lib/flow.c | 6 +----- > lib/flow.h | 20 +++++++------------- > 2 files changed, 8 insertions(+), 18 deletions(-) > > diff --git a/lib/flow.c b/lib/flow.c > index e8c12a7..e409e9d 100644 > --- a/lib/flow.c > +++ b/lib/flow.c > @@ -761,11 +761,7 @@ flow_wildcards_combine(struct flow_wildcards *dst, > uint32_t > flow_wildcards_hash(const struct flow_wildcards *wc, uint32_t basis) > { > - /* If you change struct flow_wildcards and thereby trigger this > - * assertion, please check that the new struct flow_wildcards has no > holes > - * in it before you update the assertion. */ > - BUILD_ASSERT_DECL(sizeof *wc == 120 + FLOW_N_REGS * 4); > - return hash_bytes(wc, sizeof *wc, basis); > + return hash_words((const uint32_t *) wc, sizeof *wc / 4, basis); > } > > /* Returns true if 'a' and 'b' represent the same wildcards, false if they > are > diff --git a/lib/flow.h b/lib/flow.h > index 39f1f77..16c9bf2 100644 > --- a/lib/flow.h > +++ b/lib/flow.h > @@ -77,6 +77,10 @@ struct flow { > uint8_t nw_frag; /* FLOW_FRAG_* flags. */ > uint8_t zeros[2]; /* Must be zero. */ > }; > +BUILD_ASSERT_DECL(sizeof(struct flow) % 8 == 0); > + > +/* Remember to update FLOW_WC_SEQ when changing 'struct flow'. */ > +BUILD_ASSERT_DECL(sizeof(struct flow) == 152 && FLOW_WC_SEQ == 17); > > /* Represents the metadata fields of struct flow. The masks are used to > * indicate which metadata fields are relevant in a given context. Typically > @@ -94,17 +98,6 @@ struct flow_metadata { > uint16_t in_port; /* OpenFlow port or zero. */ > }; > > -/* Assert that there are FLOW_SIG_SIZE bytes of significant data in "struct > - * flow", followed by FLOW_PAD_SIZE bytes of padding. */ > -#define FLOW_SIG_SIZE (118 + FLOW_N_REGS * 4) > -#define FLOW_PAD_SIZE 2 > -BUILD_ASSERT_DECL(offsetof(struct flow, nw_frag) == FLOW_SIG_SIZE - 1); > -BUILD_ASSERT_DECL(sizeof(((struct flow *)0)->nw_frag) == 1); > -BUILD_ASSERT_DECL(sizeof(struct flow) == FLOW_SIG_SIZE + FLOW_PAD_SIZE); > - > -/* Remember to update FLOW_WC_SEQ when changing 'struct flow'. */ > -BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 150 && FLOW_WC_SEQ == 17); > - > void flow_extract(struct ofpbuf *, uint32_t priority, ovs_be64 tun_id, > uint16_t in_port, struct flow *); > void flow_zero_wildcards(struct flow *, const struct flow_wildcards *); > @@ -125,7 +118,7 @@ void flow_compose(struct ofpbuf *, const struct flow *); > static inline int > flow_compare_3way(const struct flow *a, const struct flow *b) > { > - return memcmp(a, b, FLOW_SIG_SIZE); > + return memcmp(a, b, sizeof *a); > } > > static inline bool > @@ -137,7 +130,7 @@ flow_equal(const struct flow *a, const struct flow *b) > static inline size_t > flow_hash(const struct flow *flow, uint32_t basis) > { > - return hash_bytes(flow, FLOW_SIG_SIZE, basis); > + return hash_words((const uint32_t *) flow, sizeof *flow / 4, basis); > } > > /* Information on wildcards for a flow, as a supplement to "struct flow". */ > @@ -167,6 +160,7 @@ struct flow_wildcards { > uint8_t nw_ttl_mask; /* 1-bit in each significant nw_ttl bit. */ > uint8_t zeros[6]; /* Padding field set to zero. */ > }; > +BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) % 8 == 0); > > /* Remember to update FLOW_WC_SEQ when updating struct flow_wildcards. */ > BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 152 && FLOW_WC_SEQ == 17); > -- > 1.7.2.5 > _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev