]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libfrog/crc32defs.h
libfrog: fix bitmap error communication problems
[thirdparty/xfsprogs-dev.git] / libfrog / crc32defs.h
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
5a4d6a2d
DW
2/*
3 * Use slice-by-8, which is the fastest variant.
4 *
5 * Calculate checksum 8 bytes at a time with a clever slicing algorithm.
6 * This is the fastest algorithm, but comes with a 8KiB lookup table.
7 * Most modern processors have enough cache to hold this table without
8 * thrashing the cache.
9 *
10 * The Linux kernel uses this as the default implementation "unless you
11 * have a good reason not to". The reason why Kconfig urges you to pick
12 * SLICEBY8 is because people challenged the assertion that we should
13 * always use slice by 8, so Darrick wrote a crc microbenchmark utility
14 * and ran it on as many machines as he could get his hands on to show
15 * that sb8 was the fastest.
16 *
17 * Every 64-bit machine (and most of the 32-bit ones too) saw the best
18 * results with sb8. Any machine with more than 4K of cache saw better
19 * results. The spreadsheet still exists today[1]; note that
20 * 'crc32-kern-le' corresponds to the slice by 4 algorithm which is the
21 * default unless CRC_LE_BITS is defined explicitly.
22 *
23 * FWIW, there are a handful of board defconfigs in the kernel that
24 * don't pick sliceby8. These are all embedded 32-bit mips/ppc systems
25 * with very small cache sizes which experience cache thrashing with the
26 * slice by 8 algorithm, and therefore chose to pick defaults that are
27 * saner for their particular board configuration. For nearly all of
28 * XFS' perceived userbase (which we assume are 32 and 64-bit machines
29 * with sufficiently large CPU cache and largeish storage devices) slice
30 * by 8 is the right choice.
31 *
32 * [1] https://goo.gl/0LSzsG ("crc32c_bench")
33 */
34#define CRC_LE_BITS 64
35
7e280e68
DC
36/*
37 * This is the CRC32c polynomial, as outlined by Castagnoli.
38 * x^32+x^28+x^27+x^26+x^25+x^23+x^22+x^20+x^19+x^18+x^14+x^13+x^11+x^10+x^9+
39 * x^8+x^6+x^0
40 */
41#define CRC32C_POLY_LE 0x82F63B78
42
7e280e68
DC
43/*
44 * Little-endian CRC computation. Used with serial bit streams sent
45 * lsbit-first. Be sure to use cpu_to_le32() to append the computed CRC.
46 */
47#if CRC_LE_BITS > 64 || CRC_LE_BITS < 1 || CRC_LE_BITS == 16 || \
48 CRC_LE_BITS & CRC_LE_BITS-1
49# error "CRC_LE_BITS must be one of {1, 2, 4, 8, 32, 64}"
50#endif