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:
+2
-3
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user