diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2020-09-19 22:51:19 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2020-11-08 20:06:53 +0100 |
commit | 2f4c93099d7a0fea1e1c4a0a59d2c830c57e0760 (patch) | |
tree | 31ea188c9fc4aa7fe87346e2c1cf7b94a17b5fe6 /document | |
parent | 81f33dd36a90bcef7be8a88021a820526b093c06 (diff) |
Faster bucket order compare for global ids.
Diffstat (limited to 'document')
-rw-r--r-- | document/src/vespa/document/base/globalid.cpp | 33 | ||||
-rw-r--r-- | document/src/vespa/document/base/globalid.h | 19 |
2 files changed, 18 insertions, 34 deletions
diff --git a/document/src/vespa/document/base/globalid.cpp b/document/src/vespa/document/base/globalid.cpp index bdf81d1c3c8..4f96ac0e659 100644 --- a/document/src/vespa/document/base/globalid.cpp +++ b/document/src/vespa/document/base/globalid.cpp @@ -39,39 +39,6 @@ getHexVal(char c) namespace document { -bool -GlobalId::BucketOrderCmp::operator()(const GlobalId &lhs, const GlobalId &rhs) const -{ - const unsigned char * __restrict__ a = lhs._gid._buffer; - const unsigned char * __restrict__ b = rhs._gid._buffer; - int diff; - if ((diff = compare(a[0], b[0])) != 0) { - return diff < 0; - } - if ((diff = compare(a[1], b[1])) != 0) { - return diff < 0; - } - if ((diff = compare(a[2], b[2])) != 0) { - return diff < 0; - } - if ((diff = compare(a[3], b[3])) != 0) { - return diff < 0; - } - if ((diff = compare(a[8], b[8])) != 0) { - return diff < 0; - } - if ((diff = compare(a[9], b[9])) != 0) { - return diff < 0; - } - if ((diff = compare(a[10], b[10])) != 0) { - return diff < 0; - } - if ((diff = compare(a[11], b[11])) != 0) { - return diff < 0; - } - return lhs < rhs; -} - vespalib::string GlobalId::toString() const { vespalib::asciistream out; out << "gid(0x" << vespalib::hex; diff --git a/document/src/vespa/document/base/globalid.h b/document/src/vespa/document/base/globalid.h index 1bb257b7cbf..ac30e189033 100644 --- a/document/src/vespa/document/base/globalid.h +++ b/document/src/vespa/document/base/globalid.h @@ -64,7 +64,24 @@ public: * given bucket. */ struct BucketOrderCmp { - bool operator()(const GlobalId &lhs, const GlobalId &rhs) const; + bool operator()(const GlobalId &lhs, const GlobalId &rhs) const { + const uint32_t * __restrict__ a = lhs._gid._nums; + const uint32_t * __restrict__ b = rhs._gid._nums; + if (a[0] != b[0]) { + return bitswap(a[0]) < bitswap(b[0]); + } + if (a[2] != b[2]) { + return bitswap(a[2]) < bitswap(b[2]); + } + return __builtin_bswap32(a[1]) < __builtin_bswap32(b[1]); + } + static uint32_t bitswap(uint32_t value) { + value = ((value & 0x55555555) << 1) | ((value & 0xaaaaaaaa) >> 1); + value = ((value & 0x33333333) << 2) | ((value & 0xcccccccc) >> 2); + value = ((value & 0x0f0f0f0f) << 4) | ((value & 0xf0f0f0f0) >> 4); + return __builtin_bswap32(value); + } + //These 2 compare methods are exposed only for testing static int compareRaw(unsigned char a, unsigned char b) { return a - b; |