FreeBSD/sys/dev/sfxge/sfxge_rx.c
/* Compare IPv6 addresses, avoiding conditional branches */
Compare IPv6 addresses, avoiding conditional branches
Compare IPv6 addresses avoiding conditional branches
static unsigned long ipv6_addr_cmp(const struct in6_addr *left,
				   const struct in6_addr *right)
{
#if LONG_BIT == 64
	const uint64_t *left64 = (const uint64_t *)left;
	const uint64_t *right64 = (const uint64_t *)right;
	return (left64[0] - right64[0]) | (left64[1] - right64[1]);
#else
	return (left->s6_addr32[0] - right->s6_addr32[0]) |
	       (left->s6_addr32[1] - right->s6_addr32[1]) |
	       (left->s6_addr32[2] - right->s6_addr32[2]) |
	       (left->s6_addr32[3] - right->s6_addr32[3]);
#endif
}
static unsigned long ipv6_addr_cmp ( const struct in6_addr * left , const struct in6_addr * right ) { #if LONG_BIT == 64 const uint64_t * left64 = ( const uint64_t * ) left ; const uint64_t * right64 = ( const uint64_t * ) right ; return ( left64 [ 0 ] - right64 [ 0 ] ) | ( left64 [ 1 ] - right64 [ 1 ] ) ; #else return ( left -> s6_addr32 [ 0 ] - right -> s6_addr32 [ 0 ] ) | ( left -> s6_addr32 [ 1 ] - right -> s6_addr32 [ 1 ] ) | ( left -> s6_addr32 [ 2 ] - right -> s6_addr32 [ 2 ] ) | ( left -> s6_addr32 [ 3 ] - right -> s6_addr32 [ 3 ] ) ; #endif }
Compare IPv6 addresses, avoiding conditional branches
Compare IPv6 addresses avoiding conditional branches