Page MenuHomeFreeBSD

math: Optimize roundf() using bit manipulation
Needs ReviewPublic

Authored by kaushlendra.kumar_intel.com on Jan 6 2026, 5:14 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Mar 9, 9:56 PM
Unknown Object (File)
Wed, Mar 4, 1:13 PM
Unknown Object (File)
Mon, Mar 2, 12:37 AM
Unknown Object (File)
Thu, Feb 26, 6:01 AM
Unknown Object (File)
Sat, Feb 21, 3:46 AM
Unknown Object (File)
Feb 5 2026, 7:45 PM
Unknown Object (File)
Jan 27 2026, 6:01 PM
Unknown Object (File)
Jan 26 2026, 3:27 PM
Subscribers

Details

Reviewers
imp
Summary

Replace floorf()-based implementation with direct IEEE 754 bit
manipulation. The optimized version avoids expensive function calls
and floating-point operations by directly manipulating mantissa bits
to achieve rounding.

Key optimizations:

  • Fast paths for special values (Inf/NaN, |x| >= 2^23, |x| < 0.5)
  • Add 0.5 in mantissa position then truncate fractional bits
  • Pure integer operations until final conversion
  • faster than floorf()-based approach

The implementation is bit-exact and maintains IEEE 754 compliance.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 69654
Build 66537: arc lint + arc unit