summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-12-15 14:58:20 +0100
committerGitHub <noreply@github.com>2020-12-15 14:58:20 +0100
commit8d7a5ee3e70389543bb8c819d94266acc25287a6 (patch)
treeccc892eef73d7cd28e35d0f2f4b3bda1091bd3bd
parent67c255a1b6cd0d9f9ab74eb418794e1a6366f877 (diff)
parent28219718b594ac907408535fd502f7e746a0af2d (diff)
Merge pull request #15818 from vespa-engine/toregge/optimize-bucketid-reverse
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