diff options
| author | Doug Moore <dougm@FreeBSD.org> | 2023-06-25 17:49:15 +0000 |
|---|---|---|
| committer | Doug Moore <dougm@FreeBSD.org> | 2023-06-25 17:49:15 +0000 |
| commit | a42d8fe001b912a5e4efdd4020d9bfadc07f6c7f (patch) | |
| tree | 2a4acc7911a2a0e8b3f4dacca0039f47b4bc89b7 | |
| parent | 9cbc371c8af751c177f8242a306678da49b3adab (diff) | |
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
| -rw-r--r-- | sys/kern/subr_pctrie.c | 11 | ||||
| -rw-r--r-- | sys/vm/vm_radix.c | 11 |
2 files changed, 4 insertions, 18 deletions
diff --git a/sys/kern/subr_pctrie.c b/sys/kern/subr_pctrie.c index 043c31ad9501..44a00a9eef77 100644 --- a/sys/kern/subr_pctrie.c +++ b/sys/kern/subr_pctrie.c @@ -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)); } /* diff --git a/sys/vm/vm_radix.c b/sys/vm/vm_radix.c index cc932a6cc80d..7d3408226be1 100644 --- a/sys/vm/vm_radix.c +++ b/sys/vm/vm_radix.c @@ -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)); } /* |
