x86: simplify ceil(log2(x)) function

A function called mask_width in one place and log2 in the other
calculates its value in a more complex way than necessary. A simpler
implementation offered here saves a few bytes in the functions that
call it.

Reviewed by:	alc, avg
Differential Revision:	https://reviews.freebsd.org/D45483
This commit is contained in:
Doug Moore
2024-06-04 13:00:25 -05:00
parent 41d6858ebd
commit 9ff1462976
2 changed files with 4 additions and 7 deletions
+2 -3
View File
@@ -61,14 +61,13 @@ SYSCTL_INT(_hw_vmm_topology, OID_AUTO, cpuid_leaf_b, CTLFLAG_RDTUN,
&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
+2 -4
View File
@@ -183,15 +183,13 @@ mem_range_AP_init(void)
}
/*
* 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));
}
/*