From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9XzC-0003vz-Rh for qemu-devel@nongnu.org; Fri, 09 Jan 2015 06:44:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y9Xz9-0000PH-Kq for qemu-devel@nongnu.org; Fri, 09 Jan 2015 06:44:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33838) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9Xz9-0000P5-D7 for qemu-devel@nongnu.org; Fri, 09 Jan 2015 06:44:11 -0500 Message-ID: <54AFBEFB.6000204@redhat.com> Date: Fri, 09 Jan 2015 12:43:55 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1420802721-14457-1-git-send-email-frediano.ziglio@huawei.com> <1420802721-14457-2-git-send-email-frediano.ziglio@huawei.com> In-Reply-To: <1420802721-14457-2-git-send-email-frediano.ziglio@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/2] qemu-common.h: optimise muldiv64 for x86_64 architecture List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Frediano Ziglio , Anthony Liguori , Stefan Hajnoczi Cc: Frediano Ziglio , qemu-devel@nongnu.org On 09/01/2015 12:25, Frediano Ziglio wrote: > /* 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; > +} Reorder it the other way, and you can simplify the first #if. I applied patch 1 locally, and will send a pull request once the tree is thawed. Paolo