aboutsummaryrefslogtreecommitdiff
path: root/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
commitcf44e4ca7762742c6c3154447b40869ec9d041db (patch)
treed5a89851da0a8ab07c40966ac137f4e299c80927 /util/crc32c.cc
parent634ad517037b319147816f1d112b066528e1724a (diff)
downloadbitcoin-cf44e4ca7762742c6c3154447b40869ec9d041db.tar.xz
Squashed 'src/leveldb/' changes from a31c8aa40..196962ff0
196962ff0 Add AcceleratedCRC32C to port_win.h 1bdf1c34c Merge upstream LevelDB v1.20 d31721eb0 Merge #17: Fixed file sharing errors fecd44902 Fixed file sharing error in Win32Env::GetFileSize(), Win32SequentialFile::_Init(), Win32RandomAccessFile::_Init() Fixed error checking in Win32SequentialFile::_Init() 5b7510f1b Merge #14: Merge upstream LevelDB 1.19 0d969fd57 Merge #16: [LevelDB] Do no crash if filesystem can't fsync c8c029b5b [LevelDB] Do no crash if filesystem can't fsync a53934a3a Increase leveldb version to 1.20. f3f139737 Separate Env tests from PosixEnv tests. eb4f0972f leveldb: Fix compilation warnings in port_posix_sse.cc on x86 (32-bit). d0883b600 Fixed path to doc file: index.md. 7fa20948d Convert documentation to markdown. ea175e28f Implement support for Intel crc32 instruction (SSE 4.2) 95cd743e5 Including <limits> for std::numeric_limits. 646c3588d Limit the number of read-only files the POSIX Env will have open. d40bc3fa5 Merge #13: Typo ebbd772d3 Typo a2fb086d0 Add option for max file size. The currend hard-coded value of 2M is inefficient in colossus. git-subtree-dir: src/leveldb git-subtree-split: 196962ff01c39b4705d8117df5c3f8c205349950
Diffstat (limited to 'util/crc32c.cc')
-rw-r--r--util/crc32c.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/util/crc32c.cc b/util/crc32c.cc
index 6db9e77077..edd61cfd6f 100644
--- a/util/crc32c.cc
+++ b/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;