As discussed in the previous mail, this is the last simplification of the hash_ip* functions that I have in mind.
Index: toeplitz.c =================================================================== RCS file: /cvs/src/sys/net/toeplitz.c,v retrieving revision 1.5 diff -u -p -r1.5 toeplitz.c --- toeplitz.c 18 Jun 2020 11:06:32 -0000 1.5 +++ toeplitz.c 18 Jun 2020 11:14:06 -0000 @@ -36,6 +36,7 @@ /* * Copyright (c) 2019 David Gwynne <[email protected]> + * Copyright (c) 2020 Theo Buehler <[email protected]> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -116,25 +117,14 @@ uint16_t stoeplitz_hash_ip4(const struct stoeplitz_cache *scache, in_addr_t faddr, in_addr_t laddr) { - uint32_t n32; - - n32 = faddr ^ laddr; - n32 ^= n32 >> 16; - - return (stoeplitz_hash_n16(scache, n32)); + return (stoeplitz_hash_n32(scache, faddr ^ laddr)); } 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) { - uint32_t n32; - - n32 = faddr ^ laddr; - n32 ^= fport ^ lport; - n32 ^= n32 >> 16; - - return (stoeplitz_hash_n16(scache, n32)); + return (stoeplitz_hash_n32(scache, faddr ^ laddr ^ fport ^ lport)); } #ifdef INET6 @@ -148,9 +138,7 @@ stoeplitz_hash_ip6(const struct stoeplit for (i = 0; i < nitems(faddr6->s6_addr32); i++) n32 ^= faddr6->s6_addr32[i] ^ laddr6->s6_addr32[i]; - n32 ^= n32 >> 16; - - return (stoeplitz_hash_n16(scache, n32)); + return (stoeplitz_hash_n32(scache, n32)); } uint16_t @@ -165,9 +153,8 @@ stoeplitz_hash_ip6port(const struct stoe n32 ^= faddr6->s6_addr32[i] ^ laddr6->s6_addr32[i]; n32 ^= fport ^ lport; - n32 ^= n32 >> 16; - return (stoeplitz_hash_n16(scache, n32)); + return (stoeplitz_hash_n32(scache, n32)); } #endif /* INET6 */ Index: toeplitz.h =================================================================== RCS file: /cvs/src/sys/net/toeplitz.h,v retrieving revision 1.1 diff -u -p -r1.1 toeplitz.h --- toeplitz.h 16 Jun 2020 04:46:49 -0000 1.1 +++ toeplitz.h 18 Jun 2020 11:14:06 -0000 @@ -65,6 +65,13 @@ stoeplitz_hash_n16(const struct stoeplit return (hi ^ swap16(lo)); } +/* hash a uint32_t in network byte order */ +static __unused inline uint16_t +stoeplitz_hash_n32(const struct stoeplitz_cache *scache, uint32_t n32) +{ + return (stoeplitz_hash_n16(scache, n32 ^ (n32 >> 16))); +} + /* hash a uint16_t in host byte order */ static __unused inline uint16_t stoeplitz_hash_h16(const struct stoeplitz_cache *scache, uint16_t h16)
