From patchwork Fri Jan 9 11:25:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 427045 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48098140182 for ; Fri, 9 Jan 2015 22:26:17 +1100 (AEDT) Received: from localhost ([::1]:50101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9Xhn-0005ei-GJ for incoming@patchwork.ozlabs.org; Fri, 09 Jan 2015 06:26:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9Xh9-0004sW-DT for qemu-devel@nongnu.org; Fri, 09 Jan 2015 06:25:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y9Xh8-0002aM-2u for qemu-devel@nongnu.org; Fri, 09 Jan 2015 06:25:35 -0500 Received: from mail-wg0-x235.google.com ([2a00:1450:400c:c00::235]:46246) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9Xh7-0002a2-FE for qemu-devel@nongnu.org; Fri, 09 Jan 2015 06:25:33 -0500 Received: by mail-wg0-f53.google.com with SMTP id x13so7558273wgg.12 for ; Fri, 09 Jan 2015 03:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=K7hE3yU4biXZ1//XpJvk/TSx3b5PV5Te+rC9e8MrbJE=; b=qALqU75GHO6auicVfWZqSjCzgwb4i5G5g/bRZZywYGqmenBJzAf7XDKnoNrwD2YsTI WtjHYtSqoDYkNKOTft0a9n+v2EZPnUUsn7/c1PbpbhQEHNl6i320uM8AHpnvWQCJHe3S 7LEP/efRZhgZLgFIHyGtLLj6XE28RsJEU1e8v9F542OoGm5/doMzyVKEfOrc0h7fK6yc POYe2mNVKDSrQSDy5SX6cQc0eK7YZHAouuZTR4zJij0VTLZncJQmL8weV2DYotrk16wl FSDXNG7KDOUBaQph6QiHeVpeAr9BAD/rUXYLtikShCUyumk//3wqYodC+fIUtGYfC73L snHw== X-Received: by 10.180.103.33 with SMTP id ft1mr4088380wib.19.1420802732896; Fri, 09 Jan 2015 03:25:32 -0800 (PST) Received: from localhost.localdomain ([90.152.119.35]) by mx.google.com with ESMTPSA id hz9sm9650753wjb.17.2015.01.09.03.25.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Jan 2015 03:25:32 -0800 (PST) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: Paolo Bonzini , Anthony Liguori , Stefan Hajnoczi Date: Fri, 9 Jan 2015 11:25:21 +0000 Message-Id: <1420802721-14457-2-git-send-email-frediano.ziglio@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1420802721-14457-1-git-send-email-frediano.ziglio@huawei.com> References: <1420802721-14457-1-git-send-email-frediano.ziglio@huawei.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::235 Cc: Frediano Ziglio , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 2/2] qemu-common.h: optimise muldiv64 for x86_64 architecture X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org As this platform can do multiply/divide using 128 bit precision use these instructions to implement it. Signed-off-by: Frediano Ziglio --- 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) {