From 28219718b594ac907408535fd502f7e746a0af2d Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Tue, 15 Dec 2020 14:10:22 +0100 Subject: Optimize bucketId::reverse --- document/src/vespa/document/bucket/bucketid.cpp | 12 ++++-------- 1 file 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 -- cgit v1.2.3