summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_rman.c
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2000-10-22 04:48:11 +0000
committerimp <imp@FreeBSD.org>2000-10-22 04:48:11 +0000
commit90bca62e80c8d83ebb60270e391ee51f2a01965b (patch)
treeee63a390a27f096c0d0b11414fbf301ba567c501 /sys/kern/subr_rman.c
parent375c107d96873b06591fd6d5f18edea4ebc1fe5f (diff)
downloadFreeBSD-src-90bca62e80c8d83ebb60270e391ee51f2a01965b.zip
FreeBSD-src-90bca62e80c8d83ebb60270e391ee51f2a01965b.tar.gz
Cleanup the rman_make_alignment_flags function to be much clearer and shorter
than the prior version.
Diffstat (limited to 'sys/kern/subr_rman.c')
-rw-r--r--sys/kern/subr_rman.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/sys/kern/subr_rman.c b/sys/kern/subr_rman.c
index 91a7bcd..73a2daf 100644
--- a/sys/kern/subr_rman.c
+++ b/sys/kern/subr_rman.c
@@ -598,18 +598,16 @@ uint32_t
rman_make_alignment_flags(uint32_t size)
{
int i;
- int count;
- for (i = 0, count = 0; i < 32 && size > 0x01; i++) {
- count += size & 1;
- size >>= 1;
- }
-
- if (count > 0)
- i ++;
-
- if (i > 31)
- i = 0;
+ /*
+ * Find the hightest bit set, and add one if more than one bit
+ * set. We're effectively computing the ceil(log2(size)) here.
+ */
+ for (i = 32; i > 0; i--)
+ if ((1 << i) & size)
+ break;
+ if (~(1 << i) & size)
+ i++;
return(RF_ALIGNMENT_LOG2(i));
- }
+}
OpenPOWER on IntegriCloud