dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0008-target-s390x-split-integer-helpers.patch

5544c1
From e9f67c1f326a995ff0000a08a223435386867d8f Mon Sep 17 00:00:00 2001
5544c1
From: Blue Swirl <blauwirbel@gmail.com>
5544c1
Date: Sun, 2 Sep 2012 07:33:33 +0000
5544c1
Subject: [PATCH] target-s390x: split integer helpers
5544c1
5544c1
Move integer helpers to int_helper.c.
5544c1
5544c1
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
5544c1
Signed-off-by: Alexander Graf <agraf@suse.de>
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 target-s390x/Makefile.objs |   3 +-
5544c1
 target-s390x/int_helper.c  | 201 +++++++++++++++++++++++++++++++++++++++++++++
5544c1
 target-s390x/op_helper.c   | 170 --------------------------------------
5544c1
 3 files changed, 203 insertions(+), 171 deletions(-)
5544c1
 create mode 100644 target-s390x/int_helper.c
5544c1
5544c1
diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
5544c1
index f9437d6..e8f66e9 100644
5544c1
--- a/target-s390x/Makefile.objs
5544c1
+++ b/target-s390x/Makefile.objs
5544c1
@@ -1,8 +1,9 @@
5544c1
 obj-y += translate.o op_helper.o helper.o cpu.o interrupt.o
5544c1
-obj-y += fpu_helper.o cc_helper.o
5544c1
+obj-y += int_helper.o fpu_helper.o cc_helper.o
5544c1
 obj-$(CONFIG_SOFTMMU) += machine.o
5544c1
 obj-$(CONFIG_KVM) += kvm.o
5544c1
 
