summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Henderson2016-11-21 12:06:26 +0100
committerRichard Henderson2017-01-10 17:48:57 +0100
commit250a87d5561a7212fe43357b084f69992eced75a (patch)
treebdcddaa4f0827557266d48049b943b7c29146f07
parenttarget-ppc: Use ctpop helper (diff)
downloadqemu-250a87d5561a7212fe43357b084f69992eced75a.tar.gz
qemu-250a87d5561a7212fe43357b084f69992eced75a.tar.xz
qemu-250a87d5561a7212fe43357b084f69992eced75a.zip
target-s390x: Avoid a loop for popcnt
Signed-off-by: Richard Henderson <rth@twiddle.net>
-rw-r--r--target/s390x/int_helper.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/target/s390x/int_helper.c b/target/s390x/int_helper.c
index 5bc470bdc7..f26f36a904 100644
--- a/target/s390x/int_helper.c
+++ b/target/s390x/int_helper.c
@@ -137,14 +137,11 @@ uint64_t HELPER(cvd)(int32_t reg)
return dec;
}
-uint64_t HELPER(popcnt)(uint64_t r2)
+uint64_t HELPER(popcnt)(uint64_t val)
{
- uint64_t ret = 0;
- int i;
-
- for (i = 0; i < 64; i += 8) {
- uint64_t t = ctpop32((r2 >> i) & 0xff);
- ret |= t << i;
- }
- return ret;
+ /* Note that we don't fold past bytes. */
+ val = (val & 0x5555555555555555ULL) + ((val >> 1) & 0x5555555555555555ULL);
+ val = (val & 0x3333333333333333ULL) + ((val >> 2) & 0x3333333333333333ULL);
+ val = (val + (val >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
+ return val;
}