aboutsummaryrefslogtreecommitdiff
path: root/src/leveldb/util/crc32c.cc
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-06-09 19:24:30 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2017-06-09 19:24:30 -0700
commite4030ab4f47065c362901109c74ca8e791c2de0a (patch)
treec1678f5a72d3888ad5e4621073bbe4fa698883b5 /src/leveldb/util/crc32c.cc
parent1b708f2cf3e6e6a17c5b6dbf2909a2ed2e35755a (diff)
parentcf44e4ca7762742c6c3154447b40869ec9d041db (diff)
downloadbitcoin-e4030ab4f47065c362901109c74ca8e791c2de0a.tar.xz
Update to LevelDB 1.20
Diffstat (limited to 'src/leveldb/util/crc32c.cc')
-rw-r--r--src/leveldb/util/crc32c.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/leveldb/util/crc32c.cc b/src/leveldb/util/crc32c.cc
index 6db9e77077..edd61cfd6f 100644
--- a/src/leveldb/util/crc32c.cc
+++ b/src/leveldb/util/crc32c.cc
@@ -8,6 +8,8 @@
#include "util/crc32c.h"
#include <stdint.h>
+
+#include "port/port.h"
#include "util/coding.h"
namespace leveldb {
@@ -283,7 +285,23 @@ static inline uint32_t LE_LOAD32(const uint8_t *p) {
return DecodeFixed32(reinterpret_cast<const char*>(p));
}
+// Determine if the CPU running this program can accelerate the CRC32C
+// calculation.
+static bool CanAccelerateCRC32C() {
+ // port::AcceleretedCRC32C returns zero when unable to accelerate.
+ static const char kTestCRCBuffer[] = "TestCRCBuffer";
+ static const char kBufSize = sizeof(kTestCRCBuffer) - 1;
+ static const uint32_t kTestCRCValue = 0xdcbc59fa;
+
+ return port::AcceleratedCRC32C(0, kTestCRCBuffer, kBufSize) == kTestCRCValue;
+}
+
uint32_t Extend(uint32_t crc, const char* buf, size_t size) {
+ static bool accelerate = CanAccelerateCRC32C();
+ if (accelerate) {
+ return port::AcceleratedCRC32C(crc, buf, size);
+ }
+
const uint8_t *p = reinterpret_cast<const uint8_t *>(buf);
const uint8_t *e = p + size;
uint32_t l = crc ^ 0xffffffffu;