All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>
Subject: [PULL 28/40] target/s390x: Use a single return for helper_divs64/u64
Date: Sat,  4 Feb 2023 06:32:58 -1000	[thread overview]
Message-ID: <20230204163310.815536-29-richard.henderson@linaro.org> (raw)
In-Reply-To: <20230204163310.815536-1-richard.henderson@linaro.org>

Pack the quotient and remainder into a single Int128.
Use the divu128 primitive to remove the cpu_abort on
32-bit hosts.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
v2: Extended div test case to cover these insns.
---
 target/s390x/helper.h         |  4 ++--
 target/s390x/tcg/int_helper.c | 38 +++++++++--------------------------
 target/s390x/tcg/translate.c  | 14 +++++++++----
 tests/tcg/s390x/div.c         | 35 ++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+), 35 deletions(-)

diff --git a/target/s390x/helper.h b/target/s390x/helper.h
index bc828d976b..593f3c8bee 100644
--- a/target/s390x/helper.h
+++ b/target/s390x/helper.h
@@ -12,8 +12,8 @@ DEF_HELPER_3(clcl, i32, env, i32, i32)
 DEF_HELPER_FLAGS_4(clm, TCG_CALL_NO_WG, i32, env, i32, i32, i64)
 DEF_HELPER_FLAGS_3(divs32, TCG_CALL_NO_WG, i64, env, s64, s64)
 DEF_HELPER_FLAGS_3(divu32, TCG_CALL_NO_WG, i64, env, i64, i64)
-DEF_HELPER_FLAGS_3(divs64, TCG_CALL_NO_WG, s64, env, s64, s64)
-DEF_HELPER_FLAGS_4(divu64, TCG_CALL_NO_WG, i64, env, i64, i64, i64)
+DEF_HELPER_FLAGS_3(divs64, TCG_CALL_NO_WG, i128, env, s64, s64)
+DEF_HELPER_FLAGS_4(divu64, TCG_CALL_NO_WG, i128, env, i64, i64, i64)
 DEF_HELPER_3(srst, void, env, i32, i32)
 DEF_HELPER_3(srstu, void, env, i32, i32)
 DEF_HELPER_4(clst, i64, env, i64, i64, i64)
diff --git a/target/s390x/tcg/int_helper.c b/target/s390x/tcg/int_helper.c
index 7260583cf2..eb8e6dd1b5 100644
--- a/target/s390x/tcg/int_helper.c
+++ b/target/s390x/tcg/int_helper.c
@@ -76,46 +76,26 @@ uint64_t HELPER(divu32)(CPUS390XState *env, uint64_t a, uint64_t b64)
 }
 
 /* 64/64 -> 64 signed division */
-int64_t HELPER(divs64)(CPUS390XState *env, int64_t a, int64_t b)
+Int128 HELPER(divs64)(CPUS390XState *env, int64_t a, int64_t b)
 {
     /* Catch divide by zero, and non-representable quotient (MIN / -1).  */
     if (b == 0 || (b == -1 && a == (1ll << 63))) {
         tcg_s390_program_interrupt(env, PGM_FIXPT_DIVIDE, GETPC());
     }
-    env->retxl = a % b;
-    return a / b;
+    return int128_make128(a / b, a % b);
 }
 
 /* 128 -> 64/64 unsigned division */
