Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/external/bsd/drm2/include/linux mul_u64_u32_shr
details: https://anonhg.NetBSD.org/src/rev/f1c313977143
branches: trunk
changeset: 1028409:f1c313977143
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun Dec 19 10:58:43 2021 +0000
description:
mul_u64_u32_shr
diffstat:
sys/external/bsd/drm2/include/linux/math64.h | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
diffs (31 lines):
diff -r bc221f301e75 -r f1c313977143 sys/external/bsd/drm2/include/linux/math64.h
--- a/sys/external/bsd/drm2/include/linux/math64.h Sun Dec 19 10:58:37 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/math64.h Sun Dec 19 10:58:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: math64.h,v 1.8 2021/12/19 10:48:07 riastradh Exp $ */
+/* $NetBSD: math64.h,v 1.9 2021/12/19 10:58:43 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -75,4 +75,21 @@
return (uint64_t)a * (uint64_t)b;
}
+/* return floor((a*b) / 2^c) */
+static inline uint64_t
+mul_u64_u32_shr(uint64_t a, uint32_t b, unsigned c)
+{
+ /* 2^32 a_hi + a_lo := a */
+ uint64_t a_hi = a >> 32;
+ uint64_t a_lo = a & 0xffffffffU;
+
+ if (c >= 32) {
+ /* (a*b) / 2^c = (a_hi b + a_lo b / 2^32) / 2^{c - 32} */
+ return ((a_hi * b) + ((a_lo * b) >> 32)) >> (c - 32);
+ } else {
+ /* (a*b) / 2^c = 2^{32 - c} a_hi b + a_lo b / 2^c */
+ return ((a_hi * b) << (32 - c)) + ((a_lo * b) >> c);
+ }
+}
+
#endif /* _LINUX_MATH64_H_ */
Home |
Main Index |
Thread Index |
Old Index