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)
Sat, Sep 5, 6:18 PM
Unknown Object (File)
Sat, Sep 5, 5:19 AM
Unknown Object (File)
Fri, Sep 4, 12:25 PM
Unknown Object (File)
Fri, Sep 4, 12:10 PM
Unknown Object (File)
Fri, Sep 4, 12:04 PM
Unknown Object (File)
Thu, Sep 3, 10:53 AM
Unknown Object (File)
Tue, Sep 1, 12:44 PM
Unknown Object (File)
Tue, Sep 1, 10:54 AM
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