]>
Commit | Line | Data |
---|---|---|
0731742a XL |
1 | # crc32fast [![Build Status][travis-img]][travis] [![Crates.io][crates-img]][crates] [![Documentation][docs-img]][docs] |
2 | ||
3 | [travis-img]: https://travis-ci.com/srijs/rust-crc32fast.svg?branch=master | |
4 | [travis]: https://travis-ci.com/srijs/rust-crc32fast | |
5 | [crates-img]: https://img.shields.io/crates/v/crc32fast.svg | |
6 | [crates]: https://crates.io/crates/crc32fast | |
7 | [docs-img]: https://docs.rs/crc32fast/badge.svg | |
8 | [docs]: https://docs.rs/crc32fast | |
9 | ||
10 | _Fast, SIMD-accelerated CRC32 (IEEE) checksum computation_ | |
11 | ||
12 | ## Usage | |
13 | ||
14 | ```rust | |
15 | extern crate crc32fast; | |
16 | ||
17 | use crc32fast::Hasher; | |
18 | ||
19 | let mut hasher = Hasher::new(); | |
20 | hasher.update(b"foo bar baz"); | |
21 | let checksum = hasher.finalize(); | |
22 | ``` | |
23 | ||
24 | ## Performance | |
25 | ||
26 | This crate contains multiple CRC32 implementations: | |
27 | ||
28 | - A fast baseline implementation which processes up to 16 bytes per iteration | |
29 | - An optimized implementation for modern `x86` using `sse` and `pclmulqdq` instructions | |
30 | ||
31 | Calling the `Hasher::new` constructor at runtime will perform a feature detection to select the most | |
32 | optimal implementation for the current CPU feature set. | |
33 | ||
34 | | crate | version | variant | ns/iter | MB/s | | |
35 | |-------------------------------------|---------|-----------|---------|------| | |
36 | | [crc](https://crates.io/crates/crc) | 1.8.1 | n/a | 4,926 | 207 | | |
37 | | crc32fast (this crate) | 1.0.0 | baseline | 683 | 1499 | | |
38 | | crc32fast (this crate) | 1.0.0 | pclmulqdq | 140 | 7314 | | |
39 | ||
40 | ## Memory Safety | |
41 | ||
42 | Due to the use of SIMD intrinsics for the optimized implementations, this crate contains some amount of `unsafe` code. | |
43 | ||
44 | In order to ensure memory safety, the relevant code has been fuzz tested using [afl.rs](https://github.com/rust-fuzz/afl.rs) with millions of iterations in both `debug` and `release` build settings. You can inspect the test setup in the `fuzz` sub-directory, which also has instructions on how to run the tests yourself. | |
45 | ||
46 | On top of that, every commit is tested using an address sanitizer in CI to catch any out of bounds memory accesses. | |
47 | ||
48 | Even though neither fuzzing not sanitization has revealed any safety bugs yet, please don't hesitate to file an issue if you run into any crashes or other unexpected behaviour. | |
49 | ||
50 | ## License | |
51 | ||
52 | This project is licensed under either of | |
53 | ||
54 | * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or | |
55 | http://www.apache.org/licenses/LICENSE-2.0) | |
56 | * MIT license ([LICENSE-MIT](LICENSE-MIT) or | |
57 | http://opensource.org/licenses/MIT) | |
58 | ||
59 | at your option. | |
60 | ||
61 | ### Contribution | |
62 | ||
63 | Unless you explicitly state otherwise, any contribution intentionally submitted | |
64 | for inclusion in this project by you, as defined in the Apache-2.0 license, | |
65 | shall be dual licensed as above, without any additional terms or conditions. |