From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9WnH-0006EA-Lj for qemu-devel@nongnu.org; Fri, 09 Jan 2015 05:27:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y9WnE-0006EP-CB for qemu-devel@nongnu.org; Fri, 09 Jan 2015 05:27:51 -0500 Received: from mail-we0-x236.google.com ([2a00:1450:400c:c03::236]:51904) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9WnE-0006E7-1f for qemu-devel@nongnu.org; Fri, 09 Jan 2015 05:27:48 -0500 Received: by mail-we0-f182.google.com with SMTP id w62so7148779wes.13 for ; Fri, 09 Jan 2015 02:27:47 -0800 (PST) From: Frediano Ziglio Date: Fri, 9 Jan 2015 10:27:33 +0000 Message-Id: <1420799253-21911-1-git-send-email-frediano.ziglio@huawei.com> Subject: [Qemu-devel] [PATCH] x86_64: optimise muldiv64 for x86_64 architecture List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , Anthony Liguori , Stefan Hajnoczi Cc: Frediano Ziglio , qemu-devel@nongnu.org As this platform can do multiply/divide using 128 bit precision use these instruction to implement it. Signed-off-by: Frediano Ziglio --- include/qemu-common.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/qemu-common.h b/include/qemu-common.h index f862214..5366220 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -370,6 +370,7 @@ static inline uint8_t from_bcd(uint8_t val) } /* compute with 96 bit intermediate result: (a*b)/c */ +#ifndef __x86_64__ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) { union { @@ -392,6 +393,18 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; return res.ll; } +#else +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; +} +#endif /* Round number down to multiple */ #define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m)) -- 1.9.1