Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 May 1998 05:27:16 -0700
From:      David Greenman <dg@root.com>
To:        freebsd-net@FreeBSD.ORG
Subject:   hash calculation for IP fast forwarding
Message-ID:  <199805221227.FAA00790@implode.root.com>

next in thread | raw e-mail | index | archive | help
   As I mentioned recently in freebsd-net, the hash function that the fast
IP forwarding code uses is expensive (16 adds, 12 shifts, 6 subtracts, and
6 compares). I think the following will provide a hash with similar quality,
but I might be missing something. This assumes that the table is 256 buckets
large, but it should work for larger tables as well. Opinions?

-DG

David Greenman
Co-founder/Principal Architect, The FreeBSD Project

unsigned int src = 0x91c6115a;	/* 198.145.90.17 */
unsigned int dst = 0x01100200;	/* 16.1.0.2 */

main()
{
	unsigned int i;

	i = src ^ dst;
	i = i ^ (i >> 16);
	i = i ^ (i >> 8);

	printf("0x%x,0x%x -> 0x%x\n", src, dst, i & 255);
}

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199805221227.FAA00790>