git: 885ab0dba28b - main - linuxkpi: math.h: Add mul_u64_u32_div and mul_u64_u32_shr
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 08 Aug 2022 14:04:12 UTC
The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=885ab0dba28b799c5c70923c2cb0ee162b5b75b1 commit 885ab0dba28b799c5c70923c2cb0ee162b5b75b1 Author: Emmanuel Vadot <manu@FreeBSD.org> AuthorDate: 2022-07-26 08:06:56 +0000 Commit: Emmanuel Vadot <manu@FreeBSD.org> CommitDate: 2022-08-08 13:22:34 +0000 linuxkpi: math.h: Add mul_u64_u32_div and mul_u64_u32_shr Needed by drm-kmod. Reviewed by: hselasky Obtained from: OpenBSD Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D35937 --- sys/compat/linuxkpi/common/include/linux/math64.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/math64.h b/sys/compat/linuxkpi/common/include/linux/math64.h index da8b19d37efe..f708f1ae81fa 100644 --- a/sys/compat/linuxkpi/common/include/linux/math64.h +++ b/sys/compat/linuxkpi/common/include/linux/math64.h @@ -100,4 +100,23 @@ div64_u64_round_up(uint64_t dividend, uint64_t divisor) #define DIV64_U64_ROUND_UP(...) \ div64_u64_round_up(__VA_ARGS__) +static inline uint64_t +mul_u64_u32_div(uint64_t x, uint32_t y, uint32_t div) +{ + const uint64_t rem = x % div; + + return ((x / div) * y + (rem * y) / div); +} + +static inline uint64_t +mul_u64_u32_shr(uint64_t x, uint32_t y, unsigned int shift) +{ + uint32_t hi, lo; + hi = x >> 32; + lo = x & 0xffffffff; + + return (mul_u32_u32(lo, y) >> shift) + + (mul_u32_u32(hi, y) << (32 - shift)); +} + #endif /* _LINUXKPI_LINUX_MATH64_H */