Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crc32: select an algorithm via Kconfig

Allow the kernel builder to choose a crc32* algorithm for the kernel.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Cc: Bob Pearson <rpearson@systemfabricworks.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Darrick J. Wong and committed by
Linus Torvalds
5cde7656 577eba9e

+61
+43
lib/Kconfig
··· 80 80 and crc32_be over byte strings with random alignment and length 81 81 and computes the total elapsed time and number of bytes processed. 82 82 83 + choice 84 + prompt "CRC32 implementation" 85 + depends on CRC32 86 + default CRC32_SLICEBY8 87 + 88 + config CRC32_SLICEBY8 89 + bool "Slice by 8 bytes" 90 + help 91 + Calculate checksum 8 bytes at a time with a clever slicing algorithm. 92 + This is the fastest algorithm, but comes with a 8KiB lookup table. 93 + Most modern processors have enough cache to hold this table without 94 + thrashing the cache. 95 + 96 + This is the default implementation choice. Choose this one unless 97 + you have a good reason not to. 98 + 99 + config CRC32_SLICEBY4 100 + bool "Slice by 4 bytes" 101 + help 102 + Calculate checksum 4 bytes at a time with a clever slicing algorithm. 103 + This is a bit slower than slice by 8, but has a smaller 4KiB lookup 104 + table. 105 + 106 + Only choose this option if you know what you are doing. 107 + 108 + config CRC32_SARWATE 109 + bool "Sarwate's Algorithm (one byte at a time)" 110 + help 111 + Calculate checksum a byte at a time using Sarwate's algorithm. This 112 + is not particularly fast, but has a small 256 byte lookup table. 113 + 114 + Only choose this option if you know what you are doing. 115 + 116 + config CRC32_BIT 117 + bool "Classic Algorithm (one bit at a time)" 118 + help 119 + Calculate checksum one bit at a time. This is VERY slow, but has 120 + no lookup table. This is provided as a debugging option. 121 + 122 + Only choose this option if you are debugging crc32. 123 + 124 + endchoice 125 + 83 126 config CRC7 84 127 tristate "CRC7 functions" 85 128 help
+18
lib/crc32defs.h
··· 13 13 */ 14 14 #define CRC32C_POLY_LE 0x82F63B78 15 15 16 + /* Try to choose an implementation variant via Kconfig */ 17 + #ifdef CONFIG_CRC32_SLICEBY8 18 + # define CRC_LE_BITS 64 19 + # define CRC_BE_BITS 64 20 + #endif 21 + #ifdef CONFIG_CRC32_SLICEBY4 22 + # define CRC_LE_BITS 32 23 + # define CRC_BE_BITS 32 24 + #endif 25 + #ifdef CONFIG_CRC32_SARWATE 26 + # define CRC_LE_BITS 8 27 + # define CRC_BE_BITS 8 28 + #endif 29 + #ifdef CONFIG_CRC32_BIT 30 + # define CRC_LE_BITS 1 31 + # define CRC_BE_BITS 1 32 + #endif 33 + 16 34 /* 17 35 * How many bits at a time to use. Valid values are 1, 2, 4, 8, 32 and 64. 18 36 * For less performance-sensitive, use 4 or 8 to save table size.