summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2020-12-15 14:10:22 +0100
committerTor Egge <Tor.Egge@broadpark.no>2020-12-15 14:10:22 +0100
commit28219718b594ac907408535fd502f7e746a0af2d (patch)
tree77cbaa0ec39b94c4ea574e62b1e3dc578d1f8c40
parenta10f8b332ab69f7674962e9ae45a8f55799e2c62 (diff)
Optimize bucketId::reverse
-rw-r--r--document/src/vespa/document/bucket/bucketid.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/document/src/vespa/document/bucket/bucketid.cpp b/document/src/vespa/document/bucket/bucketid.cpp
index ddea0d4ba85..668798d6c39 100644
--- a/document/src/vespa/document/bucket/bucketid.cpp
+++ b/document/src/vespa/document/bucket/bucketid.cpp
@@ -93,14 +93,10 @@ void BucketId::throwFailedSetUsedBits(uint32_t used, uint32_t availBits) {
BucketId::Type
BucketId::reverse(Type id)
{
- Type retVal;
- int bytes = sizeof(Type);
-
- for (int i = 0; i < bytes; i++) {
- ((unsigned char*)&retVal)[bytes - i - 1] = reverseBitTable[((const unsigned char*)&id)[i]];
- }
-
- return retVal;
+ id = ((id & 0x5555555555555555l) << 1) | ((id & 0xaaaaaaaaaaaaaaaal) >> 1);
+ id = ((id & 0x3333333333333333l) << 2) | ((id & 0xccccccccccccccccl) >> 2);
+ id = ((id & 0x0f0f0f0f0f0f0f0fl) << 4) | ((id & 0xf0f0f0f0f0f0f0f0l) >> 4);
+ return __builtin_bswap64(id);
}
BucketId::Type