From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IoWOF-0001Yf-DK for qemu-devel@nongnu.org; Sat, 03 Nov 2007 23:43:11 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IoWOA-0001Sq-G8 for qemu-devel@nongnu.org; Sat, 03 Nov 2007 23:43:10 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IoWOA-0001Sh-BV for qemu-devel@nongnu.org; Sat, 03 Nov 2007 23:43:06 -0400 Received: from bangui.magic.fr ([195.154.194.245]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IoWO9-0005Wc-RE for qemu-devel@nongnu.org; Sat, 03 Nov 2007 23:43:06 -0400 Received: from [192.168.0.2] (ppp-36.net-123.static.magiconline.fr [80.118.184.36]) by bangui.magic.fr (8.13.1/8.13.1) with ESMTP id lA43h0Rl016350 for ; Sun, 4 Nov 2007 04:43:00 +0100 Subject: Re: [Qemu-devel] qemu exec-all.h host-utils.c host-utils.h targe... From: "J. Mayer" In-Reply-To: References: Content-Type: multipart/mixed; boundary="=-6Cbbirpj66Hr9jL/4WfC" Date: Sun, 04 Nov 2007 04:43:01 +0100 Message-Id: <1194147781.16781.584.camel@rapid> Mime-Version: 1.0 Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --=-6Cbbirpj66Hr9jL/4WfC Content-Type: text/plain Content-Transfer-Encoding: 7bit On Sun, 2007-11-04 at 02:24 +0000, Jocelyn Mayer wrote: > CVSROOT: /sources/qemu > Module name: qemu > Changes by: Jocelyn Mayer 07/11/04 02:24:58 > > Modified files: > . : exec-all.h host-utils.c host-utils.h > target-alpha : op.c > target-i386 : helper.c > > Log message: > For consistency, move muls64 / mulu64 prototypes to host-utils.h > Make x86_64 optimized versions inline. Following this patch, I also got optimized versions of muls64 / mulu64 / clz64 for PowerPC 64 and clz32 for PowerPC 32 hosts. Seems like it could be useful... -- J. Mayer Never organized --=-6Cbbirpj66Hr9jL/4WfC Content-Disposition: attachment; filename=host-utils.diff Content-Type: text/x-patch; name=host-utils.diff; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Index: host-utils.h =================================================================== RCS file: /sources/qemu/qemu/host-utils.h,v retrieving revision 1.3 diff -u -d -d -p -r1.3 host-utils.h --- host-utils.h 4 Nov 2007 02:24:57 -0000 1.3 +++ host-utils.h 4 Nov 2007 02:26:34 -0000 @@ -40,6 +40,25 @@ static always_inline void muls64 (uint64 : "=d" (*phigh), "=a" (*plow) : "a" (a), "0" (b)); } +#elif defined(__powerpc64__) +#define __HAVE_FAST_MULU64__ +static always_inline void mulu64 (uint64_t *plow, uint64_t *phigh, + uint64_t a, uint64_t b) +{ + __asm__ ("mulld %1, %2, %3 \n\t" + "mulhdu %0, %2, %3 \n\t" + : "=r"(*phigh), "=r"(*plow) + : "r"(a), "r"(b)); +} +#define __HAVE_FAST_MULS64__ +static always_inline void muls64 (uint64_t *plow, uint64_t *phigh, + uint64_t a, uint64_t b) +{ + __asm__ ("mulld %1, %2, %3 \n\t" + "mulhd %0, %2, %3 \n\t" + : "=r"(*phigh), "=r"(*plow) + : "r"(a), "r"(b)); +} #else void muls64(int64_t *phigh, int64_t *plow, int64_t a, int64_t b); void mulu64(uint64_t *phigh, uint64_t *plow, uint64_t a, uint64_t b); @@ -50,7 +69,19 @@ void mulu64(uint64_t *phigh, uint64_t *p cope with that. */ /* Binary search for leading zeros. */ +#if defined(__powerpc__) +#define __HAVE_FAST_CLZ32__ +static always_inline int clz32 (uint32_t val) +{ + int cnt; + + __asm__ ("cntlzw %0, %1 \n\t" + : "=r"(cnt) + : "r"(val)); + return cnt; +} +#else static always_inline int clz32(uint32_t val) { int cnt = 0; @@ -80,12 +111,26 @@ static always_inline int clz32(uint32_t } return cnt; } +#endif static always_inline int clo32(uint32_t val) { return clz32(~val); } +#if defined(__powerpc64__) +#define __HAVE_FAST_CLZ64__ +static always_inline int clz64 (uint32_t val) +{ + int cnt; + + __asm__ ("cntlzd %0, %1 \n\t" + : "=r"(cnt) + : "r"(val)); + + return cnt; +} +#else static always_inline int clz64(uint64_t val) { int cnt = 0; @@ -98,6 +143,7 @@ static always_inline int clz64(uint64_t return cnt + clz32(val); } +#endif static always_inline int clo64(uint64_t val) { --=-6Cbbirpj66Hr9jL/4WfC--