diff --git a/sys/amd64/vmm/x86.c b/sys/amd64/vmm/x86.c --- a/sys/amd64/vmm/x86.c +++ b/sys/amd64/vmm/x86.c @@ -61,14 +61,13 @@ &cpuid_leaf_b, 0, NULL); /* - * Round up to the next power of two, if necessary, and then take log2. - * Returns -1 if argument is zero. + * Compute ceil(log2(x)). Returns -1 if x is zero. */ static __inline int log2(u_int x) { - return (fls(x << (1 - powerof2(x))) - 1); + return (x == 0 ? -1 : fls(x - 1)); } int diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -183,15 +183,13 @@ } /* - * Round up to the next power of two, if necessary, and then - * take log2. - * Returns -1 if argument is zero. + * Compute ceil(log2(x)). Returns -1 if x is zero. */ static __inline int mask_width(u_int x) { - return (fls(x << (1 - powerof2(x))) - 1); + return (x == 0 ? -1 : fls(x - 1)); } /*