[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/54] host-utils: Introduce mulu128
From: |
David Gibson |
Subject: |
[PULL 15/54] host-utils: Introduce mulu128 |
Date: |
Tue, 9 Nov 2021 16:51:25 +1100 |
From: Luis Pires <luis.pires@eldorado.org.br>
Signed-off-by: Luis Pires <luis.pires@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20211029192417.400707-6-luis.pires@eldorado.org.br>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
include/qemu/host-utils.h | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index a3a7ced78d..ca979dc6cc 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -590,6 +590,42 @@ static inline bool umul64_overflow(uint64_t x, uint64_t y,
uint64_t *ret)
#endif
}
+/*
+ * Unsigned 128x64 multiplication.
+ * Returns true if the result got truncated to 128 bits.
+ * Otherwise, returns false and the multiplication result via plow and phigh.
+ */
+static inline bool mulu128(uint64_t *plow, uint64_t *phigh, uint64_t factor)
+{
+#if defined(CONFIG_INT128) && \
+ (__has_builtin(__builtin_mul_overflow) || __GNUC__ >= 5)
+ bool res;
+ __uint128_t r;
+ __uint128_t f = ((__uint128_t)*phigh << 64) | *plow;
+ res = __builtin_mul_overflow(f, factor, &r);
+
+ *plow = r;
+ *phigh = r >> 64;
+
+ return res;
+#else
+ uint64_t dhi = *phigh;
+ uint64_t dlo = *plow;
+ uint64_t ahi;
+ uint64_t blo, bhi;
+
+ if (dhi == 0) {
+ mulu64(plow, phigh, dlo, factor);
+ return false;
+ }
+
+ mulu64(plow, &ahi, dlo, factor);
+ mulu64(&blo, &bhi, dhi, factor);
+
+ return uadd64_overflow(ahi, blo, phigh) || bhi != 0;
+#endif
+}
+
/**
* uadd64_carry - addition with carry-in and carry-out
* @x, @y: addends
--
2.33.1
- [PULL 00/54] ppc-for-6.2 queue 20211109, David Gibson, 2021/11/09
- [PULL 04/54] target/ppc: Implement PLFS, PLFD, PSTFS and PSTFD instructions, David Gibson, 2021/11/09
- [PULL 02/54] target/ppc: move resolve_PLS_D to translate.c, David Gibson, 2021/11/09
- [PULL 01/54] target/ppc: introduce do_ea_calc, David Gibson, 2021/11/09
- [PULL 03/54] target/ppc: Move load and store floating point instructions to decodetree, David Gibson, 2021/11/09
- [PULL 15/54] host-utils: Introduce mulu128,
David Gibson <=
- [PULL 08/54] target/ppc: Implement cnttzdm, David Gibson, 2021/11/09
- [PULL 09/54] target/ppc: Implement pdepd instruction, David Gibson, 2021/11/09
- [PULL 07/54] target/ppc: Implement cntlzdm, David Gibson, 2021/11/09
- [PULL 05/54] target/ppc: Move LQ and STQ to decodetree, David Gibson, 2021/11/09
- [PULL 10/54] target/ppc: Implement pextd instruction, David Gibson, 2021/11/09
- [PULL 14/54] target/ppc: Implement DCFFIXQQ, David Gibson, 2021/11/09
- [PULL 12/54] target/ppc: Move REQUIRE_ALTIVEC/VECTOR to translate.c, David Gibson, 2021/11/09
- [PULL 11/54] libdecnumber: introduce decNumberFrom[U]Int128, David Gibson, 2021/11/09
- [PULL 16/54] libdecnumber: Introduce decNumberIntegralToInt128, David Gibson, 2021/11/09
- [PULL 28/54] target/ppc: Move vcfuged to vmx-impl.c.inc, David Gibson, 2021/11/09