xref: /aosp_15_r20/external/webrtc/third_party/crc32c/src/README.md (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1# CRC32C
2
3[![Build Status](https://travis-ci.org/google/crc32c.svg?branch=master)](https://travis-ci.org/google/crc32c)
4[![Build Status](https://ci.appveyor.com/api/projects/status/moiq7331pett4xuj/branch/master?svg=true)](https://ci.appveyor.com/project/pwnall/crc32c)
5
6New file format authors should consider
7[HighwayHash](https://github.com/google/highwayhash). The initial version of
8this code was extracted from [LevelDB](https://github.com/google/leveldb), which
9is a stable key-value store that is widely used at Google.
10
11This project collects a few CRC32C implementations under an umbrella that
12dispatches to a suitable implementation based on the host computer's hardware
13capabilities.
14
15CRC32C is specified as the CRC that uses the iSCSI polynomial in
16[RFC 3720](https://tools.ietf.org/html/rfc3720#section-12.1). The polynomial was
17introduced by G. Castagnoli, S. Braeuer and M. Herrmann. CRC32C is used in
18software such as Btrfs, ext4, Ceph and leveldb.
19
20
21## Usage
22
23```cpp
24#include "crc32c/crc32c.h"
25
26int main() {
27  const std::uint8_t buffer[] = {0, 0, 0, 0};
28  std::uint32_t result;
29
30  // Process a raw buffer.
31  result = crc32c::Crc32c(buffer, 4);
32
33  // Process a std::string.
34  std::string string;
35  string.resize(4);
36  result = crc32c::Crc32c(string);
37
38  // If you have C++17 support, process a std::string_view.
39  std::string_view string_view(string);
40  result = crc32c::Crc32c(string_view);
41
42  return 0;
43}
44```
45
46
47## Prerequisites
48
49This project uses [CMake](https://cmake.org/) for building and testing. CMake is
50available in all popular Linux distributions, as well as in
51[Homebrew](https://brew.sh/).
52
53This project uses submodules for dependency management.
54
55```bash
56git submodule update --init --recursive
57```
58
59If you're using [Atom](https://atom.io/), the following packages can help.
60
61```bash
62apm install autocomplete-clang build build-cmake clang-format language-cmake \
63    linter linter-clang
64```
65
66If you don't mind more setup in return for more speed, replace
67`autocomplete-clang` and `linter-clang` with `you-complete-me`. This requires
68[setting up ycmd](https://github.com/ycm-core/ycmd#building).
69
70```bash
71apm install autocomplete-plus build build-cmake clang-format language-cmake \
72    linter you-complete-me
73```
74
75## Building
76
77The following commands build and install the project.
78
79```bash
80mkdir build
81cd build
82cmake -DCRC32C_BUILD_TESTS=0 -DCRC32C_BUILD_BENCHMARKS=0 .. && make all install
83```
84
85
86## Development
87
88The following command (when executed from `build/`) (re)builds the project and
89runs the tests.
90
91```bash
92cmake .. && cmake --build . && ctest --output-on-failure
93```
94
95
96### Android testing
97
98The following command builds the project against the Android NDK, which is
99useful for benchmarking against ARM processors.
100
101```bash
102cmake .. -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
103    -DCMAKE_ANDROID_NDK=$HOME/Library/Android/sdk/ndk-bundle \
104    -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \
105    -DCMAKE_ANDROID_STL_TYPE=c++_static -DCRC32C_USE_GLOG=0 \
106    -DCMAKE_BUILD_TYPE=Release && cmake --build .
107```
108
109The following commands install and run the benchmarks.
110
111```bash
112adb push crc32c_bench /data/local/tmp
113adb shell chmod +x /data/local/tmp/crc32c_bench
114adb shell 'cd /data/local/tmp && ./crc32c_bench'
115adb shell rm /data/local/tmp/crc32c_bench
116```
117
118The following commands install and run the tests.
119
120```bash
121adb push crc32c_tests /data/local/tmp
122adb shell chmod +x /data/local/tmp/crc32c_tests
123adb shell 'cd /data/local/tmp && ./crc32c_tests'
124adb shell rm /data/local/tmp/crc32c_tests
125```
126