[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/15] host-utils: Implemented signed 256-by-128 division
From: |
Daniel Henrique Barboza |
Subject: |
[PULL 05/15] host-utils: Implemented signed 256-by-128 division |
Date: |
Tue, 21 Jun 2022 06:43:50 -0300 |
From: "Lucas Mateus Castro (alqotel)" <lucas.araujo@eldorado.org.br>
Based on already existing QEMU implementation created a signed
256 bit by 128 bit division needed to implement the vector divide
extended signed quadword instruction from PowerISA 3.1
Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220525134954.85056-6-lucas.araujo@eldorado.org.br>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
include/qemu/host-utils.h | 1 +
util/host-utils.c | 51 +++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index 9767af7573..bc743f5e32 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -851,4 +851,5 @@ static inline uint64_t udiv_qrnnd(uint64_t *r, uint64_t n1,
}
Int128 divu256(Int128 *plow, Int128 *phigh, Int128 divisor);
+Int128 divs256(Int128 *plow, Int128 *phigh, Int128 divisor);
#endif
diff --git a/util/host-utils.c b/util/host-utils.c
index 93dfb1b6ab..fb91bcba82 100644
--- a/util/host-utils.c
+++ b/util/host-utils.c
@@ -395,3 +395,54 @@ Int128 divu256(Int128 *plow, Int128 *phigh, Int128 divisor)
return rem;
}
}
+
+/*
+ * Signed 256-by-128 division.
+ * Returns quotient via plow and phigh.
+ * Also returns the remainder via the function return value.
+ */
+Int128 divs256(Int128 *plow, Int128 *phigh, Int128 divisor)
+{
+ bool neg_quotient = false, neg_remainder = false;
+ Int128 unsig_hi = *phigh, unsig_lo = *plow;
+ Int128 rem;
+
+ if (!int128_nonneg(*phigh)) {
+ neg_quotient = !neg_quotient;
+ neg_remainder = !neg_remainder;
+
+ if (!int128_nz(unsig_lo)) {
+ unsig_hi = int128_neg(unsig_hi);
+ } else {
+ unsig_hi = int128_not(unsig_hi);
+ unsig_lo = int128_neg(unsig_lo);
+ }
+ }
+
+ if (!int128_nonneg(divisor)) {
+ neg_quotient = !neg_quotient;
+
+ divisor = int128_neg(divisor);
+ }
+
+ rem = divu256(&unsig_lo, &unsig_hi, divisor);
+
+ if (neg_quotient) {
+ if (!int128_nz(unsig_lo)) {
+ *phigh = int128_neg(unsig_hi);
+ *plow = int128_zero();
+ } else {
+ *phigh = int128_not(unsig_hi);
+ *plow = int128_neg(unsig_lo);
+ }
+ } else {
+ *phigh = unsig_hi;
+ *plow = unsig_lo;
+ }
+
+ if (neg_remainder) {
+ return int128_neg(rem);
+ } else {
+ return rem;
+ }
+}
--
2.36.1
- [PULL 01/15] target/ppc: Implemented vector divide instructions, (continued)
- [PULL 01/15] target/ppc: Implemented vector divide instructions, Daniel Henrique Barboza, 2022/06/21
- [PULL 02/15] target/ppc: Implemented vector divide quadword, Daniel Henrique Barboza, 2022/06/21
- [PULL 03/15] target/ppc: Implemented vector divide extended word, Daniel Henrique Barboza, 2022/06/21
- [PULL 04/15] host-utils: Implemented unsigned 256-by-128 division, Daniel Henrique Barboza, 2022/06/21
- [PULL 08/15] target/ppc: Implemented vector module quadword, Daniel Henrique Barboza, 2022/06/21
- [PULL 07/15] target/ppc: Implemented vector module word/doubleword, Daniel Henrique Barboza, 2022/06/21
- [PULL 11/15] pnv/xive2: Access direct mapped thread contexts from all chips, Daniel Henrique Barboza, 2022/06/21
- [PULL 06/15] target/ppc: Implemented remaining vector divide extended, Daniel Henrique Barboza, 2022/06/21
- [PULL 09/15] ppc: fix boot with sam460ex, Daniel Henrique Barboza, 2022/06/21
- [PULL 12/15] ppc/pnv: fix extra indent spaces with DEFINE_PROP*, Daniel Henrique Barboza, 2022/06/21
- [PULL 05/15] host-utils: Implemented signed 256-by-128 division,
Daniel Henrique Barboza <=
- [PULL 10/15] target/ppc: fix vbpermd in big endian hosts, Daniel Henrique Barboza, 2022/06/21
- [PULL 13/15] target/ppc: avoid int32 multiply overflow in int_helper.c, Daniel Henrique Barboza, 2022/06/21
- [PULL 15/15] target/ppc: cpu_init: Clean up stop state on cpu reset, Daniel Henrique Barboza, 2022/06/21
- [PULL 14/15] target/ppc: fix unreachable code in fpu_helper.c, Daniel Henrique Barboza, 2022/06/21
- Re: [PULL 00/15] ppc queue, Richard Henderson, 2022/06/21