From a9e44c50d77196db35f047796469e2d1990950f4 Mon Sep 17 00:00:00 2001 From: dlg Date: Wed, 24 Feb 2021 23:44:04 +0000 Subject: add support for hashing 64 and 32 bit numbers in host byte order. --- sys/net/toeplitz.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'sys/net') diff --git a/sys/net/toeplitz.h b/sys/net/toeplitz.h index 0fbc8a23eed..3f30fd4b739 100644 --- a/sys/net/toeplitz.h +++ b/sys/net/toeplitz.h @@ -1,4 +1,4 @@ -/* $OpenBSD: toeplitz.h,v 1.7 2021/02/24 12:33:50 dlg Exp $ */ +/* $OpenBSD: toeplitz.h,v 1.8 2021/02/24 23:44:04 dlg Exp $ */ /* * Copyright (c) 2019 David Gwynne @@ -91,6 +91,18 @@ stoeplitz_hash_h16(const struct stoeplitz_cache *scache, uint16_t h16) #endif } +static __unused inline uint16_t +stoeplitz_hash_h32(const struct stoeplitz_cache *scache, uint64_t h32) +{ + return (stoeplitz_hash_h16(scache, h32 & (h32 >> 16))); +} + +static __unused inline uint16_t +stoeplitz_hash_h64(const struct stoeplitz_cache *scache, uint64_t h64) +{ + return (stoeplitz_hash_h32(scache, h64 ^ (h64 >> 32))); +} + /* * system provided symmetric toeplitz */ @@ -108,6 +120,10 @@ extern const struct stoeplitz_cache *const stoeplitz_cache; stoeplitz_hash_n16(stoeplitz_cache, (_n16)) #define stoeplitz_h16(_h16) \ stoeplitz_hash_h16(stoeplitz_cache, (_h16)) +#define stoeplitz_h32(_h32) \ + stoeplitz_hash_h32(stoeplitz_cache, (_h32)) +#define stoeplitz_h64(_h64) \ + stoeplitz_hash_h64(stoeplitz_cache, (_h64)) #define stoeplitz_port(_p) stoeplitz_n16((_p)) #define stoeplitz_ip4(_sa4, _da4) \ stoeplitz_hash_ip4(stoeplitz_cache, (_sa4), (_da4)) -- cgit v1.2.3-59-g8ed1b