aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-05-16 11:59:40 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-05-16 11:59:40 +0000
commit69d357286d0ab5a852e827dad1dc4b05917aaaa8 (patch)
treedbf5fae9642821155fdb93539c266e7c5dc12406
parent100ce98812c2624a7e7922055d80ebbd81e8caa9 (diff)
More generic 64 bit multiplication support, by Aurelien Jarno.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2821 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--Makefile.target1
-rw-r--r--exec-all.h3
-rw-r--r--host-utils.c75
-rw-r--r--target-i386/helper.c50
-rw-r--r--target-mips/exec.h2
-rw-r--r--target-mips/op.c4
-rw-r--r--target-mips/op_helper.c14
7 files changed, 84 insertions, 65 deletions
diff --git a/Makefile.target b/Makefile.target
index aa99f39cd1..1e573f44b5 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -365,6 +365,7 @@ endif
# must use static linking to avoid leaving stuff in virtual address space
VL_OBJS=vl.o osdep.o readline.o monitor.o pci.o console.o loader.o isa_mmio.o
VL_OBJS+=cutils.o
+VL_OBJS+=host-utils.o
VL_OBJS+=block.o block-raw.o
VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o block-bochs.o block-vpc.o block-vvfat.o block-qcow2.o
VL_OBJS+=irq.o
diff --git a/exec-all.h b/exec-all.h
index 863ca3bdb3..2b9376930f 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -78,6 +78,9 @@ void optimize_flags_init(void);
extern FILE *logfile;
extern int loglevel;
+void muls64(int64_t *phigh, int64_t *plow, int64_t a, int64_t b);
+void mulu64(uint64_t *phigh, uint64_t *plow, uint64_t a, uint64_t b);
+
int gen_intermediate_code(CPUState *env, struct TranslationBlock *tb);
int gen_intermediate_code_pc(CPUState *env, struct TranslationBlock *tb);
void dump_ops(const uint16_t *opc_buf, const uint32_t *opparam_buf);
diff --git a/host-utils.c b/host-utils.c
new file mode 100644
index 0000000000..10341063f1
--- /dev/null
+++ b/host-utils.c
@@ -0,0 +1,75 @@
+/*
+ * Utility compute operations used by translated code.
+ *
+ * Copyright (c) 2007 Aurelien Jarno
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "vl.h"
+
+/* Signed 64x64 -> 128 multiplication */
+
+void muls64(int64_t *phigh, int64_t *plow, int64_t a, int64_t b)
+{
+#if defined(__x86_64__)
+ __asm__ ("imul %0\n\t"
+ : "=d" (*phigh), "=a" (*plow)
+ : "a" (a), "0" (b)
+ );
+#else
+ int64_t ph;
+ uint64_t pm1, pm2, pl;
+
+ pl = (uint64_t)((uint32_t)a) * (uint64_t)((uint32_t)b);
+ pm1 = (a >> 32) * (uint32_t)b;
+ pm2 = (uint32_t)a * (b >> 32);
+ ph = (a >> 32) * (b >> 32);
+
+ ph += (int64_t)pm1 >> 32;
+ pm1 = (uint64_t)((uint32_t)pm1) + pm2 + (pl >> 32);
+
+ *phigh = ph + ((int64_t)pm1 >> 32);
+ *plow = (pm1 << 32) + (uint32_t)pl;
+#endif
+}
+
+/* Unsigned 64x64 -> 128 multiplication */
+void mulu64(uint64_t *phigh, uint64_t *plow, uint64_t a, uint64_t b)
+{
+#if defined(__x86_64__)
+ __asm__ ("mul %0\n\t"
+ : "=d" (*phigh), "=a" (*plow)
+ : "a" (a), "0" (b)
+ );
+#else
+ uint64_t ph, pm1, pm2, pl;
+
+ pl = (uint64_t)((uint32_t)a) * (uint64_t)((uint32_t)b);
+ pm1 = (a >> 32) * (uint32_t)b;
+ pm2 = (uint32_t)a * (b >> 32);
+ ph = (a >> 32) * (b >> 32);
+
+ ph += pm1 >> 32;
+ pm1 = (uint64_t)((uint32_t)pm1) + pm2 + (pl >> 32);
+
+ *phigh = ph + (pm1 >> 32);
+ *plow = (pm1 << 32) + (uint32_t)pl;
+#endif
+}
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 4656596eb1..20c1f57620 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -3620,50 +3620,6 @@ static void neg128(uint64_t *plow, uint64_t *phigh)
add128(plow, phigh, 1, 0);
}
-static void mul64(uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
-{
- uint32_t a0, a1, b0, b1;
- uint64_t v;
-
- a0 = a;
- a1 = a >> 32;
-
- b0 = b;
- b1 = b >> 32;
-
- v = (uint64_t)a0 * (uint64_t)b0;
- *plow = v;
- *phigh = 0;
-
- v = (uint64_t)a0 * (uint64_t)b1;
- add128(plow, phigh, v << 32, v >> 32);
-
- v = (uint64_t)a1 * (uint64_t)b0;
- add128(plow, phigh, v << 32, v >> 32);
-
- v = (uint64_t)a1 * (uint64_t)b1;
- *phigh += v;
-#ifdef DEBUG_MULDIV
- printf("mul: 0x%016" PRIx64 " * 0x%016" PRIx64 " = 0x%016" PRIx64 "%016" PRIx64 "\n",
- a, b, *phigh, *plow);
-#endif
-}
-
-static void imul64(uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b)
-{
- int sa, sb;
- sa = (a < 0);
- if (sa)
- a = -a;
- sb = (b < 0);
- if (sb)
- b = -b;
- mul64(plow, phigh, a, b);
- if (sa ^ sb) {
- neg128(plow, phigh);
- }
-}
-
/* return TRUE if overflow */
static int div64(uint64_t *plow, uint64_t *phigh, uint64_t b)
{
@@ -3731,7 +3687,7 @@ void helper_mulq_EAX_T0(void)
{
uint64_t r0, r1;
- mul64(&r0, &r1, EAX, T0);
+ mulu64(&r1, &r0, EAX, T0);
EAX = r0;
EDX = r1;
CC_DST = r0;
@@ -3742,7 +3698,7 @@ void helper_imulq_EAX_T0(void)
{
uint64_t r0, r1;
- imul64(&r0, &r1, EAX, T0);
+ muls64(&r1, &r0, EAX, T0);
EAX = r0;
EDX = r1;
CC_DST = r0;
@@ -3753,7 +3709,7 @@ void helper_imulq_T0_T1(void)
{
uint64_t r0, r1;
- imul64(&r0, &r1, T0, T1);
+ muls64(&r1, &r0, T0, T1);
T0 = r0;
CC_DST = r0;
CC_SRC = ((int64_t)r1 != ((int64_t)r0 >> 63));
diff --git a/target-mips/exec.h b/target-mips/exec.h
index 44314a98b3..e82b71651b 100644
--- a/target-mips/exec.h
+++ b/target-mips/exec.h
@@ -97,8 +97,6 @@ void do_ddiv (void);
#if TARGET_LONG_BITS > HOST_LONG_BITS
void do_ddivu (void);
#endif
-void do_dmult (void);
-void do_dmultu (void);
#endif
void do_mfc0_random(void);
void do_mfc0_count(void);
diff --git a/target-mips/op.c b/target-mips/op.c
index ddc3cdea59..1188e82846 100644
--- a/target-mips/op.c
+++ b/target-mips/op.c
@@ -874,13 +874,13 @@ void op_msubu (void)
#ifdef TARGET_MIPS64
void op_dmult (void)
{
- CALL_FROM_TB0(do_dmult);
+ CALL_FROM_TB4(muls64, &(env->HI), &(env->LO), T0, T1);
RETURN();
}
void op_dmultu (void)
{
- CALL_FROM_TB0(do_dmultu);
+ CALL_FROM_TB4(mulu64, &(env->HI), &(env->LO), T0, T1);
RETURN();
}
#endif
diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c
index 2dd0f887b0..9cc55dcef8 100644
--- a/target-mips/op_helper.c
+++ b/target-mips/op_helper.c
@@ -228,20 +228,6 @@ void do_div (void)
#endif
#ifdef TARGET_MIPS64
-void do_dmult (void)
-{
- env->LO = (int64_t)T0 * (int64_t)T1;
- /* XXX */
- env->HI = (env->LO | (1ULL << 63)) ? ~0ULL : 0ULL;
-}
-
-void do_dmultu (void)
-{
- env->LO = T0 * T1;
- /* XXX */
- env->HI = 0;
-}
-
void do_ddiv (void)
{
if (T1 != 0) {