dash/src/crc32c
MacroFake 1526885baf
Merge bitcoin/bitcoin#25836: subtree: update crc32c subtree
08269e54a9a74e06c9fb72720a216d8c4d4532a2 Squashed 'src/crc32c/' changes from 0d624261ef..0bac72c455 (fanquake)

Pull request description:

  Update the crc32c subtree. Includes:
  * https://github.com/bitcoin-core/crc32c-subtree/pull/5

  Which is useful for https://github.com/bitcoin/bitcoin/pull/25797.

  Guix Build (x86_64):
  ```bash
  10677afb5b43e75f9c44ca2a854df88c2d2443392d3930d8c63d3c17e8d5959f  guix-build-9546b3a2a3a4/output/aarch64-linux-gnu/SHA256SUMS.part
  a05ea337e8dbbf234419908e1c95467f24f9ad83f3371718d4d4e3c1ae64dc7b  guix-build-9546b3a2a3a4/output/aarch64-linux-gnu/bitcoin-9546b3a2a3a4-aarch64-linux-gnu-debug.tar.gz
  9e3bcaecc55e8100c17cd6049f99a5dcdd485153091a9ddc1bb014cd74da719b  guix-build-9546b3a2a3a4/output/aarch64-linux-gnu/bitcoin-9546b3a2a3a4-aarch64-linux-gnu.tar.gz
  1306478fadf15b11636625747029de78a9121d179bc63cad77478a5a4b70e012  guix-build-9546b3a2a3a4/output/arm-linux-gnueabihf/SHA256SUMS.part
  55e82fc26fb57b4a58d63985b4b746c939c949abc670c976e270d5ec9c678623  guix-build-9546b3a2a3a4/output/arm-linux-gnueabihf/bitcoin-9546b3a2a3a4-arm-linux-gnueabihf-debug.tar.gz
  4ef06487c7df0b5ffdbcd5b8e4d32ffc8016f071fda7566f824e713581e7b043  guix-build-9546b3a2a3a4/output/arm-linux-gnueabihf/bitcoin-9546b3a2a3a4-arm-linux-gnueabihf.tar.gz
  fff63a55498bc592296fa3514bc99b39e83c4ab808ce3b04c9499b7a6adf3fd6  guix-build-9546b3a2a3a4/output/arm64-apple-darwin/SHA256SUMS.part
  965a96698bf7e49e2cc710ea567f69fbd4bedef64308f574e96c66e15c78d84d  guix-build-9546b3a2a3a4/output/arm64-apple-darwin/bitcoin-9546b3a2a3a4-arm64-apple-darwin-unsigned.dmg
  6738a0692430d4e59b45a8a9a247b6765970fb17c4047b66a332999425caafd9  guix-build-9546b3a2a3a4/output/arm64-apple-darwin/bitcoin-9546b3a2a3a4-arm64-apple-darwin-unsigned.tar.gz
  d2dc890f9d4e7f147b29e3e186504fc1af7f68b516d770d7700d4982429ad7e3  guix-build-9546b3a2a3a4/output/arm64-apple-darwin/bitcoin-9546b3a2a3a4-arm64-apple-darwin.tar.gz
  c74196e38f26f0aa8b345d81389a69c2324017c08b32fe5d97823a6bdaebd63b  guix-build-9546b3a2a3a4/output/dist-archive/bitcoin-9546b3a2a3a4.tar.gz
  fdcebf2b6518f3a538429aba53795f45a6c07e0b3a73e58242a46b0e1a1de429  guix-build-9546b3a2a3a4/output/powerpc64-linux-gnu/SHA256SUMS.part
  d4180196535c6a13f158e6f1b013bac6e1f32291d2940f830898aff55bd215ad  guix-build-9546b3a2a3a4/output/powerpc64-linux-gnu/bitcoin-9546b3a2a3a4-powerpc64-linux-gnu-debug.tar.gz
  ffbaea4130f460a93afd89618b68be5918d9fad053427390350daa1f512f628c  guix-build-9546b3a2a3a4/output/powerpc64-linux-gnu/bitcoin-9546b3a2a3a4-powerpc64-linux-gnu.tar.gz
  09071b159126c89bdbc3f19b51b89c34d9709658e77f0f5da55b41218453b652  guix-build-9546b3a2a3a4/output/powerpc64le-linux-gnu/SHA256SUMS.part
  4b75a22ac557a0fea88f8df0beaff9b19fb032587710edcca3d942847445fbc3  guix-build-9546b3a2a3a4/output/powerpc64le-linux-gnu/bitcoin-9546b3a2a3a4-powerpc64le-linux-gnu-debug.tar.gz
  1bbb30880fe9ec5151377b0ee1952316b63d3d4bfaaa383f72660591e46e1965  guix-build-9546b3a2a3a4/output/powerpc64le-linux-gnu/bitcoin-9546b3a2a3a4-powerpc64le-linux-gnu.tar.gz
  06e6140b0b23f974a1c49e551fc4f8effba8afcc3fef3adf4fc3a5cd72d55007  guix-build-9546b3a2a3a4/output/riscv64-linux-gnu/SHA256SUMS.part
  948219a7eb070e48d613bef5c96e47880414d738ecc0c334e1d46291af315cc9  guix-build-9546b3a2a3a4/output/riscv64-linux-gnu/bitcoin-9546b3a2a3a4-riscv64-linux-gnu-debug.tar.gz
  9dcdb87bf947a23eb8e108a15b7b224f03f01dfac1879be85114f67ecc1cd425  guix-build-9546b3a2a3a4/output/riscv64-linux-gnu/bitcoin-9546b3a2a3a4-riscv64-linux-gnu.tar.gz
  c02b6fcc9f1333a83571eff16c6d7789febd8f693c6945b751b0665bdc025f20  guix-build-9546b3a2a3a4/output/x86_64-apple-darwin/SHA256SUMS.part
  3a092d1c08cb85f4ac502424b3c5932ff6970a191ce43d622d36ad17f9b36243  guix-build-9546b3a2a3a4/output/x86_64-apple-darwin/bitcoin-9546b3a2a3a4-x86_64-apple-darwin-unsigned.dmg
  1a1bbefb93131d62f88d9eb51bddc2bd3e247533f8000555af20ea582fe65daa  guix-build-9546b3a2a3a4/output/x86_64-apple-darwin/bitcoin-9546b3a2a3a4-x86_64-apple-darwin-unsigned.tar.gz
  684180389af6cba525439b8c8142bbdc3391c125583743275b6876e69adbd733  guix-build-9546b3a2a3a4/output/x86_64-apple-darwin/bitcoin-9546b3a2a3a4-x86_64-apple-darwin.tar.gz
  f81bc831e3d933b387940c8bd3cc10402e00116c713cd2ac9e7531082a354187  guix-build-9546b3a2a3a4/output/x86_64-linux-gnu/SHA256SUMS.part
  05faf45bc567742d41addafc5d8e85b5b586173f2efdd2ae501d6ebdf69379bb  guix-build-9546b3a2a3a4/output/x86_64-linux-gnu/bitcoin-9546b3a2a3a4-x86_64-linux-gnu-debug.tar.gz
  dfe1b0c22c706a918cbc8952bebba0b471c849276725dd5e0b2eee265c281386  guix-build-9546b3a2a3a4/output/x86_64-linux-gnu/bitcoin-9546b3a2a3a4-x86_64-linux-gnu.tar.gz
  64186c495eb9b6e8c6a2be89530c928e7b161e5ca7a1b56b7786dd28d310e7e8  guix-build-9546b3a2a3a4/output/x86_64-w64-mingw32/SHA256SUMS.part
  c099d0dfeb4556539b52c8bc08ef2c15c636526dccc0a73900c68fa45b052189  guix-build-9546b3a2a3a4/output/x86_64-w64-mingw32/bitcoin-9546b3a2a3a4-win64-debug.zip
  7751e50110ed1a9a46a2fdadb7d71c6e30910685a3074dea563ec64997cbb134  guix-build-9546b3a2a3a4/output/x86_64-w64-mingw32/bitcoin-9546b3a2a3a4-win64-setup-unsigned.exe
  d8ec6a7d24c9b514c342fe3ee2281482a104100230650523d3303484036507a3  guix-build-9546b3a2a3a4/output/x86_64-w64-mingw32/bitcoin-9546b3a2a3a4-win64-unsigned.tar.gz
  ee3123a60a732596347e58351c38cc5c0a8bf9b24f3cc9041f12ec11572e0659  guix-build-9546b3a2a3a4/output/x86_64-w64-mingw32/bitcoin-9546b3a2a3a4-win64.zip
  ```

  Guix Build (arm64):
  ```bash
  1306478fadf15b11636625747029de78a9121d179bc63cad77478a5a4b70e012  guix-build-9546b3a2a3a4/output/arm-linux-gnueabihf/SHA256SUMS.part
  55e82fc26fb57b4a58d63985b4b746c939c949abc670c976e270d5ec9c678623  guix-build-9546b3a2a3a4/output/arm-linux-gnueabihf/bitcoin-9546b3a2a3a4-arm-linux-gnueabihf-debug.tar.gz
  4ef06487c7df0b5ffdbcd5b8e4d32ffc8016f071fda7566f824e713581e7b043  guix-build-9546b3a2a3a4/output/arm-linux-gnueabihf/bitcoin-9546b3a2a3a4-arm-linux-gnueabihf.tar.gz
  fff63a55498bc592296fa3514bc99b39e83c4ab808ce3b04c9499b7a6adf3fd6  guix-build-9546b3a2a3a4/output/arm64-apple-darwin/SHA256SUMS.part
  965a96698bf7e49e2cc710ea567f69fbd4bedef64308f574e96c66e15c78d84d  guix-build-9546b3a2a3a4/output/arm64-apple-darwin/bitcoin-9546b3a2a3a4-arm64-apple-darwin-unsigned.dmg
  6738a0692430d4e59b45a8a9a247b6765970fb17c4047b66a332999425caafd9  guix-build-9546b3a2a3a4/output/arm64-apple-darwin/bitcoin-9546b3a2a3a4-arm64-apple-darwin-unsigned.tar.gz
  d2dc890f9d4e7f147b29e3e186504fc1af7f68b516d770d7700d4982429ad7e3  guix-build-9546b3a2a3a4/output/arm64-apple-darwin/bitcoin-9546b3a2a3a4-arm64-apple-darwin.tar.gz
  c74196e38f26f0aa8b345d81389a69c2324017c08b32fe5d97823a6bdaebd63b  guix-build-9546b3a2a3a4/output/dist-archive/bitcoin-9546b3a2a3a4.tar.gz
  fdcebf2b6518f3a538429aba53795f45a6c07e0b3a73e58242a46b0e1a1de429  guix-build-9546b3a2a3a4/output/powerpc64-linux-gnu/SHA256SUMS.part
  d4180196535c6a13f158e6f1b013bac6e1f32291d2940f830898aff55bd215ad  guix-build-9546b3a2a3a4/output/powerpc64-linux-gnu/bitcoin-9546b3a2a3a4-powerpc64-linux-gnu-debug.tar.gz
  ffbaea4130f460a93afd89618b68be5918d9fad053427390350daa1f512f628c  guix-build-9546b3a2a3a4/output/powerpc64-linux-gnu/bitcoin-9546b3a2a3a4-powerpc64-linux-gnu.tar.gz
  09071b159126c89bdbc3f19b51b89c34d9709658e77f0f5da55b41218453b652  guix-build-9546b3a2a3a4/output/powerpc64le-linux-gnu/SHA256SUMS.part
  4b75a22ac557a0fea88f8df0beaff9b19fb032587710edcca3d942847445fbc3  guix-build-9546b3a2a3a4/output/powerpc64le-linux-gnu/bitcoin-9546b3a2a3a4-powerpc64le-linux-gnu-debug.tar.gz
  1bbb30880fe9ec5151377b0ee1952316b63d3d4bfaaa383f72660591e46e1965  guix-build-9546b3a2a3a4/output/powerpc64le-linux-gnu/bitcoin-9546b3a2a3a4-powerpc64le-linux-gnu.tar.gz
  06e6140b0b23f974a1c49e551fc4f8effba8afcc3fef3adf4fc3a5cd72d55007  guix-build-9546b3a2a3a4/output/riscv64-linux-gnu/SHA256SUMS.part
  948219a7eb070e48d613bef5c96e47880414d738ecc0c334e1d46291af315cc9  guix-build-9546b3a2a3a4/output/riscv64-linux-gnu/bitcoin-9546b3a2a3a4-riscv64-linux-gnu-debug.tar.gz
  9dcdb87bf947a23eb8e108a15b7b224f03f01dfac1879be85114f67ecc1cd425  guix-build-9546b3a2a3a4/output/riscv64-linux-gnu/bitcoin-9546b3a2a3a4-riscv64-linux-gnu.tar.gz
  c02b6fcc9f1333a83571eff16c6d7789febd8f693c6945b751b0665bdc025f20  guix-build-9546b3a2a3a4/output/x86_64-apple-darwin/SHA256SUMS.part
  3a092d1c08cb85f4ac502424b3c5932ff6970a191ce43d622d36ad17f9b36243  guix-build-9546b3a2a3a4/output/x86_64-apple-darwin/bitcoin-9546b3a2a3a4-x86_64-apple-darwin-unsigned.dmg
  1a1bbefb93131d62f88d9eb51bddc2bd3e247533f8000555af20ea582fe65daa  guix-build-9546b3a2a3a4/output/x86_64-apple-darwin/bitcoin-9546b3a2a3a4-x86_64-apple-darwin-unsigned.tar.gz
  684180389af6cba525439b8c8142bbdc3391c125583743275b6876e69adbd733  guix-build-9546b3a2a3a4/output/x86_64-apple-darwin/bitcoin-9546b3a2a3a4-x86_64-apple-darwin.tar.gz
  f81bc831e3d933b387940c8bd3cc10402e00116c713cd2ac9e7531082a354187  guix-build-9546b3a2a3a4/output/x86_64-linux-gnu/SHA256SUMS.part
  05faf45bc567742d41addafc5d8e85b5b586173f2efdd2ae501d6ebdf69379bb  guix-build-9546b3a2a3a4/output/x86_64-linux-gnu/bitcoin-9546b3a2a3a4-x86_64-linux-gnu-debug.tar.gz
  dfe1b0c22c706a918cbc8952bebba0b471c849276725dd5e0b2eee265c281386  guix-build-9546b3a2a3a4/output/x86_64-linux-gnu/bitcoin-9546b3a2a3a4-x86_64-linux-gnu.tar.gz
  64186c495eb9b6e8c6a2be89530c928e7b161e5ca7a1b56b7786dd28d310e7e8  guix-build-9546b3a2a3a4/output/x86_64-w64-mingw32/SHA256SUMS.part
  c099d0dfeb4556539b52c8bc08ef2c15c636526dccc0a73900c68fa45b052189  guix-build-9546b3a2a3a4/output/x86_64-w64-mingw32/bitcoin-9546b3a2a3a4-win64-debug.zip
  7751e50110ed1a9a46a2fdadb7d71c6e30910685a3074dea563ec64997cbb134  guix-build-9546b3a2a3a4/output/x86_64-w64-mingw32/bitcoin-9546b3a2a3a4-win64-setup-unsigned.exe
  d8ec6a7d24c9b514c342fe3ee2281482a104100230650523d3303484036507a3  guix-build-9546b3a2a3a4/output/x86_64-w64-mingw32/bitcoin-9546b3a2a3a4-win64-unsigned.tar.gz
  ee3123a60a732596347e58351c38cc5c0a8bf9b24f3cc9041f12ec11572e0659  guix-build-9546b3a2a3a4/output/x86_64-w64-mingw32/bitcoin-9546b3a2a3a4-win64.zip
  ```

