git: a42d8fe001b9 - main - radix_trie: simplify trimkey functions
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 25 Jun 2023 17:50:56 UTC
The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=a42d8fe001b912a5e4efdd4020d9bfadc07f6c7f commit a42d8fe001b912a5e4efdd4020d9bfadc07f6c7f Author: Doug Moore <dougm@FreeBSD.org> AuthorDate: 2023-06-25 17:49:15 +0000 Commit: Doug Moore <dougm@FreeBSD.org> CommitDate: 2023-06-25 17:49:15 +0000 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 --- sys/kern/subr_pctrie.c | 11 ++--------- 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)); } /*