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
F132377715: D35937.id108538.diff
Thu, Oct 16, 9:10 AM
F132322478: D35937.id.diff
Wed, Oct 15, 9:38 PM
F132321970: D35937.id108538.diff
Wed, Oct 15, 9:30 PM
F132321969: D35937.id108798.diff
Wed, Oct 15, 9:30 PM
F132321966: D35937.id.diff
Wed, Oct 15, 9:30 PM
F132321965: D35937.id108799.diff
Wed, Oct 15, 9:30 PM
F132321964: D35937.id108986.diff
Wed, Oct 15, 9:30 PM
F132315495: D35937.id108799.diff
Wed, Oct 15, 7:53 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