5544c1
 $(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
5544c1
+$(obj)/int_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
5544c1
 $(obj)/fpu_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
5544c1
 $(obj)/cc_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
5544c1
diff --git a/target-s390x/int_helper.c b/target-s390x/int_helper.c
5544c1
new file mode 100644
5544c1
index 0000000..e2eeb07
5544c1
--- /dev/null
5544c1
+++ b/target-s390x/int_helper.c
5544c1
@@ -0,0 +1,201 @@
5544c1
+/*
5544c1
+ *  S/390 integer helper routines
5544c1
+ *
5544c1
+ *  Copyright (c) 2009 Ulrich Hecht
5544c1
+ *  Copyright (c) 2009 Alexander Graf
5544c1
+ *
5544c1
+ * This library is free software; you can redistribute it and/or
5544c1
+ * modify it under the terms of the GNU Lesser General Public
5544c1
+ * License as published by the Free Software Foundation; either
5544c1
+ * version 2 of the License, or (at your option) any later version.
5544c1
+ *
5544c1
+ * This library is distributed in the hope that it will be useful,
5544c1
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
5544c1
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5544c1
+ * Lesser General Public License for more details.
5544c1
+ *
5544c1
+ * You should have received a copy of the GNU Lesser General Public
5544c1
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
5544c1
+ */
5544c1
+
5544c1
+#include "cpu.h"
5544c1
+#include "dyngen-exec.h"
5544c1
+#include "host-utils.h"
5544c1
+#include "helper.h"
5544c1
+
5544c1
+/* #define DEBUG_HELPER */
5544c1
+#ifdef DEBUG_HELPER
5544c1
+#define HELPER_LOG(x...) qemu_log(x)
5544c1
+#else
5544c1
+#define HELPER_LOG(x...)
5544c1
+#endif
5544c1
+
5544c1
+/* 64/64 -> 128 unsigned multiplication */
5544c1
+void HELPER(mlg)(uint32_t r1, uint64_t v2)
5544c1
+{
5544c1
+#if HOST_LONG_BITS == 64 && defined(__GNUC__)
5544c1
+    /* assuming 64-bit hosts have __uint128_t */
5544c1
+    __uint128_t res = (__uint128_t)env->regs[r1 + 1];
5544c1
+
5544c1
+    res *= (__uint128_t)v2;
5544c1
+    env->regs[r1] = (uint64_t)(res >> 64);
5544c1
+    env->regs[r1 + 1] = (uint64_t)res;
5544c1
+#else
5544c1
+    mulu64(&env->regs[r1 + 1], &env->regs[r1], env->regs[r1 + 1], v2);
5544c1
+#endif
5544c1
+}
5544c1
+
5544c1
+/* 128 -> 64/64 unsigned division */
5544c1
+void HELPER(dlg)(uint32_t r1, uint64_t v2)
5544c1
+{
5544c1
+    uint64_t divisor = v2;
5544c1
+
5544c1
+    if (!env->regs[r1]) {
5544c1
+        /* 64 -> 64/64 case */
5544c1
+        env->regs[r1] = env->regs[r1 + 1] % divisor;
5544c1
+        env->regs[r1 + 1] = env->regs[r1 + 1] / divisor;
5544c1
+        return;
5544c1
+    } else {
5544c1
+#if HOST_LONG_BITS == 64 && defined(__GNUC__)
5544c1
+        /* assuming 64-bit hosts have __uint128_t */
5544c1
+        __uint128_t dividend = (((__uint128_t)env->regs[r1]) << 64) |
5544c1
+            (env->regs[r1 + 1]);
5544c1
+        __uint128_t quotient = dividend / divisor;
5544c1
+        __uint128_t remainder = dividend % divisor;
5544c1
+
5544c1
+        env->regs[r1 + 1] = quotient;
5544c1
+        env->regs[r1] = remainder;
5544c1
+#else
5544c1
+        /* 32-bit hosts would need special wrapper functionality - just abort if
5544c1
+           we encounter such a case; it's very unlikely anyways. */
5544c1
+        cpu_abort(env, "128 -> 64/64 division not implemented\n");
5544c1
+#endif
5544c1
+    }
5544c1
+}
5544c1
+
5544c1
+/* absolute value 32-bit */
5544c1
+uint32_t HELPER(abs_i32)(int32_t val)
5544c1
+{
5544c1
+    if (val < 0) {
5544c1
+        return -val;
5544c1
+    } else {
5544c1
+        return val;
5544c1
+    }
5544c1
+}
5544c1
+
5544c1
+/* negative absolute value 32-bit */
5544c1
+int32_t HELPER(nabs_i32)(int32_t val)
5544c1
+{
5544c1
+    if (val < 0) {
5544c1
+        return val;
5544c1
+    } else {
5544c1
+        return -val;
5544c1
+    }
5544c1
+}
5544c1
+
5544c1
+/* absolute value 64-bit */
5544c1
+uint64_t HELPER(abs_i64)(int64_t val)
5544c1
+{
5544c1
+    HELPER_LOG("%s: val 0x%" PRIx64 "\n", __func__, val);
5544c1
+
5544c1
+    if (val < 0) {
5544c1
+        return -val;
5544c1
+    } else {
5544c1
+        return val;
5544c1
+    }
5544c1
+}
5544c1
+
5544c1
+/* negative absolute value 64-bit */
5544c1
+int64_t HELPER(nabs_i64)(int64_t val)
5544c1
+{
5544c1
+    if (val < 0) {
5544c1
+        return val;
5544c1
+    } else {
5544c1
+        return -val;
5544c1
+    }
5544c1
+}
5544c1
+
5544c1
+/* add with carry 32-bit unsigned */
5544c1
+uint32_t HELPER(addc_u32)(uint32_t cc, uint32_t v1, uint32_t v2)
5544c1
+{
5544c1
+    uint32_t res;
5544c1
+
5544c1
+    res = v1 + v2;
5544c1
+    if (cc & 2) {
5544c1
+        res++;
5544c1
+    }
5544c1
+
5544c1
+    return res;
5544c1
+}
5544c1
+
5544c1
+/* subtract unsigned v2 from v1 with borrow */
5544c1
+uint32_t HELPER(slb)(uint32_t cc, uint32_t r1, uint32_t v2)
5544c1
+{
5544c1
+    uint32_t v1 = env->regs[r1];
5544c1
+    uint32_t res = v1 + (~v2) + (cc >> 1);
5544c1
+
5544c1
+    env->regs[r1] = (env->regs[r1] & 0xffffffff00000000ULL) | res;
5544c1
+    if (cc & 2) {
5544c1
+        /* borrow */
5544c1
+        return v1 ? 1 : 0;
5544c1
+    } else {
5544c1
+        return v1 ? 3 : 2;
5544c1
+    }
5544c1
+}
5544c1
+
5544c1
+/* subtract unsigned v2 from v1 with borrow */
5544c1
+uint32_t HELPER(slbg)(uint32_t cc, uint32_t r1, uint64_t v1, uint64_t v2)
5544c1
+{
5544c1
+    uint64_t res = v1 + (~v2) + (cc >> 1);
5544c1
+
5544c1
+    env->regs[r1] = res;
5544c1
+    if (cc & 2) {
5544c1
+        /* borrow */
5544c1
+        return v1 ? 1 : 0;
5544c1
+    } else {
5544c1
+        return v1 ? 3 : 2;
5544c1
+    }
5544c1
+}
5544c1
+
5544c1
+/* find leftmost one */
5544c1
+uint32_t HELPER(flogr)(uint32_t r1, uint64_t v2)
5544c1
+{
5544c1
+    uint64_t res = 0;
5544c1
+    uint64_t ov2 = v2;
5544c1
+
5544c1
+    while (!(v2 & 0x8000000000000000ULL) && v2) {
5544c1
+        v2 <<= 1;
5544c1
+        res++;
5544c1
+    }
5544c1
+
5544c1
+    if (!v2) {
5544c1
+        env->regs[r1] = 64;
5544c1
+        env->regs[r1 + 1] = 0;
5544c1
+        return 0;
5544c1
+    } else {
5544c1
+        env->regs[r1] = res;
5544c1
+        env->regs[r1 + 1] = ov2 & ~(0x8000000000000000ULL >> res);
5544c1
+        return 2;
5544c1
+    }
5544c1
+}
5544c1
+
5544c1
+uint64_t HELPER(cvd)(int32_t bin)
5544c1
+{
5544c1
+    /* positive 0 */
5544c1
+    uint64_t dec = 0x0c;
5544c1
+    int shift = 4;
5544c1
+
5544c1
+    if (bin < 0) {
5544c1
+        bin = -bin;
5544c1
+        dec = 0x0d;
5544c1
+    }
5544c1
+
5544c1
+    for (shift = 4; (shift < 64) && bin; shift += 4) {
5544c1
+        int current_number = bin % 10;
5544c1
+
5544c1
+        dec |= (current_number) << shift;
5544c1
+        bin /= 10;
5544c1
+    }
5544c1
+
5544c1
+    return dec;
5544c1
+}
5544c1
diff --git a/target-s390x/op_helper.c b/target-s390x/op_helper.c
5544c1
index eced890..3b8b997 100644
5544c1
--- a/target-s390x/op_helper.c
5544c1
+++ b/target-s390x/op_helper.c
5544c1
@@ -352,49 +352,6 @@ void HELPER(stcm)(uint32_t r1, uint32_t mask, uint64_t addr)
5544c1
     HELPER_LOG("\n");
5544c1
 }
