> On 18 Jun 2020, at 2:34 pm, Theo Buehler <[email protected]> wrote:
> 
> Now that the calls to stoeplitz_cache_entry() are out of the way,
> we can avoid half of the calculations by merging the computation of
> hi and lo, only spliting at the end.  This allows us to leverage
> stoeplitz_hash_n16().
> 
> The name lo is now wrong. I kept it in order to avoid noise. I'm
> going clean this up in the next step.

ok on this, and on the next step where lo is renamed.

please keep __unused though.

> 
> Index: toeplitz.c
> ===================================================================
> RCS file: /cvs/src/sys/net/toeplitz.c,v
> retrieving revision 1.3
> diff -u -p -U5 -r1.3 toeplitz.c
> --- toeplitz.c        18 Jun 2020 03:53:38 -0000      1.3
> +++ toeplitz.c        18 Jun 2020 03:57:43 -0000
> @@ -114,108 +114,79 @@ stoeplitz_cache_init(struct stoeplitz_ca
> 
> uint16_t
> stoeplitz_hash_ip4(const struct stoeplitz_cache *scache,
>     in_addr_t faddr, in_addr_t laddr)
> {
> -     uint16_t lo, hi;
> +     uint16_t lo;
> 
>       lo  = faddr >> 0;
>       lo ^= faddr >> 16;
>       lo ^= laddr >> 0;
>       lo ^= laddr >> 16;
> 
> -     hi  = faddr >> 8;
> -     hi ^= faddr >> 24;
> -     hi ^= laddr >> 8;
> -     hi ^= laddr >> 24;
> -
> -     return (swap16(stoeplitz_cache_entry(scache, lo))
> -         ^ stoeplitz_cache_entry(scache, hi));
> +     return (stoeplitz_hash_n16(scache, lo));
> }
> 
> uint16_t
> stoeplitz_hash_ip4port(const struct stoeplitz_cache *scache,
>     in_addr_t faddr, in_addr_t laddr, in_port_t fport, in_port_t lport)
> {
> -     uint16_t hi, lo;
> +     uint16_t lo;
> 
>       lo  = faddr >> 0;
>       lo ^= faddr >> 16;
>       lo ^= laddr >> 0;
>       lo ^= laddr >> 16;
>       lo ^= fport >> 0;
>       lo ^= lport >> 0;
> 
> -     hi  = faddr >> 8;
> -     hi ^= faddr >> 24;
> -     hi ^= laddr >> 8;
> -     hi ^= laddr >> 24;
> -     hi ^= fport >> 8;
> -     hi ^= lport >> 8;
> -
> -     return (swap16(stoeplitz_cache_entry(scache, lo))
> -         ^ stoeplitz_cache_entry(scache, hi));
> +     return (stoeplitz_hash_n16(scache, lo));
> }
> 
> #ifdef INET6
> uint16_t
> stoeplitz_hash_ip6(const struct stoeplitz_cache *scache,
>     const struct in6_addr *faddr6, const struct in6_addr *laddr6)
> {
> -     uint16_t hi = 0, lo = 0;
> +     uint16_t lo = 0;
>       size_t i;
> 
>       for (i = 0; i < nitems(faddr6->s6_addr32); i++) {
>               uint32_t faddr = faddr6->s6_addr32[i];
>               uint32_t laddr = laddr6->s6_addr32[i];
> 
>               lo ^= faddr >> 0;
>               lo ^= faddr >> 16;
>               lo ^= laddr >> 0;
>               lo ^= laddr >> 16;
> -
> -             hi ^= faddr >> 8;
> -             hi ^= faddr >> 24;
> -             hi ^= laddr >> 8;
> -             hi ^= laddr >> 24;
>       }
> 
> -     return (swap16(stoeplitz_cache_entry(scache, lo))
> -         ^ stoeplitz_cache_entry(scache, hi));
> +     return (stoeplitz_hash_n16(scache, lo));
> }
> 
> uint16_t
> stoeplitz_hash_ip6port(const struct stoeplitz_cache *scache,
>     const struct in6_addr *faddr6, const struct in6_addr * laddr6,
>     in_port_t fport, in_port_t lport)
> {
> -     uint16_t hi = 0, lo = 0;
> +     uint16_t lo = 0;
>       size_t i;
> 
>       for (i = 0; i < nitems(faddr6->s6_addr32); i++) {
>               uint32_t faddr = faddr6->s6_addr32[i];
>               uint32_t laddr = laddr6->s6_addr32[i];
> 
>               lo ^= faddr >> 0;
>               lo ^= faddr >> 16;
>               lo ^= laddr >> 0;
>               lo ^= laddr >> 16;
> -
> -             hi ^= faddr >> 8;
> -             hi ^= faddr >> 24;
> -             hi ^= laddr >> 8;
> -             hi ^= laddr >> 24;
>       }
> 
>       lo ^= fport >> 0;
>       lo ^= lport >> 0;
> 
> -     hi ^= fport >> 8;
> -     hi ^= lport >> 8;
> -
> -     return (swap16(stoeplitz_cache_entry(scache, lo))
> -         ^ stoeplitz_cache_entry(scache, hi));
> +     return (stoeplitz_hash_n16(scache, lo));
> }
> #endif /* INET6 */
> 
> void
> stoeplitz_to_key(uint8_t *k, size_t klen)
> Index: toeplitz.h
> ===================================================================
> RCS file: /cvs/src/sys/net/toeplitz.h,v
> retrieving revision 1.1
> diff -u -p -U5 -r1.1 toeplitz.h
> --- toeplitz.h        16 Jun 2020 04:46:49 -0000      1.1
> +++ toeplitz.h        18 Jun 2020 03:57:43 -0000
> @@ -52,11 +52,11 @@ uint16_t  stoeplitz_hash_ip6port(const st
>                   const struct in6_addr *, const struct in6_addr *,
>                   uint16_t, uint16_t);
> #endif
> 
> /* hash a uint16_t in network byte order */
> -static __unused inline uint16_t
> +static inline uint16_t
> stoeplitz_hash_n16(const struct stoeplitz_cache *scache, uint16_t n16)
> {
>       uint16_t hi, lo;
> 
>       hi = stoeplitz_cache_entry(scache, n16 >> 8);
> 

Reply via email to