From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [5464] Optimize some host-utils function with gcc builtins
Date: Sun, 12 Oct 2008 00:53:08 +0000 [thread overview]
Message-ID: <E1KopCm-0001WI-Te@cvs.savannah.gnu.org> (raw)
Revision: 5464
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5464
Author: aurel32
Date: 2008-10-12 00:53:08 +0000 (Sun, 12 Oct 2008)
Log Message:
-----------
Optimize some host-utils function with gcc builtins
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Modified Paths:
--------------
trunk/host-utils.h
Modified: trunk/host-utils.h
===================================================================
--- trunk/host-utils.h 2008-10-12 00:52:58 UTC (rev 5463)
+++ trunk/host-utils.h 2008-10-12 00:53:08 UTC (rev 5464)
@@ -47,14 +47,16 @@
void mulu64(uint64_t *phigh, uint64_t *plow, uint64_t a, uint64_t b);
#endif
-/* Note that some of those functions may end up calling libgcc functions,
- depending on the host machine. It is up to the target emulation to
- cope with that. */
-
/* Binary search for leading zeros. */
static always_inline int clz32(uint32_t val)
{
+#if defined(__GNUC__)
+ if (val)
+ return __builtin_clz(val);
+ else
+ return 32;
+#else
int cnt = 0;
if (!(val & 0xFFFF0000U)) {
@@ -81,6 +83,7 @@
cnt++;
}
return cnt;
+#endif
}
static always_inline int clo32(uint32_t val)
@@ -90,6 +93,12 @@
static always_inline int clz64(uint64_t val)
{
+#if defined(__GNUC__)
+ if (val)
+ return __builtin_clzll(val);
+ else
+ return 64;
+#else
int cnt = 0;
if (!(val >> 32)) {
@@ -99,6 +108,7 @@
}
return cnt + clz32(val);
+#endif
}
static always_inline int clo64(uint64_t val)
@@ -108,6 +118,12 @@
static always_inline int ctz32 (uint32_t val)
{
+#if defined(__GNUC__)
+ if (val)
+ return __builtin_ctz(val);
+ else
+ return 32;
+#else
int cnt;
cnt = 0;
@@ -136,6 +152,7 @@
}
return cnt;
+#endif
}
static always_inline int cto32 (uint32_t val)
@@ -145,6 +162,12 @@
static always_inline int ctz64 (uint64_t val)
{
+#if defined(__GNUC__)
+ if (val)
+ return __builtin_ctz(val);
+ else
+ return 64;
+#else
int cnt;
cnt = 0;
@@ -154,6 +177,7 @@
}
return cnt + ctz32(val);
+#endif
}
static always_inline int cto64 (uint64_t val)
@@ -182,6 +206,9 @@
static always_inline int ctpop32 (uint32_t val)
{
+#if defined(__GNUC__)
+ return __builtin_popcount(val);
+#else
val = (val & 0x55555555) + ((val >> 1) & 0x55555555);
val = (val & 0x33333333) + ((val >> 2) & 0x33333333);
val = (val & 0x0f0f0f0f) + ((val >> 4) & 0x0f0f0f0f);
@@ -189,10 +216,14 @@
val = (val & 0x0000ffff) + ((val >> 16) & 0x0000ffff);
return val;
+#endif
}
static always_inline int ctpop64 (uint64_t val)
{
+#if defined(__GNUC__)
+ return __builtin_popcountll(val);
+#else
val = (val & 0x5555555555555555ULL) + ((val >> 1) & 0x5555555555555555ULL);
val = (val & 0x3333333333333333ULL) + ((val >> 2) & 0x3333333333333333ULL);
val = (val & 0x0f0f0f0f0f0f0f0fULL) + ((val >> 4) & 0x0f0f0f0f0f0f0f0fULL);
@@ -201,4 +232,5 @@
val = (val & 0x00000000ffffffffULL) + ((val >> 32) & 0x00000000ffffffffULL);
return val;
+#endif
}
reply other threads:[~2008-10-12 0:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1KopCm-0001WI-Te@cvs.savannah.gnu.org \
--to=aurelien@aurel32.net \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).