Page MenuHomeFreeBSD

linuxkpi: math.h: Add mul_u64_u32_div and mul_u64_u32_shr
ClosedPublic

Authored by manu on Jul 26 2022, 9:30 AM.
Tags
None
Referenced Files
F132315495: D35937.id108799.diff
Wed, Oct 15, 7:53 PM
F132293979: D35937.id108799.diff
Wed, Oct 15, 2:56 PM
F132278427: D35937.diff
Wed, Oct 15, 11:11 AM
Unknown Object (File)
Tue, Oct 14, 4:10 PM
Unknown Object (File)
Tue, Oct 14, 1:57 AM
Unknown Object (File)
Sun, Oct 12, 9:23 PM
Unknown Object (File)
Sun, Oct 12, 5:51 PM
Unknown Object (File)
Sun, Oct 12, 4:16 PM

Details

Summary

Needed by drm-kmod.

Obtained from: OpenBSD
Sponsored by: Beckhoff Automation GmbH & Co. KG

Diff Detail

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

Event Timeline

manu requested review of this revision.Jul 26 2022, 9:30 AM
hselasky added inline comments.
sys/compat/linuxkpi/common/include/linux/math64.h
106

This looks wrong and may overflow! Do it like shown below instead, and implement mul_u64_u64_div() at the same time:

static inline uint64_t
mul_u64_u64_div(uint64_t num, uint64_t mul, uint64_t div)
{
       const uint64_t rem = num % div;

       return (num / div) * mul + (rem * mul) / div;
}
bz added inline comments.
sys/compat/linuxkpi/common/include/linux/math64.h
106

In any case, BSD style is putting the return (value) in ().

sys/compat/linuxkpi/common/include/linux/math64.h
104

x->num and y->rem

Looks good.

sys/compat/linuxkpi/common/include/linux/math64.h
108

Maybe add ()'s

This revision is now accepted and ready to land.Aug 2 2022, 8:11 AM