summaryrefslogtreecommitdiffstats
path: root/dexdump
diff options
context:
space:
mode:
authorCosmin Cojocar <cosmin.cojocar@gmail.com>2010-04-18 18:25:06 +0200
committerCosmin Cojocar <cosmin.cojocar@gmail.com>2010-04-20 22:13:26 +0200
commite339343c9c698a887681771372ba6cc58a79c707 (patch)
tree237302fed1f7a04f82776488cb922b66b55d2d56 /dexdump
parentb16b78db118036d7df2cf5705baa18f34bd42eec (diff)
downloadandroid_dalvik-e339343c9c698a887681771372ba6cc58a79c707.tar.gz
android_dalvik-e339343c9c698a887681771372ba6cc58a79c707.tar.bz2
android_dalvik-e339343c9c698a887681771372ba6cc58a79c707.zip
Improve the implementation of countOnes function to use only 12 operations.
Change-Id: I01b62606a0c87b2937572f8cb7beafc956867353
Diffstat (limited to 'dexdump')
-rw-r--r--dexdump/DexDump.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/dexdump/DexDump.c b/dexdump/DexDump.c
index 6fed7aaf4..ccb6e0afc 100644
--- a/dexdump/DexDump.c
+++ b/dexdump/DexDump.c
@@ -225,20 +225,14 @@ static const char* quotedVisibility(u4 accessFlags)
/*
* Count the number of '1' bits in a word.
- *
- * Having completed this, I'm ready for an interview at Google.
- *
- * TODO? there's a parallel version w/o loops. Performance not currently
- * important.
*/
static int countOnes(u4 val)
{
int count = 0;
- while (val != 0) {
- val &= val-1;
- count++;
- }
+ val = val - ((val >> 1) & 0x55555555);
+ val = (val & 0x33333333) + ((val >> 2) & 0x33333333);
+ count = (((val + (val >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
return count;
}