All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [5464] Optimize some host-utils function with gcc builtins
@ 2008-10-12  0:53 Aurelien Jarno
  0 siblings, 0 replies; only message in thread
From: Aurelien Jarno @ 2008-10-12  0:53 UTC (permalink / raw)
  To: qemu-devel

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
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-10-12  0:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-12  0:53 [Qemu-devel] [5464] Optimize some host-utils function with gcc builtins Aurelien Jarno

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.