From patchwork Sat Feb 16 20:46:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 221032 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4380E2C008C for ; Sun, 17 Feb 2013 07:47:33 +1100 (EST) Received: from localhost ([::1]:48551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6ofT-00069F-CU for incoming@patchwork.ozlabs.org; Sat, 16 Feb 2013 15:47:31 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6of9-00060f-RT for qemu-devel@nongnu.org; Sat, 16 Feb 2013 15:47:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U6of6-00083P-RB for qemu-devel@nongnu.org; Sat, 16 Feb 2013 15:47:11 -0500 Received: from mail-pb0-f46.google.com ([209.85.160.46]:62874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6of6-00083K-LG for qemu-devel@nongnu.org; Sat, 16 Feb 2013 15:47:08 -0500 Received: by mail-pb0-f46.google.com with SMTP id uo15so1071024pbc.19 for ; Sat, 16 Feb 2013 12:47:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=1SdordtqIJo2CyoS8Fnon6YOeAq44CCR2c/rPDNWfhg=; b=B4XJSY05/liWX/fqy0eOeOGKF5PAWyW1rixr9E1J/Ow1+stEfyrGgIoSLD4FvCLAtN br2aYPaTiI+MucWhE760TJT8ETgfQjzt629Ft/CFYz2hfDl5rQDglzV7EJ/rn3uhbDdx HgbxxxcUwAagbs5TJ8I/l511L3QFnIezxlX8SFgXkeuzTO/Eh7pDIM5ivfPI9zkRNd5v h+zqT7cYDx5vuoyxwM/KRCm3ASegPX8Oq+VKP3h7fTgj5uth/28tMLTPHjltcuv8TYdV cU94mSD/VRkIj0AQZYwxB+HZOloK74W453apdoWdIczzsdPjNnB8ta6rIm+T70GWfKQy c1Qg== X-Received: by 10.68.191.106 with SMTP id gx10mr17065323pbc.151.1361047627861; Sat, 16 Feb 2013 12:47:07 -0800 (PST) Received: from anchor.twiddle.net (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPS id kc15sm8961940pbb.5.2013.02.16.12.47.06 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 16 Feb 2013 12:47:06 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 16 Feb 2013 12:46:59 -0800 Message-Id: <1361047621-27480-2-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1361047621-27480-1-git-send-email-rth@twiddle.net> References: <1361047621-27480-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.46 Cc: blauwirbel@gmail.com Subject: [Qemu-devel] [PATCH 1/3] host-utils: Use __int128_t for mul[us]64 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 Replace some x86_64 specific inline assembly with something that all 64-bit hosts ought to optimize well. At worst this becomes a call to the gcc __multi3 routine, which is no worse than our implementation in util/host-utils.c. With gcc 4.7, we get identical code generation for x86_64. We now get native multiplication on ia64 and s390x hosts. With minor improvements to gcc we can get it for ppc64 as well. Signed-off-by: Richard Henderson --- configure | 20 ++++++++++++++++++++ include/qemu/host-utils.h | 17 ++++++++--------- util/host-utils.c | 4 ++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/configure b/configure index 8789324..bf5970f 100755 --- a/configure +++ b/configure @@ -3150,6 +3150,22 @@ if compile_prog "" "" ; then cpuid_h=yes fi +######################################## +# check if __[u]int128_t is usable. + +int128=no +cat > $TMPC << EOF +__int128_t a; +__uint128_t b; +int main (void) { + a = a + b; + b = a * b; + return 0; +} +EOF +if compile_prog "" "" ; then + int128=yes +fi ########################################## # End of CC checks @@ -3692,6 +3708,10 @@ if test "$cpuid_h" = "yes" ; then echo "CONFIG_CPUID_H=y" >> $config_host_mak fi +if test "$int128" = "yes" ; then + echo "CONFIG_INT128=y" >> $config_host_mak +fi + if test "$glusterfs" = "yes" ; then echo "CONFIG_GLUSTERFS=y" >> $config_host_mak fi diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index f0dd850..0f688c1 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -28,22 +28,21 @@ #include "qemu/compiler.h" /* QEMU_GNUC_PREREQ */ #include -#if defined(__x86_64__) -#define __HAVE_FAST_MULU64__ +#ifdef CONFIG_INT128 static inline void mulu64(uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b) { - __asm__ ("mul %0\n\t" - : "=d" (*phigh), "=a" (*plow) - : "a" (a), "0" (b)); + __uint128_t r = (__uint128_t)a * b; + *plow = r; + *phigh = r >> 64; } -#define __HAVE_FAST_MULS64__ + static inline void muls64(uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b) { - __asm__ ("imul %0\n\t" - : "=d" (*phigh), "=a" (*plow) - : "a" (a), "0" (b)); + __int128_t r = (__int128_t)a * b; + *plow = r; + *phigh = r >> 64; } #else void muls64(uint64_t *phigh, uint64_t *plow, int64_t a, int64_t b); diff --git a/util/host-utils.c b/util/host-utils.c index 5e3915a..2d06a2c 100644 --- a/util/host-utils.c +++ b/util/host-utils.c @@ -30,7 +30,7 @@ //#define DEBUG_MULDIV /* Long integer helpers */ -#if !defined(__x86_64__) +#ifndef CONFIG_INT128 static void add128 (uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b) { *plow += a; @@ -102,4 +102,4 @@ void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b) a, b, *phigh, *plow); #endif } -#endif /* !defined(__x86_64__) */ +#endif /* !CONFIG_INT128 */