5544c1
 
5544c1
-/* 64/64 -> 128 unsigned multiplication */
5544c1
-void HELPER(mlg)(uint32_t r1, uint64_t v2)
5544c1
-{
5544c1
-#if HOST_LONG_BITS == 64 && defined(__GNUC__)
5544c1
-    /* assuming 64-bit hosts have __uint128_t */
5544c1
-    __uint128_t res = (__uint128_t)env->regs[r1 + 1];
5544c1
-
5544c1
-    res *= (__uint128_t)v2;
5544c1
-    env->regs[r1] = (uint64_t)(res >> 64);
5544c1
-    env->regs[r1 + 1] = (uint64_t)res;
5544c1
-#else
5544c1
-    mulu64(&env->regs[r1 + 1], &env->regs[r1], env->regs[r1 + 1], v2);
5544c1
-#endif
5544c1
-}
5544c1
-
5544c1
-/* 128 -> 64/64 unsigned division */
5544c1
-void HELPER(dlg)(uint32_t r1, uint64_t v2)
5544c1
-{
5544c1
-    uint64_t divisor = v2;
5544c1
-
5544c1
-    if (!env->regs[r1]) {
5544c1
-        /* 64 -> 64/64 case */
5544c1
-        env->regs[r1] = env->regs[r1 + 1] % divisor;
5544c1
-        env->regs[r1 + 1] = env->regs[r1 + 1] / divisor;
5544c1
-        return;
5544c1
-    } else {
5544c1
-#if HOST_LONG_BITS == 64 && defined(__GNUC__)
5544c1
-        /* assuming 64-bit hosts have __uint128_t */
5544c1
-        __uint128_t dividend = (((__uint128_t)env->regs[r1]) << 64) |
5544c1
-            (env->regs[r1 + 1]);
5544c1
-        __uint128_t quotient = dividend / divisor;
5544c1
-        __uint128_t remainder = dividend % divisor;
5544c1
-
5544c1
-        env->regs[r1 + 1] = quotient;
5544c1
-        env->regs[r1] = remainder;
5544c1
-#else
5544c1
-        /* 32-bit hosts would need special wrapper functionality - just abort if
5544c1
-           we encounter such a case; it's very unlikely anyways. */
5544c1
-        cpu_abort(env, "128 -> 64/64 division not implemented\n");
5544c1
-#endif
5544c1
-    }
5544c1
-}
5544c1
-
5544c1
 static inline uint64_t get_address(int x2, int b2, int d2)