ACKs for top commit:
  hebasto:
    ACK 9546b3a2a3a4796a13f05edd1340bfc0fa4c0a75, I have reviewed the code and it looks OK, I agree it can be merged.
  jarolrod:
    ACK 9546b3a2a3a4796a13f05edd1340bfc0fa4c0a75

Tree-SHA512: e5f98fd3bdb90516d24ed6cc26da9ed4a83374888d322a4e3a26d8df4a2352711d842787b07ba94e2dbd142391bb8f39eb6f040cbb3c2f217f7980b69aaae31f
2024-02-29 09:35:00 -06:00
..
include/crc32c
src Merge bitcoin/bitcoin#23133: Update crc32c subtree 2022-03-13 14:52:24 -05:00
.appveyor.yml
.clang_complete
.clang-format
.gitignore
.gitmodules
.travis.yml Merge bitcoin/bitcoin#23133: Update crc32c subtree 2022-03-13 14:52:24 -05:00
.ycm_extra_conf.py Merge bitcoin/bitcoin#23133: Update crc32c subtree 2022-03-13 14:52:24 -05:00
AUTHORS
CMakeLists.txt Merge bitcoin/bitcoin#25836: subtree: update crc32c subtree 2024-02-29 09:35:00 -06:00
CONTRIBUTING.md
Crc32cConfig.cmake.in
LICENSE
README.md Merge bitcoin/bitcoin#23133: Update crc32c subtree 2022-03-13 14:52:24 -05:00

