qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [5592] target-ppc: optimize popcntb
@ 2008-11-01  0:54 Aurelien Jarno
  2008-11-01 12:29 ` Laurent Desnogues
  0 siblings, 1 reply; 5+ messages in thread
From: Aurelien Jarno @ 2008-11-01  0:54 UTC (permalink / raw)
  To: qemu-devel

Revision: 5592
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5592
Author:   aurel32
Date:     2008-11-01 00:54:33 +0000 (Sat, 01 Nov 2008)

Log Message:
-----------
target-ppc: optimize popcntb

Suggested by Andrzej Zaborowski.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

Modified Paths:
--------------
    trunk/target-ppc/op_helper.c

Modified: trunk/target-ppc/op_helper.c
===================================================================
--- trunk/target-ppc/op_helper.c	2008-11-01 00:54:23 UTC (rev 5591)
+++ trunk/target-ppc/op_helper.c	2008-11-01 00:54:33 UTC (rev 5592)
@@ -222,25 +222,19 @@
 
 target_ulong helper_popcntb (target_ulong val)
 {
-    uint32_t ret;
-    int i;
-
-    ret = 0;
-    for (i = 0; i < 32; i += 8)
-        ret |= ctpop8((val >> i) & 0xFF) << i;
-    return ret;
+    val = (val & 0x55555555) + ((val >>  1) & 0x55555555);
+    val = (val & 0x33333333) + ((val >>  2) & 0x33333333);
+    val = (val & 0x0f0f0f0f) + ((val >>  4) & 0x0f0f0f0f);
+    return val;
 }
 
 #if defined(TARGET_PPC64)
 target_ulong helper_popcntb_64 (target_ulong val)
 {
-    uint64_t ret;
-    int i;
-
-    ret = 0;
-    for (i = 0; i < 64; i += 8)
-        ret |= ctpop8((val >> i) & 0xFF) << i;
-    return ret;
+    val = (val & 0x5555555555555555ULL) + ((val >>  1) & 0x5555555555555555ULL);
+    val = (val & 0x3333333333333333ULL) + ((val >>  2) & 0x3333333333333333ULL);
+    val = (val & 0x0f0f0f0f0f0f0f0fULL) + ((val >>  4) & 0x0f0f0f0f0f0f0f0fULL);
+    return val;
 }
 #endif
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-01 14:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-01  0:54 [Qemu-devel] [5592] target-ppc: optimize popcntb Aurelien Jarno
2008-11-01 12:29 ` Laurent Desnogues
2008-11-01 12:35   ` Laurent Desnogues
2008-11-01 13:57     ` andrzej zaborowski
2008-11-01 14:34       ` Laurent Desnogues

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).