diff options
author | Richard Henderson <rth@twiddle.net> | 2016-11-21 12:30:34 +0100 |
---|---|---|
committer | Richard Henderson <rth@twiddle.net> | 2017-01-10 08:49:59 -0800 |
commit | 7bdcecb7b2d79c292d1256f7d6cf0f1da50d381f (patch) | |
tree | c3399317fdae1f11a468511ffd660ba7af42d161 /include | |
parent | 4885c3c49531995d67e54907d01d5aa1350faaaf (diff) |
qemu/host-utils.h: Reduce the operation count in the fallback ctpop
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
Diffstat (limited to 'include')
-rw-r--r-- | include/qemu/host-utils.h | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index 46187bbc7e..96288d0bce 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -327,7 +327,7 @@ static inline int ctpop8(uint8_t val) #else val = (val & 0x55) + ((val >> 1) & 0x55); val = (val & 0x33) + ((val >> 2) & 0x33); - val = (val & 0x0f) + ((val >> 4) & 0x0f); + val = (val + (val >> 4)) & 0x0f; return val; #endif @@ -344,8 +344,8 @@ static inline int ctpop16(uint16_t val) #else val = (val & 0x5555) + ((val >> 1) & 0x5555); val = (val & 0x3333) + ((val >> 2) & 0x3333); - val = (val & 0x0f0f) + ((val >> 4) & 0x0f0f); - val = (val & 0x00ff) + ((val >> 8) & 0x00ff); + val = (val + (val >> 4)) & 0x0f0f; + val = (val + (val >> 8)) & 0x00ff; return val; #endif @@ -360,11 +360,10 @@ static inline int ctpop32(uint32_t val) #if QEMU_GNUC_PREREQ(3, 4) return __builtin_popcount(val); #else - val = (val & 0x55555555) + ((val >> 1) & 0x55555555); - val = (val & 0x33333333) + ((val >> 2) & 0x33333333); - val = (val & 0x0f0f0f0f) + ((val >> 4) & 0x0f0f0f0f); - val = (val & 0x00ff00ff) + ((val >> 8) & 0x00ff00ff); - val = (val & 0x0000ffff) + ((val >> 16) & 0x0000ffff); + val = (val & 0x55555555) + ((val >> 1) & 0x55555555); + val = (val & 0x33333333) + ((val >> 2) & 0x33333333); + val = (val + (val >> 4)) & 0x0f0f0f0f; + val = (val * 0x01010101) >> 24; return val; #endif @@ -379,12 +378,10 @@ static inline int ctpop64(uint64_t val) #if QEMU_GNUC_PREREQ(3, 4) return __builtin_popcountll(val); #else - val = (val & 0x5555555555555555ULL) + ((val >> 1) & 0x5555555555555555ULL); - val = (val & 0x3333333333333333ULL) + ((val >> 2) & 0x3333333333333333ULL); - val = (val & 0x0f0f0f0f0f0f0f0fULL) + ((val >> 4) & 0x0f0f0f0f0f0f0f0fULL); - val = (val & 0x00ff00ff00ff00ffULL) + ((val >> 8) & 0x00ff00ff00ff00ffULL); - val = (val & 0x0000ffff0000ffffULL) + ((val >> 16) & 0x0000ffff0000ffffULL); - val = (val & 0x00000000ffffffffULL) + ((val >> 32) & 0x00000000ffffffffULL); + val = (val & 0x5555555555555555ULL) + ((val >> 1) & 0x5555555555555555ULL); + val = (val & 0x3333333333333333ULL) + ((val >> 2) & 0x3333333333333333ULL); + val = (val + (val >> 4)) & 0x0f0f0f0f0f0f0f0fULL; + val = (val * 0x0101010101010101ULL) >> 56; return val; #endif |