CRC32C

Build Status Build Status

New file format authors should consider HighwayHash. The initial version of this code was extracted from LevelDB, which is a stable key-value store that is widely used at Google.

This project collects a few CRC32C implementations under an umbrella that dispatches to a suitable implementation based on the host computer's hardware capabilities.

CRC32C is specified as the CRC that uses the iSCSI polynomial in RFC 3720. The polynomial was introduced by G. Castagnoli, S. Braeuer and M. Herrmann. CRC32C is used in software such as Btrfs, ext4, Ceph and leveldb.

Usage

#include "crc32c/crc32c.h"

int main() {
  const std::uint8_t buffer[] = {0, 0, 0, 0};
  std::uint32_t result;

  // Process a raw buffer.
  result = crc32c::Crc32c(buffer, 4);

  // Process a std::string.
  std::string string;
  string.resize(4);
  result = crc32c::Crc32c(string);

  // If you have C++17 support, process a std::string_view.
  std::string_view string_view(string);
  result = crc32c::Crc32c(string_view);

  return 0;
}

Prerequisites

This project uses CMake for building and testing. CMake is available in all popular Linux distributions, as well as in Homebrew.

This project uses submodules for dependency management.

git submodule update --init --recursive

If you're using Atom, the following packages can help.

apm install autocomplete-clang build build-cmake clang-format language-cmake \
    linter linter-clang