5544c1
 {
5544c1
     uint64_t r = d2;
5544c1
@@ -677,61 +634,6 @@ uint32_t HELPER(ex)(uint32_t cc, uint64_t v1, uint64_t addr, uint64_t ret)
5544c1
     return cc;
5544c1
 }
5544c1
 
5544c1
-/* absolute value 32-bit */
5544c1
-uint32_t HELPER(abs_i32)(int32_t val)
5544c1
-{
5544c1
-    if (val < 0) {
5544c1
-        return -val;
5544c1
-    } else {
5544c1
-        return val;
5544c1
-    }
5544c1
-}
5544c1
-
5544c1
-/* negative absolute value 32-bit */
5544c1
-int32_t HELPER(nabs_i32)(int32_t val)
5544c1
-{
5544c1
-    if (val < 0) {
5544c1
-        return val;
5544c1
-    } else {
5544c1
-        return -val;
5544c1
-    }
5544c1
-}
5544c1
-
5544c1
-/* absolute value 64-bit */
5544c1
-uint64_t HELPER(abs_i64)(int64_t val)
5544c1
-{
5544c1
-    HELPER_LOG("%s: val 0x%" PRIx64 "\n", __func__, val);
5544c1
-
5544c1
-    if (val < 0) {
5544c1
-        return -val;
5544c1
-    } else {
5544c1
-        return val;
5544c1
-    }
5544c1
-}
5544c1
-
5544c1
-/* negative absolute value 64-bit */
5544c1
-int64_t HELPER(nabs_i64)(int64_t val)
5544c1
-{
5544c1
-    if (val < 0) {
5544c1
-        return val;
5544c1
-    } else {
5544c1
-        return -val;
5544c1
-    }
5544c1
-}
5544c1
-
5544c1
-/* add with carry 32-bit unsigned */
5544c1
-uint32_t HELPER(addc_u32)(uint32_t cc, uint32_t v1, uint32_t v2)
5544c1
-{
5544c1
-    uint32_t res;
5544c1
-
5544c1
-    res = v1 + v2;
5544c1
-    if (cc & 2) {
5544c1
-        res++;
5544c1
-    }
5544c1
-
5544c1
-    return res;
5544c1
-}
5544c1
-
5544c1
 /* store character under mask high operates on the upper half of r1 */
