Page MenuHomeFreeBSD

x86: simplify ceil(log2(x)) function
ClosedPublic

Authored by dougm on Jun 4 2024, 5:10 PM.
Tags
None
Referenced Files
F149651062: D45483.id.diff
Thu, Mar 26, 12:10 AM
Unknown Object (File)
Wed, Mar 18, 11:18 AM
Unknown Object (File)
Sun, Mar 15, 2:05 PM
Unknown Object (File)
Feb 18 2026, 11:29 AM
Unknown Object (File)
Feb 8 2026, 2:29 AM
Unknown Object (File)
Feb 7 2026, 10:46 PM
Unknown Object (File)
Jan 30 2026, 11:29 PM
Unknown Object (File)
Jan 21 2026, 7:41 AM
Subscribers

Details

Summary

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. 128 bytes in add_deterministic_cache, in particular.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dougm requested review of this revision.Jun 4 2024, 5:10 PM

Looks good to me.
A bit ashamed that I could not figure that fls(x - 1) does the job if zero is handled as a special case.

This revision is now accepted and ready to land.Jun 4 2024, 5:30 PM
alc added inline comments.
sys/amd64/vmm/x86.c
63–64

Update the comment?

This revision was automatically updated to reflect the committed changes.