[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 05/15] host-utils: Introduce mulu128
From: |
Luis Pires |
Subject: |
[PATCH v5 05/15] host-utils: Introduce mulu128 |
Date: |
Fri, 29 Oct 2021 16:24:07 -0300 |
Signed-off-by: Luis Pires <luis.pires@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
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.25.1
- [PATCH v5 00/15] target/ppc: DFP instructions using decodetree, Luis Pires, 2021/10/29
- [PATCH v5 01/15] libdecnumber: introduce decNumberFrom[U]Int128, Luis Pires, 2021/10/29
- [PATCH v5 02/15] target/ppc: Move REQUIRE_ALTIVEC/VECTOR to translate.c, Luis Pires, 2021/10/29
- [PATCH v5 03/15] target/ppc: Introduce REQUIRE_FPU, Luis Pires, 2021/10/29
- [PATCH v5 04/15] target/ppc: Implement DCFFIXQQ, Luis Pires, 2021/10/29
- [PATCH v5 05/15] host-utils: Introduce mulu128,
Luis Pires <=
- [PATCH v5 06/15] libdecnumber: Introduce decNumberIntegralToInt128, Luis Pires, 2021/10/29
- [PATCH v5 07/15] target/ppc: Implement DCTFIXQQ, Luis Pires, 2021/10/29
- [PATCH v5 08/15] target/ppc: Do not update nip on DFP instructions, Luis Pires, 2021/10/29
- [PATCH v5 09/15] target/ppc: Move dtstdc[q]/dtstdg[q] to decodetree, Luis Pires, 2021/10/29
- [PATCH v5 10/15] target/ppc: Move d{add, sub, mul, div, iex}[q] to decodetree, Luis Pires, 2021/10/29
- [PATCH v5 11/15] target/ppc: Move dcmp{u, o}[q], dts{tex, tsf, tsfi}[q] to decodetree, Luis Pires, 2021/10/29
- [PATCH v5 12/15] target/ppc: Move dquai[q], drint{x, n}[q] to decodetree, Luis Pires, 2021/10/29
- [PATCH v5 13/15] target/ppc: Move dqua[q], drrnd[q] to decodetree, Luis Pires, 2021/10/29
- [PATCH v5 14/15] target/ppc: Move dct{dp, qpq}, dr{sp, dpq}, dc{f, t}fix[q], dxex[q] to decodetree, Luis Pires, 2021/10/29
- [PATCH v5 15/15] target/ppc: Move ddedpd[q], denbcd[q], dscli[q], dscri[q] to decodetree, Luis Pires, 2021/10/29