-uint64_t HELPER(divu64)(CPUS390XState *env, uint64_t ah, uint64_t al,
-                        uint64_t b)
+Int128 HELPER(divu64)(CPUS390XState *env, uint64_t ah, uint64_t al, uint64_t b)
 {
-    uint64_t ret;
-    /* Signal divide by zero.  */
-    if (b == 0) {
-        tcg_s390_program_interrupt(env, PGM_FIXPT_DIVIDE, GETPC());
-    }
-    if (ah == 0) {
-        /* 64 -> 64/64 case */
-        env->retxl = al % b;
-        ret = al / b;
-    } else {
-        /* ??? Move i386 idivq helper to host-utils.  */
-#ifdef CONFIG_INT128
-        __uint128_t a = ((__uint128_t)ah << 64) | al;
-        __uint128_t q = a / b;
-        env->retxl = a % b;
-        ret = q;
-        if (ret != q) {
-            tcg_s390_program_interrupt(env, PGM_FIXPT_DIVIDE, GETPC());
+    if (b != 0) {
+        uint64_t r = divu128(&al, &ah, b);
+        if (ah == 0) {
+            return int128_make128(al, r);
         }
-#else
-        /* 32-bit hosts would need special wrapper functionality - just abort if
-           we encounter such a case; it's very unlikely anyways. */
-        cpu_abort(env_cpu(env), "128 -> 64/64 division not implemented\n");
-#endif
     }
-    return ret;
+    /* divide by zero or overflow */
+    tcg_s390_program_interrupt(env, PGM_FIXPT_DIVIDE, GETPC());
 }
 
 uint64_t HELPER(cvd)(int32_t reg)
diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c
index 169f7ee1b2..6953b81de7 100644
--- a/target/s390x/tcg/translate.c
+++ b/target/s390x/tcg/translate.c
@@ -2409,15 +2409,21 @@ static DisasJumpType op_divu32(DisasContext *s, DisasOps *o)
 
 static DisasJumpType op_divs64(DisasContext *s, DisasOps *o)
 {
-    gen_helper_divs64(o->out2, cpu_env, o->in1, o->in2);
-    return_low128(o->out);
+    TCGv_i128 t = tcg_temp_new_i128();
+
+    gen_helper_divs64(t, cpu_env, o->in1, o->in2);
+    tcg_gen_extr_i128_i64(o->out2, o->out, t);
+    tcg_temp_free_i128(t);
     return DISAS_NEXT;
 }
 
 static DisasJumpType op_divu64(DisasContext *s, DisasOps *o)
 {
-    gen_helper_divu64(o->out2, cpu_env, o->out, o->out2, o->in2);
-    return_low128(o->out);
+    TCGv_i128 t = tcg_temp_new_i128();
+
+    gen_helper_divu64(t, cpu_env, o->out, o->out2, o->in2);
+    tcg_gen_extr_i128_i64(o->out2, o->out, t);
+    tcg_temp_free_i128(t);
     return DISAS_NEXT;
 }
 
diff --git a/tests/tcg/s390x/div.c b/tests/tcg/s390x/div.c
index 5807295614..6ad9900e08 100644
--- a/tests/tcg/s390x/div.c
+++ b/tests/tcg/s390x/div.c
@@ -33,8 +33,43 @@ static void test_dlr(void)
     assert(r == 1);
 }
 
+static void test_dsgr(void)
+{
+    register int64_t r0 asm("r0") = -1;
+    register int64_t r1 asm("r1") = -4241;
+    int64_t b = 101, q, r;
+
+    asm("dsgr %[r0],%[b]"
+        : [r0] "+r" (r0), [r1] "+r" (r1)
+        : [b] "r" (b)
+        : "cc");
+    q = r1;
+    r = r0;
+    assert(q == -41);
+    assert(r == -100);
+}
+
+static void test_dlgr(void)
+{
+    register uint64_t r0 asm("r0") = 0;
+    register uint64_t r1 asm("r1") = 4243;
+    uint64_t b = 101, q, r;
+
+    asm("dlgr %[r0],%[b]"
+        : [r0] "+r" (r0), [r1] "+r" (r1)
+        : [b] "r" (b)
+        : "cc");
+    q = r1;
+    r = r0;
+    assert(q == 42);
+    assert(r == 1);
+}
+
 int main(void)
 {
     test_dr();
     test_dlr();
+    test_dsgr();
+    test_dlgr();
+    return 0;
 }
-- 
2.34.1



  parent reply	other threads:[~2023-02-04 16:34 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-04 16:32 [PULL 00/40] tcg patch queue Richard Henderson
2023-02-04 16:32 ` [PULL 01/40] accel/tcg: Test CPUJumpCache in tb_jmp_cache_clear_page Richard Henderson
2023-02-04 16:32 ` [PULL 02/40] tcg: Init temp_subindex in liveness_pass_2 Richard Henderson
2023-02-04 16:32 ` [PULL 03/40] tcg: Define TCG_TYPE_I128 and related helper macros Richard Henderson
2023-02-04 16:32 ` [PULL 04/40] tcg: Handle dh_typecode_i128 with TCG_CALL_{RET, ARG}_NORMAL Richard Henderson
2023-02-04 16:32 ` [PULL 05/40] tcg: Allocate objects contiguously in temp_allocate_frame Richard Henderson
2023-02-04 16:32 ` [PULL 06/40] tcg: Introduce tcg_out_addi_ptr Richard Henderson
2023-02-04 16:32 ` [PULL 07/40] tcg: Add TCG_CALL_{RET,ARG}_BY_REF Richard Henderson
2023-02-04 16:32 ` [PULL 08/40] tcg: Introduce tcg_target_call_oarg_reg Richard Henderson
2023-02-04 16:32 ` [PULL 09/40] tcg: Add TCG_CALL_RET_BY_VEC Richard Henderson
2023-02-04 16:32 ` [PULL 10/40] include/qemu/int128: Use Int128 structure for TCI Richard Henderson
2023-02-04 16:32 ` [PULL 11/40] tcg/i386: Add TCG_TARGET_CALL_{RET,ARG}_I128 Richard Henderson
2023-02-04 16:32 ` [PULL 12/40] tcg/tci: Fix big-endian return register ordering Richard Henderson
2023-02-04 16:32 ` [PULL 13/40] tcg/tci: Add TCG_TARGET_CALL_{RET,ARG}_I128 Richard Henderson
2023-02-04 16:32 ` [PULL 14/40] tcg: " Richard Henderson
2023-02-04 16:32 ` [PULL 15/40] tcg: Add temp allocation for TCGv_i128 Richard Henderson
2023-02-04 16:32 ` [PULL 16/40] tcg: Add basic data movement " Richard Henderson
2023-02-04 16:32 ` [PULL 17/40] tcg: Add guest load/store primitives " Richard Henderson
2023-02-04 16:32 ` [PULL 18/40] tcg: Add tcg_gen_{non}atomic_cmpxchg_i128 Richard Henderson
2023-02-04 16:32 ` [PULL 19/40] tcg: Split out tcg_gen_nonatomic_cmpxchg_i{32,64} Richard Henderson
2023-02-04 16:32 ` [PULL 20/40] target/arm: Use tcg_gen_atomic_cmpxchg_i128 for STXP Richard Henderson
2023-02-04 16:32 ` [PULL 21/40] target/arm: Use tcg_gen_atomic_cmpxchg_i128 for CASP Richard Henderson
2023-02-04 16:32 ` [PULL 22/40] target/ppc: Use tcg_gen_atomic_cmpxchg_i128 for STQCX Richard Henderson
2023-02-04 16:32 ` [PULL 23/40] tests/tcg/s390x: Add div.c Richard Henderson
2023-02-04 16:32 ` [PULL 24/40] tests/tcg/s390x: Add clst.c Richard Henderson
2023-02-04 16:32 ` [PULL 25/40] tests/tcg/s390x: Add long-double.c Richard Henderson
2023-02-04 16:32 ` [PULL 26/40] tests/tcg/s390x: Add cdsg.c Richard Henderson
2023-02-04 16:32 ` [PULL 27/40] target/s390x: Use a single return for helper_divs32/u32 Richard Henderson
2023-02-04 16:32 ` Richard Henderson [this message]
2023-02-04 16:32 ` [PULL 29/40] target/s390x: Use Int128 for return from CLST Richard Henderson
2023-02-04 16:33 ` [PULL 30/40] target/s390x: Use Int128 for return from CKSM Richard Henderson
2023-02-04 16:33 ` [PULL 31/40] target/s390x: Use Int128 for return from TRE Richard Henderson
2023-02-04 16:33 ` [PULL 32/40] target/s390x: Copy wout_x1 to wout_x1_P Richard Henderson
2023-02-04 16:33 ` [PULL 33/40] target/s390x: Use Int128 for returning float128 Richard Henderson
2023-02-04 16:33 ` [PULL 34/40] target/s390x: Use Int128 for passing float128 Richard Henderson
2023-02-04 16:33 ` [PULL 35/40] target/s390x: Use tcg_gen_atomic_cmpxchg_i128 for CDSG Richard Henderson
2023-02-04 16:33 ` [PULL 36/40] target/s390x: Implement CC_OP_NZ in gen_op_calc_cc Richard Henderson
2023-02-04 16:33 ` [PULL 37/40] target/i386: Split out gen_cmpxchg8b, gen_cmpxchg16b Richard Henderson
2023-02-04 16:33 ` [PULL 38/40] target/i386: Inline cmpxchg8b Richard Henderson
2023-02-04 16:33 ` [PULL 39/40] target/i386: Inline cmpxchg16b Richard Henderson
2023-02-04 16:33 ` [PULL 40/40] tcg/aarch64: Fix patching of LDR in tb_target_set_jmp_target Richard Henderson
2023-02-05 16:48 ` [PULL 00/40] tcg patch queue Peter Maydell

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=20230204163310.815536-29-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=iii@linux.ibm.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --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 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.