From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: Luis Pires <luis.pires@eldorado.org.br>
Subject: [PULL v2 03/60] host-utils: move udiv_qrnnd() to host-utils
Date: Thu, 28 Oct 2021 21:32:32 -0700 [thread overview]
Message-ID: <20211029043329.1518029-4-richard.henderson@linaro.org> (raw)
In-Reply-To: <20211029043329.1518029-1-richard.henderson@linaro.org>
From: Luis Pires <luis.pires@eldorado.org.br>
Move udiv_qrnnd() from include/fpu/softfloat-macros.h to host-utils,
so it can be reused by divu128().
Signed-off-by: Luis Pires <luis.pires@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20211025191154.350831-3-luis.pires@eldorado.org.br>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/fpu/softfloat-macros.h | 82 ----------------------------------
include/qemu/host-utils.h | 81 +++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+), 82 deletions(-)
diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h
index 81c3fe8256..f35cdbfa63 100644
--- a/include/fpu/softfloat-macros.h
+++ b/include/fpu/softfloat-macros.h
@@ -8,7 +8,6 @@
* so some portions are provided under:
* the SoftFloat-2a license
* the BSD license
- * GPL-v2-or-later
*
* Any future contributions to this file after December 1st 2014 will be
* taken to be licensed under the Softfloat-2a license unless specifically
@@ -75,10 +74,6 @@ this code that are retained.
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-/* Portions of this work are licensed under the terms of the GNU GPL,
- * version 2 or later. See the COPYING file in the top-level directory.
- */
-
#ifndef FPU_SOFTFLOAT_MACROS_H
#define FPU_SOFTFLOAT_MACROS_H
@@ -585,83 +580,6 @@ static inline uint64_t estimateDiv128To64(uint64_t a0, uint64_t a1, uint64_t b)
}
-/* From the GNU Multi Precision Library - longlong.h __udiv_qrnnd
- * (https://gmplib.org/repo/gmp/file/tip/longlong.h)
- *
- * Licensed under the GPLv2/LGPLv3
- */
-static inline uint64_t udiv_qrnnd(uint64_t *r, uint64_t n1,
- uint64_t n0, uint64_t d)
-{
-#if defined(__x86_64__)
- uint64_t q;
- asm("divq %4" : "=a"(q), "=d"(*r) : "0"(n0), "1"(n1), "rm"(d));
- return q;
-#elif defined(__s390x__) && !defined(__clang__)
- /* Need to use a TImode type to get an even register pair for DLGR. */
- unsigned __int128 n = (unsigned __int128)n1 << 64 | n0;
- asm("dlgr %0, %1" : "+r"(n) : "r"(d));
- *r = n >> 64;
- return n;
-#elif defined(_ARCH_PPC64) && defined(_ARCH_PWR7)
- /* From Power ISA 2.06, programming note for divdeu. */
- uint64_t q1, q2, Q, r1, r2, R;
- asm("divdeu %0,%2,%4; divdu %1,%3,%4"
- : "=&r"(q1), "=r"(q2)
- : "r"(n1), "r"(n0), "r"(d));
- r1 = -(q1 * d); /* low part of (n1<<64) - (q1 * d) */
- r2 = n0 - (q2 * d);
- Q = q1 + q2;
- R = r1 + r2;
- if (R >= d || R < r2) { /* overflow implies R > d */
- Q += 1;
- R -= d;
- }
- *r = R;
- return Q;
-#else
- uint64_t d0, d1, q0, q1, r1, r0, m;
-
- d0 = (uint32_t)d;
- d1 = d >> 32;
-
- r1 = n1 % d1;
- q1 = n1 / d1;
- m = q1 * d0;
- r1 = (r1 << 32) | (n0 >> 32);
- if (r1 < m) {
- q1 -= 1;
- r1 += d;
- if (r1 >= d) {
- if (r1 < m) {
- q1 -= 1;
- r1 += d;
- }
- }
- }
- r1 -= m;
-
- r0 = r1 % d1;
- q0 = r1 / d1;
- m = q0 * d0;
- r0 = (r0 << 32) | (uint32_t)n0;
- if (r0 < m) {
- q0 -= 1;
- r0 += d;
- if (r0 >= d) {
- if (r0 < m) {
- q0 -= 1;
- r0 += d;
- }
- }
- }
- r0 -= m;
-
- *r = r0;
- return (q1 << 32) | q0;
-#endif
-}
-
/*----------------------------------------------------------------------------
| Returns an approximation to the square root of the 32-bit significand given
| by `a'. Considered as an integer, `a' must be at least 2^31. If bit 0 of
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index e82e6239af..08a17e16e5 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -23,6 +23,10 @@
* THE SOFTWARE.
*/
+/* Portions of this work are licensed under the terms of the GNU GPL,
+ * version 2 or later. See the COPYING file in the top-level directory.
+ */
+
#ifndef HOST_UTILS_H
#define HOST_UTILS_H
@@ -726,4 +730,81 @@ void urshift(uint64_t *plow, uint64_t *phigh, int32_t shift);
*/
void ulshift(uint64_t *plow, uint64_t *phigh, int32_t shift, bool *overflow);
+/* From the GNU Multi Precision Library - longlong.h __udiv_qrnnd
+ * (https://gmplib.org/repo/gmp/file/tip/longlong.h)
+ *
+ * Licensed under the GPLv2/LGPLv3
+ */
+static inline uint64_t udiv_qrnnd(uint64_t *r, uint64_t n1,
+ uint64_t n0, uint64_t d)
+{
+#if defined(__x86_64__)
+ uint64_t q;
+ asm("divq %4" : "=a"(q), "=d"(*r) : "0"(n0), "1"(n1), "rm"(d));
+ return q;
+#elif defined(__s390x__) && !defined(__clang__)
+ /* Need to use a TImode type to get an even register pair for DLGR. */
+ unsigned __int128 n = (unsigned __int128)n1 << 64 | n0;
+ asm("dlgr %0, %1" : "+r"(n) : "r"(d));
+ *r = n >> 64;
+ return n;
+#elif defined(_ARCH_PPC64) && defined(_ARCH_PWR7)
+ /* From Power ISA 2.06, programming note for divdeu. */
+ uint64_t q1, q2, Q, r1, r2, R;
+ asm("divdeu %0,%2,%4; divdu %1,%3,%4"
+ : "=&r"(q1), "=r"(q2)
+ : "r"(n1), "r"(n0), "r"(d));
+ r1 = -(q1 * d); /* low part of (n1<<64) - (q1 * d) */
+ r2 = n0 - (q2 * d);
+ Q = q1 + q2;
+ R = r1 + r2;
+ if (R >= d || R < r2) { /* overflow implies R > d */
+ Q += 1;
+ R -= d;
+ }
+ *r = R;
+ return Q;
+#else
+ uint64_t d0, d1, q0, q1, r1, r0, m;
+
+ d0 = (uint32_t)d;
+ d1 = d >> 32;
+
+ r1 = n1 % d1;
+ q1 = n1 / d1;
+ m = q1 * d0;
+ r1 = (r1 << 32) | (n0 >> 32);
+ if (r1 < m) {
+ q1 -= 1;
+ r1 += d;
+ if (r1 >= d) {
+ if (r1 < m) {
+ q1 -= 1;
+ r1 += d;
+ }
+ }
+ }
+ r1 -= m;
+
+ r0 = r1 % d1;
+ q0 = r1 / d1;
+ m = q0 * d0;
+ r0 = (r0 << 32) | (uint32_t)n0;
+ if (r0 < m) {
+ q0 -= 1;
+ r0 += d;
+ if (r0 >= d) {
+ if (r0 < m) {
+ q0 -= 1;
+ r0 += d;
+ }
+ }
+ }
+ r0 -= m;
+
+ *r = r0;
+ return (q1 << 32) | q0;
+#endif
+}
+
#endif
--
2.25.1
next prev parent reply other threads:[~2021-10-29 4:39 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-29 4:32 [PULL v2 00/60] tcg patch queue Richard Henderson
2021-10-29 4:32 ` [PULL v2 01/60] qemu/int128: Add int128_{not,xor} Richard Henderson
2021-10-29 4:32 ` [PULL v2 02/60] host-utils: move checks out of divu128/divs128 Richard Henderson
2021-10-29 4:32 ` Richard Henderson [this message]
2021-10-29 4:32 ` [PULL v2 04/60] host-utils: add 128-bit quotient support to divu128/divs128 Richard Henderson
2021-10-29 4:32 ` [PULL v2 05/60] host-utils: add unit tests for divu128/divs128 Richard Henderson
2021-10-29 4:32 ` [PULL v2 06/60] tcg/optimize: Rename "mask" to "z_mask" Richard Henderson
2021-10-29 4:32 ` [PULL v2 07/60] tcg/optimize: Split out OptContext Richard Henderson
2021-10-29 4:32 ` [PULL v2 08/60] tcg/optimize: Remove do_default label Richard Henderson
2021-10-29 4:32 ` [PULL v2 09/60] tcg/optimize: Change tcg_opt_gen_{mov, movi} interface Richard Henderson
2021-10-29 4:32 ` [PULL v2 10/60] tcg/optimize: Move prev_mb into OptContext Richard Henderson
2021-10-29 4:32 ` [PULL v2 11/60] tcg/optimize: Split out init_arguments Richard Henderson
2021-10-29 4:32 ` [PULL v2 12/60] tcg/optimize: Split out copy_propagate Richard Henderson
2021-10-29 4:32 ` [PULL v2 13/60] tcg/optimize: Split out fold_call Richard Henderson
2021-10-29 4:32 ` [PULL v2 14/60] tcg/optimize: Drop nb_oargs, nb_iargs locals Richard Henderson
2021-10-29 4:32 ` [PULL v2 15/60] tcg/optimize: Change fail return for do_constant_folding_cond* Richard Henderson
2021-10-29 4:32 ` [PULL v2 16/60] tcg/optimize: Return true from tcg_opt_gen_{mov, movi} Richard Henderson
2021-10-29 4:32 ` [PULL v2 17/60] tcg/optimize: Split out finish_folding Richard Henderson
2021-10-29 4:32 ` [PULL v2 18/60] tcg/optimize: Use a boolean to avoid a mass of continues Richard Henderson
2021-10-29 4:32 ` [PULL v2 19/60] tcg/optimize: Split out fold_mb, fold_qemu_{ld,st} Richard Henderson
2021-10-29 4:32 ` [PULL v2 20/60] tcg/optimize: Split out fold_const{1,2} Richard Henderson
2021-10-29 4:32 ` [PULL v2 21/60] tcg/optimize: Split out fold_setcond2 Richard Henderson
2021-10-29 4:32 ` [PULL v2 22/60] tcg/optimize: Split out fold_brcond2 Richard Henderson
2021-10-29 4:32 ` [PULL v2 23/60] tcg/optimize: Split out fold_brcond Richard Henderson
2021-10-29 4:32 ` [PULL v2 24/60] tcg/optimize: Split out fold_setcond Richard Henderson
2021-10-29 4:32 ` [PULL v2 25/60] tcg/optimize: Split out fold_mulu2_i32 Richard Henderson
2021-10-29 4:32 ` [PULL v2 26/60] tcg/optimize: Split out fold_addsub2_i32 Richard Henderson
2021-10-29 4:32 ` [PULL v2 27/60] tcg/optimize: Split out fold_movcond Richard Henderson
2021-10-29 4:32 ` [PULL v2 28/60] tcg/optimize: Split out fold_extract2 Richard Henderson
2021-11-09 16:52 ` Peter Maydell
2021-11-09 17:22 ` Richard Henderson
2021-10-29 4:32 ` [PULL v2 29/60] tcg/optimize: Split out fold_extract, fold_sextract Richard Henderson
2021-10-29 4:32 ` [PULL v2 30/60] tcg/optimize: Split out fold_deposit Richard Henderson
2021-10-29 4:33 ` [PULL v2 31/60] tcg/optimize: Split out fold_count_zeros Richard Henderson
2021-10-29 4:33 ` [PULL v2 32/60] tcg/optimize: Split out fold_bswap Richard Henderson
2021-10-29 4:33 ` [PULL v2 33/60] tcg/optimize: Split out fold_dup, fold_dup2 Richard Henderson
2021-10-29 4:33 ` [PULL v2 34/60] tcg/optimize: Split out fold_mov Richard Henderson
2021-10-29 4:33 ` [PULL v2 35/60] tcg/optimize: Split out fold_xx_to_i Richard Henderson
2021-10-29 4:33 ` [PULL v2 36/60] tcg/optimize: Split out fold_xx_to_x Richard Henderson
2021-10-29 4:33 ` [PULL v2 37/60] tcg/optimize: Split out fold_xi_to_i Richard Henderson
2021-10-29 4:33 ` [PULL v2 38/60] tcg/optimize: Add type to OptContext Richard Henderson
2021-10-29 4:33 ` [PULL v2 39/60] tcg/optimize: Split out fold_to_not Richard Henderson
2021-10-29 4:33 ` [PULL v2 40/60] tcg/optimize: Split out fold_sub_to_neg Richard Henderson
2021-10-29 4:33 ` [PULL v2 41/60] tcg/optimize: Split out fold_xi_to_x Richard Henderson
2021-10-29 4:33 ` [PULL v2 42/60] tcg/optimize: Split out fold_ix_to_i Richard Henderson
2021-10-29 4:33 ` [PULL v2 43/60] tcg/optimize: Split out fold_masks Richard Henderson
2021-10-29 4:33 ` [PULL v2 44/60] tcg/optimize: Expand fold_mulu2_i32 to all 4-arg multiplies Richard Henderson
2021-10-29 4:33 ` [PULL v2 45/60] tcg/optimize: Expand fold_addsub2_i32 to 64-bit ops Richard Henderson
2021-10-29 4:33 ` [PULL v2 46/60] tcg/optimize: Sink commutative operand swapping into fold functions Richard Henderson
2021-10-29 4:33 ` [PULL v2 47/60] tcg: Extend call args using the correct opcodes Richard Henderson
2021-10-29 4:33 ` [PULL v2 48/60] tcg/optimize: Stop forcing z_mask to "garbage" for 32-bit values Richard Henderson
2021-10-29 4:33 ` [PULL v2 49/60] tcg/optimize: Use fold_xx_to_i for orc Richard Henderson
2021-10-29 4:33 ` [PULL v2 50/60] tcg/optimize: Use fold_xi_to_x for mul Richard Henderson
2021-10-29 4:33 ` [PULL v2 51/60] tcg/optimize: Use fold_xi_to_x for div Richard Henderson
2021-10-29 4:33 ` [PULL v2 52/60] tcg/optimize: Use fold_xx_to_i for rem Richard Henderson
2021-10-29 4:33 ` [PULL v2 53/60] tcg/optimize: Optimize sign extensions Richard Henderson
2021-10-29 4:33 ` [PULL v2 54/60] tcg/optimize: Propagate sign info for logical operations Richard Henderson
2021-10-29 4:33 ` [PULL v2 55/60] tcg/optimize: Propagate sign info for setcond Richard Henderson
2021-10-29 4:33 ` [PULL v2 56/60] tcg/optimize: Propagate sign info for bit counting Richard Henderson
2021-10-29 4:33 ` [PULL v2 57/60] tcg/optimize: Propagate sign info for shifting Richard Henderson
2021-10-29 4:33 ` [PULL v2 58/60] softmmu: fix watchpoint processing in icount mode Richard Henderson
2021-10-29 4:33 ` [PULL v2 59/60] softmmu: remove useless condition in watchpoint check Richard Henderson
2021-10-29 4:33 ` [PULL v2 60/60] softmmu: fix for "after access" watchpoints Richard Henderson
2021-10-29 17:58 ` [PULL v2 00/60] tcg patch queue Richard Henderson
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=20211029043329.1518029-4-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=luis.pires@eldorado.org.br \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).