mirror of
https://github.com/opnsense/src.git
synced 2026-06-04 22:32:43 -04:00
radix_trie: simplify trimkey functions
Replacing a branch and two shifts with a single masking operation saves 64 bytes the pair of functions lookup_le and lookup_ge on amd64. Refresh the associated comments. Reviewed by: alc Differential Revision: https://reviews.freebsd.org/D40722
This commit is contained in:
parent
9cbc371c8a
commit
a42d8fe001
2 changed files with 4 additions and 18 deletions
|
|
@ -156,18 +156,11 @@ pctrie_slot(uint64_t index, uint16_t level)
|
|||
return ((index >> (level * PCTRIE_WIDTH)) & PCTRIE_MASK);
|
||||
}
|
||||
|
||||
/* Trims the key after the specified level. */
|
||||
/* Computes the key (index) with the low-order 'level' radix-digits zeroed. */
|
||||
static __inline uint64_t
|
||||
pctrie_trimkey(uint64_t index, uint16_t level)
|
||||
{
|
||||
uint64_t ret;
|
||||
|
||||
ret = index;
|
||||
if (level > 0) {
|
||||
ret >>= level * PCTRIE_WIDTH;
|
||||
ret <<= level * PCTRIE_WIDTH;
|
||||
}
|
||||
return (ret);
|
||||
return (index & -PCTRIE_UNITLEVEL(level));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -181,18 +181,11 @@ vm_radix_slot(vm_pindex_t index, uint16_t level)
|
|||
return ((index >> (level * VM_RADIX_WIDTH)) & VM_RADIX_MASK);
|
||||
}
|
||||
|
||||
/* Trims the key after the specified level. */
|
||||
/* Computes the key (index) with the low-order 'level' radix-digits zeroed. */
|
||||
static __inline vm_pindex_t
|
||||
vm_radix_trimkey(vm_pindex_t index, uint16_t level)
|
||||
{
|
||||
vm_pindex_t ret;
|
||||
|
||||
ret = index;
|
||||
if (level > 0) {
|
||||
ret >>= level * VM_RADIX_WIDTH;
|
||||
ret <<= level * VM_RADIX_WIDTH;
|
||||
}
|
||||
return (ret);
|
||||
return (index & -VM_RADIX_UNITLEVEL(level));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in a new issue