[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/2] qemu-common.h: optimise muldiv64 for x86_64 arc
From: |
Frediano Ziglio |
Subject: |
[Qemu-devel] [PATCH 2/2] qemu-common.h: optimise muldiv64 for x86_64 architecture |
Date: |
Fri, 9 Jan 2015 11:25:21 +0000 |
As this platform can do multiply/divide using 128 bit precision use
these instructions to implement it.
Signed-off-by: Frediano Ziglio <address@hidden>
---
include/qemu-common.h | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/include/qemu-common.h b/include/qemu-common.h
index f3033ae..880659d 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -370,11 +370,23 @@ static inline uint8_t from_bcd(uint8_t val)
}
/* compute with 96 bit intermediate result: (a*b)/c */
-#ifdef CONFIG_INT128
+#if defined(CONFIG_INT128) && !defined(__x86_64__)
static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
{
return (__int128)a * b / c;
}
+#elif defined(__x86_64__)
+/* Optimised x64 version. This assume that a*b/c fits in 64 bit */
+static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
+{
+ uint64_t res;
+
+ asm ("mulq %2\n\tdivq %3"
+ : "=a"(res)
+ : "a"(a), "qm"((uint64_t) b), "qm"((uint64_t)c)
+ : "rdx", "cc");
+ return res;
+}
#else
static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
{
--
1.9.1
Re: [Qemu-devel] [PATCH 1/2] qemu-common.h: optimise muldiv64 if int128 is available, Peter Maydell, 2015/01/09