All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lucas Mateus Castro(alqotel)" <lucas.araujo@eldorado.org.br>
To: qemu-ppc@nongnu.org
Cc: richard.henderson@linaro.org, clg@kaod.org,
	danielhb413@gmail.com,
	"Lucas Mateus Castro (alqotel)" <lucas.araujo@eldorado.org.br>,
	qemu-devel@nongnu.org (open list:All patches CC here)
Subject: [PATCH RESEND v3 5/8] host-utils: Implemented signed 256-by-128 division
Date: Wed, 25 May 2022 10:49:51 -0300	[thread overview]
Message-ID: <20220525134954.85056-6-lucas.araujo@eldorado.org.br> (raw)
In-Reply-To: <20220525134954.85056-1-lucas.araujo@eldorado.org.br>

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>
---
 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.31.1



  parent reply	other threads:[~2022-05-25 13:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220525134954.85056-1-lucas.araujo@eldorado.org.br>
2022-05-25 13:49 ` [PATCH RESEND v3 1/8] target/ppc: Implemented vector divide instructions Lucas Mateus Castro(alqotel)
2022-06-03 18:04   ` Richard Henderson
2022-05-25 13:49 ` [PATCH RESEND v3 2/8] target/ppc: Implemented vector divide quadword Lucas Mateus Castro(alqotel)
2022-05-25 13:49 ` [PATCH RESEND v3 3/8] target/ppc: Implemented vector divide extended word Lucas Mateus Castro(alqotel)
2022-06-03 18:06   ` Richard Henderson
2022-05-25 13:49 ` [PATCH RESEND v3 4/8] host-utils: Implemented unsigned 256-by-128 division Lucas Mateus Castro(alqotel)
2022-06-03 18:08   ` Richard Henderson
2022-05-25 13:49 ` Lucas Mateus Castro(alqotel) [this message]
2022-05-25 13:49 ` [PATCH RESEND v3 6/8] target/ppc: Implemented remaining vector divide extended Lucas Mateus Castro(alqotel)
2022-05-25 13:49 ` [PATCH RESEND v3 7/8] target/ppc: Implemented vector module word/doubleword Lucas Mateus Castro(alqotel)
2022-06-03 18:09   ` Richard Henderson
2022-05-25 13:49 ` [PATCH RESEND v3 8/8] target/ppc: Implemented vector module quadword Lucas Mateus Castro(alqotel)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220525134954.85056-6-lucas.araujo@eldorado.org.br \
    --to=lucas.araujo@eldorado.org.br \
    --cc=clg@kaod.org \
    --cc=danielhb413@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.