mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 22:15:20 +00:00
Use GCC builtin for clz in RPZ lookup code (#42818)
This commit is contained in:
@@ -970,34 +970,43 @@ name2data(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num,
|
||||
(void)dns_name_concatenate(&tmp_name, dns_rootname, trig_name, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the first differing bit in a key (IP address) word.
|
||||
#ifndef HAVE_BUILTIN_CLZ
|
||||
/**
|
||||
* \brief Count Leading Zeros: Find the location of the left-most set
|
||||
* bit.
|
||||
*/
|
||||
static inline int
|
||||
ffs_keybit(dns_rpz_cidr_word_t w) {
|
||||
int bit;
|
||||
static inline unsigned int
|
||||
clz(dns_rpz_cidr_word_t w) {
|
||||
unsigned int bit;
|
||||
|
||||
bit = DNS_RPZ_CIDR_WORD_BITS-1;
|
||||
|
||||
if ((w & 0xffff0000) != 0) {
|
||||
w >>= 16;
|
||||
bit -= 16;
|
||||
}
|
||||
|
||||
if ((w & 0xff00) != 0) {
|
||||
w >>= 8;
|
||||
bit -= 8;
|
||||
}
|
||||
|
||||
if ((w & 0xf0) != 0) {
|
||||
w >>= 4;
|
||||
bit -= 4;
|
||||
}
|
||||
|
||||
if ((w & 0xc) != 0) {
|
||||
w >>= 2;
|
||||
bit -= 2;
|
||||
}
|
||||
|
||||
if ((w & 2) != 0)
|
||||
--bit;
|
||||
|
||||
return (bit);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Find the first differing bit in two keys (IP addresses).
|
||||
@@ -1016,12 +1025,14 @@ diff_keys(const dns_rpz_cidr_key_t *key1, dns_rpz_prefix_t prefix1,
|
||||
/*
|
||||
* find the first differing words
|
||||
*/
|
||||
for (i = 0;
|
||||
bit < maxbit;
|
||||
i++, bit += DNS_RPZ_CIDR_WORD_BITS) {
|
||||
for (i = 0; bit < maxbit; i++, bit += DNS_RPZ_CIDR_WORD_BITS) {
|
||||
delta = key1->w[i] ^ key2->w[i];
|
||||
if (delta != 0) {
|
||||
bit += ffs_keybit(delta);
|
||||
if (ISC_UNLIKELY(delta != 0)) {
|
||||
#ifdef HAVE_BUILTIN_CLZ
|
||||
bit += __builtin_clz(delta);
|
||||
#else
|
||||
bit += clz(delta);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user