5544c1
 void HELPER(stcmh)(uint32_t r1, uint64_t address, uint32_t mask)
5544c1
 {
5544c1
@@ -936,57 +838,6 @@ uint32_t HELPER(clcle)(uint32_t r1, uint64_t a2, uint32_t r3)
5544c1
     return cc;
5544c1
 }
5544c1
 
5544c1
-/* subtract unsigned v2 from v1 with borrow */
5544c1
-uint32_t HELPER(slb)(uint32_t cc, uint32_t r1, uint32_t v2)
5544c1
-{
5544c1
-    uint32_t v1 = env->regs[r1];
5544c1
-    uint32_t res = v1 + (~v2) + (cc >> 1);
5544c1
-
5544c1
-    env->regs[r1] = (env->regs[r1] & 0xffffffff00000000ULL) | res;
5544c1
-    if (cc & 2) {
5544c1
-        /* borrow */
5544c1
-        return v1 ? 1 : 0;
5544c1
-    } else {
5544c1
-        return v1 ? 3 : 2;
5544c1
-    }
5544c1
-}
5544c1
-
5544c1
-/* subtract unsigned v2 from v1 with borrow */
5544c1
-uint32_t HELPER(slbg)(uint32_t cc, uint32_t r1, uint64_t v1, uint64_t v2)
5544c1
-{
5544c1
-    uint64_t res = v1 + (~v2) + (cc >> 1);
5544c1
-
5544c1
-    env->regs[r1] = res;
5544c1
-    if (cc & 2) {
5544c1
-        /* borrow */
5544c1
-        return v1 ? 1 : 0;
5544c1
-    } else {
5544c1
-        return v1 ? 3 : 2;
5544c1
-    }
5544c1
-}
5544c1
-
5544c1
-/* find leftmost one */
5544c1
-uint32_t HELPER(flogr)(uint32_t r1, uint64_t v2)
5544c1
-{
5544c1
-    uint64_t res = 0;
5544c1
-    uint64_t ov2 = v2;
5544c1
-
5544c1
-    while (!(v2 & 0x8000000000000000ULL) && v2) {
5544c1
-        v2 <<= 1;
5544c1
-        res++;
5544c1
-    }
5544c1
-
5544c1
-    if (!v2) {
5544c1
-        env->regs[r1] = 64;
5544c1
-        env->regs[r1 + 1] = 0;
5544c1
-        return 0;
5544c1
-    } else {
5544c1
-        env->regs[r1] = res;
5544c1
-        env->regs[r1 + 1] = ov2 & ~(0x8000000000000000ULL >> res);
5544c1
-        return 2;
5544c1
-    }
5544c1
-}
5544c1
-
5544c1
 /* checksum */
5544c1
 void HELPER(cksm)(uint32_t r1, uint32_t r2)
5544c1
 {
5544c1
@@ -1026,27 +877,6 @@ void HELPER(cksm)(uint32_t r1, uint32_t r2)
5544c1
         ((uint32_t)cksm + (cksm >> 32));
5544c1
 }
5544c1
 
5544c1
-uint64_t HELPER(cvd)(int32_t bin)
5544c1
-{
5544c1
-    /* positive 0 */
5544c1
-    uint64_t dec = 0x0c;
5544c1
-    int shift = 4;
5544c1
-
5544c1
-    if (bin < 0) {
5544c1
-        bin = -bin;
5544c1
-        dec = 0x0d;
5544c1
-    }
5544c1
-
5544c1
-    for (shift = 4; (shift < 64) && bin; shift += 4) {
5544c1
-        int current_number = bin % 10;
5544c1
-
5544c1
-        dec |= (current_number) << shift;
5544c1
-        bin /= 10;
5544c1
-    }
5544c1
-
5544c1
-    return dec;
5544c1
-}
5544c1
-
5544c1
 void HELPER(unpk)(uint32_t len, uint64_t dest, uint64_t src)
5544c1
 {
5544c1
     int len_dest = len >> 4;
5544c1
-- 
5544c1
1.7.12.1
5544c1