diff options
author | Jim Huang <jserv@0xlab.org> | 2011-09-18 07:37:25 +0800 |
---|---|---|
committer | Jim Huang <jserv@0xlab.org> | 2011-09-18 10:35:22 +0800 |
commit | 1cd3559178c691e4f6cea4be85de918afabb033c (patch) | |
tree | c22fb30923779dd3177780f7e30a6e637e03ee67 | |
parent | 69d762d81468aec1b97b39498d0a5e83b05ff44b (diff) | |
download | bionic-1cd3559178c691e4f6cea4be85de918afabb033c.zip bionic-1cd3559178c691e4f6cea4be85de918afabb033c.tar.gz bionic-1cd3559178c691e4f6cea4be85de918afabb033c.tar.bz2 |
dlmalloc: Use more efficient ARMv7 implementation for macro compute_bit2idx
The macro compute_bit2idx(X, I) was definied as "I = ffs(X)-1". This
equals to the operation __builtin_ctz(X), and using the new bit-reversal
instruction would have been better for ARMv7:
rbit r0, r0
clz r0, r0
This patch re-implements macro compute_bit2idx by using the above ARMv7
specific instructions to be more efficient.
Reference: http://hardwarebug.org/2010/01/14/beware-the-builtins/
Change-Id: I7cd49da327329c5d75e5e75a557fd115a0c7c0e2
-rw-r--r-- | libc/bionic/dlmalloc.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libc/bionic/dlmalloc.c b/libc/bionic/dlmalloc.c index 559ccaf..d30ec30 100644 --- a/libc/bionic/dlmalloc.c +++ b/libc/bionic/dlmalloc.c @@ -467,6 +467,9 @@ DEFAULT_MMAP_THRESHOLD default: 256K #ifdef ANDROID #define USE_BUILTIN_FFS 1 +#ifdef __arm__ +#include <machine/cpu-features.h> +#endif #endif /* ANDROID */ #ifndef WIN32 @@ -2398,6 +2401,17 @@ static size_t traverse_and_check(mstate m); } #else /* GNUC */ +#if defined(__ARM_ARCH__) && __ARM_ARCH__ >= 7 +#define compute_bit2idx(X, I) \ +{ \ + unsigned int J; \ + __asm__ ("rbit %0, %1\n" \ + "clz %0, %0" \ + : "=r" (J) : "r" (X)); \ + I = (bindex_t) J; \ +} + +#else /* ARM_ARCH */ #if USE_BUILTIN_FFS #define compute_bit2idx(X, I) I = ffs(X)-1 @@ -2413,6 +2427,7 @@ static size_t traverse_and_check(mstate m); N += K = Y >> (1-0) & 1; Y >>= K;\ I = (bindex_t)(N + Y);\ } +#endif /* ARM_ARCH */ #endif /* USE_BUILTIN_FFS */ #endif /* GNUC */ |