If you don't mind more setup in return for more speed, replace autocomplete-clang and linter-clang with you-complete-me. This requires setting up ycmd.

apm install autocomplete-plus build build-cmake clang-format language-cmake \
    linter you-complete-me

Building

The following commands build and install the project.

mkdir build
cd build
cmake -DCRC32C_BUILD_TESTS=0 -DCRC32C_BUILD_BENCHMARKS=0 .. && make all install

Development

The following command (when executed from build/) (re)builds the project and runs the tests.

cmake .. && cmake --build . && ctest --output-on-failure

Android testing

The following command builds the project against the Android NDK, which is useful for benchmarking against ARM processors.

cmake .. -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
    -DCMAKE_ANDROID_NDK=$HOME/Library/Android/sdk/ndk-bundle \
    -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \
    -DCMAKE_ANDROID_STL_TYPE=c++_static -DCRC32C_USE_GLOG=0 \
    -DCMAKE_BUILD_TYPE=Release && cmake --build .

The following commands install and run the benchmarks.

adb push crc32c_bench /data/local/tmp
adb shell chmod +x /data/local/tmp/crc32c_bench
adb shell 'cd /data/local/tmp && ./crc32c_bench'
adb shell rm /data/local/tmp/crc32c_bench

The following commands install and run the tests.

adb push crc32c_tests /data/local/tmp
adb shell chmod +x /data/local/tmp/crc32c_tests
adb shell 'cd /data/local/tmp && ./crc32c_tests'
adb shell rm /data/local/tmp/crc32c_tests