git: 543d55d79109 - main - vm_phys: use ilog2(x) instead of fls(x)-1
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 04 Jun 2024 18:08:37 UTC
The branch main has been updated by dougm:
URL: https://cgit.FreeBSD.org/src/commit/?id=543d55d79109ce47e43a98af16232aa86d0e02ec
commit 543d55d79109ce47e43a98af16232aa86d0e02ec
Author: Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2024-06-04 18:07:07 +0000
Commit: Doug Moore <dougm@FreeBSD.org>
CommitDate: 2024-06-04 18:07:07 +0000
vm_phys: use ilog2(x) instead of fls(x)-1
One of these changes saves two instructions on an amd64
GENERIC-NODEBUG build. The rest are entirely cosmetic, because the
compiler can deduce that x is nonzero, and avoid the needless test.
Reviewed by: alc
Differential Revision: https://reviews.freebsd.org/D45331
---
sys/vm/vm_phys.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/sys/vm/vm_phys.c b/sys/vm/vm_phys.c
index 66ad9c13dceb..62e84a5b52bd 100644
--- a/sys/vm/vm_phys.c
+++ b/sys/vm/vm_phys.c
@@ -699,14 +699,14 @@ vm_phys_enq_beg(vm_page_t m, u_int npages, struct vm_freelist *fl, int tail)
KASSERT(npages == 0 ||
(VM_PAGE_TO_PHYS(m) &
- ((PAGE_SIZE << (fls(npages) - 1)) - 1)) == 0,
+ ((PAGE_SIZE << ilog2(npages)) - 1)) == 0,
("%s: page %p and npages %u are misaligned",
__func__, m, npages));
while (npages > 0) {
KASSERT(m->order == VM_NFREEORDER,
("%s: page %p has unexpected order %d",
__func__, m, m->order));
- order = fls(npages) - 1;
+ order = ilog2(npages);
KASSERT(order < VM_NFREEORDER,
("%s: order %d is out of range", __func__, order));
vm_freelist_add(fl, m, order, tail);
@@ -735,7 +735,7 @@ vm_phys_enq_range(vm_page_t m, u_int npages, struct vm_freelist *fl, int tail)
KASSERT(npages == 0 ||
((VM_PAGE_TO_PHYS(m) + npages * PAGE_SIZE) &
- ((PAGE_SIZE << (fls(npages) - 1)) - 1)) == 0,
+ ((PAGE_SIZE << ilog2(npages)) - 1)) == 0,
("vm_phys_enq_range: page %p and npages %u are misaligned",
m, npages));
while (npages > 0) {
@@ -1193,7 +1193,7 @@ vm_phys_enqueue_contig(vm_page_t m, u_long npages)
lo = atop(VM_PAGE_TO_PHYS(m));
if (m < m_end &&
(diff = lo ^ (lo + npages - 1)) != 0) {
- order = min(flsll(diff) - 1, VM_NFREEORDER - 1);
+ order = min(ilog2(diff), VM_NFREEORDER - 1);
m = vm_phys_enq_range(m, roundup2(lo, 1 << order) - lo, fl, 1);
}
@@ -1225,7 +1225,7 @@ vm_phys_free_contig(vm_page_t m, u_long npages)
vm_domain_free_assert_locked(vm_pagequeue_domain(m));
lo = atop(VM_PAGE_TO_PHYS(m));
- max_order = min(flsll(lo ^ (lo + npages)) - 1, VM_NFREEORDER - 1);
+ max_order = min(ilog2(lo ^ (lo + npages)), VM_NFREEORDER - 1);
m_start = m;
order_start = ffsll(lo) - 1;