Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Sep 2022 15:10:03 GMT
From:      Emmanuel Vadot <manu@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: b00f8e7ff01e - stable/13 - linuxkpi: math.h: Add mul_u64_u32_div and mul_u64_u32_shr
Message-ID:  <202209071510.287FA3Hl019396@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=b00f8e7ff01e442f1e28e9dd80b111245fdd4509

commit b00f8e7ff01e442f1e28e9dd80b111245fdd4509
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-07-26 08:06:56 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-09-07 15:09:03 +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
    
    (cherry picked from commit 885ab0dba28b799c5c70923c2cb0ee162b5b75b1)
---
 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 */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202209071510.287FA3Hl019396>