aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162>2008-11-01 00:54:33 +0000
committeraurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162>2008-11-01 00:54:33 +0000
commit6176a26d1d0fe40dea0fd6a4e1a437931cbdcb2d (patch)
tree333a8cce25a64f84d601f40dafbe03172467b130
parent182608d44cc64bfec3f82e7895b7572db60b7c92 (diff)
target-ppc: optimize popcntb
Suggested by Andrzej Zaborowski. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5592 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--target-ppc/op_helper.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/target-ppc/op_helper.c b/target-ppc/op_helper.c
index ef1035fc56..b1a88b5271 100644
--- a/target-ppc/op_helper.c
+++ b/target-ppc/op_helper.c
@@ -222,25 +222,19 @@ target_ulong helper_srad (target_ulong value, target_ulong shift)
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