[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 13/35] host-utils: Add muldiv64_round_up
From: |
Cédric Le Goater |
Subject: |
[PULL 13/35] host-utils: Add muldiv64_round_up |
Date: |
Mon, 4 Sep 2023 11:06:08 +0200 |
From: Nicholas Piggin <npiggin@gmail.com>
This will be used for converting time intervals in different base units
to host units, for the purpose of scheduling timers to emulate target
timers. Timers typically must not fire before their requested expiry
time but may fire some time afterward, so rounding up is the right way
to implement these.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
include/qemu/host-utils.h | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index 011618373e59..e2a50a567f6b 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -56,6 +56,11 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b,
uint32_t c)
return (__int128_t)a * b / c;
}
+static inline uint64_t muldiv64_round_up(uint64_t a, uint32_t b, uint32_t c)
+{
+ return ((__int128_t)a * b + c - 1) / c;
+}
+
static inline uint64_t divu128(uint64_t *plow, uint64_t *phigh,
uint64_t divisor)
{
@@ -83,7 +88,8 @@ void mulu64(uint64_t *plow, uint64_t *phigh, uint64_t a,
uint64_t b);
uint64_t divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor);
int64_t divs128(uint64_t *plow, int64_t *phigh, int64_t divisor);
-static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
+static inline uint64_t __muldiv64(uint64_t a, uint32_t b, uint32_t c,
+ bool round_up)
{
union {
uint64_t ll;
@@ -99,12 +105,25 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b,
uint32_t c)
u.ll = a;
rl = (uint64_t)u.l.low * (uint64_t)b;
+ if (round_up) {
+ rl += c - 1;
+ }
rh = (uint64_t)u.l.high * (uint64_t)b;
rh += (rl >> 32);
res.l.high = rh / c;
res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c;
return res.ll;
}
+
+static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
+{
+ return __muldiv64(a, b, c, false);
+}
+
+static inline uint64_t muldiv64_round_up(uint64_t a, uint32_t b, uint32_t c)
+{
+ return __muldiv64(a, b, c, true);
+}
#endif
/**
--
2.41.0
- [PULL 06/35] target/ppc: Implement breakpoint debug facility for v2.07S, (continued)
- [PULL 06/35] target/ppc: Implement breakpoint debug facility for v2.07S, Cédric Le Goater, 2023/09/04
- [PULL 01/35] target/ppc: Generate storage interrupts for radix RC changes, Cédric Le Goater, 2023/09/04
- [PULL 05/35] target/ppc: Suppress single step interrupts on rfi-type instructions, Cédric Le Goater, 2023/09/04
- [PULL 04/35] target/ppc: Improve book3s branch trace interrupt for v2.07S, Cédric Le Goater, 2023/09/04
- [PULL 07/35] target/ppc: Implement watchpoint debug facility for v2.07S, Cédric Le Goater, 2023/09/04
- [PULL 08/35] spapr: implement H_SET_MODE debug facilities, Cédric Le Goater, 2023/09/04
- [PULL 09/35] ppc/vhyp: reset exception state when handling vhyp hcall, Cédric Le Goater, 2023/09/04
- [PULL 10/35] ppc/vof: Fix missed fields in VOF cleanup, Cédric Le Goater, 2023/09/04
- [PULL 11/35] hw/ppc/ppc.c: Tidy over-long lines, Cédric Le Goater, 2023/09/04
- [PULL 12/35] hw/ppc: Introduce functions for conversion between timebase and nanoseconds, Cédric Le Goater, 2023/09/04
- [PULL 13/35] host-utils: Add muldiv64_round_up,
Cédric Le Goater <=
- [PULL 14/35] hw/ppc: Round up the decrementer interval when converting to ns, Cédric Le Goater, 2023/09/04
- [PULL 15/35] hw/ppc: Avoid decrementer rounding errors, Cédric Le Goater, 2023/09/04
- [PULL 16/35] target/ppc: Sign-extend large decrementer to 64-bits, Cédric Le Goater, 2023/09/04
- [PULL 17/35] hw/ppc: Always store the decrementer value, Cédric Le Goater, 2023/09/04
- [PULL 18/35] target/ppc: Migrate DECR SPR, Cédric Le Goater, 2023/09/04
- [PULL 19/35] hw/ppc: Reset timebase facilities on machine reset, Cédric Le Goater, 2023/09/04
- [PULL 20/35] hw/ppc: Read time only once to perform decrementer write, Cédric Le Goater, 2023/09/04
- [PULL 21/35] target/ppc: Fix CPU reservation migration for record-replay, Cédric Le Goater, 2023/09/04
- [PULL 23/35] spapr: Fix machine reset deadlock from replay-record, Cédric Le Goater, 2023/09/04
- [PULL 25/35] tests/avocado: boot ppc64 pseries replay-record test to Linux VFS mount, Cédric Le Goater, 2023/09/04