diff options
author | Darrick J. Wong <djwong@us.ibm.com> | 2012-03-23 18:02:26 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-23 19:58:38 -0400 |
commit | 5cde7656d0dd222170eb0250bd1f70c9018fd438 (patch) | |
tree | 6ebd5b76968f84d5fd8545cfe3400162d76d222c /lib | |
parent | 577eba9e22e872574c466648b46eeb3e0d04372e (diff) |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kconfig | 43 | ||||
-rw-r--r-- | lib/crc32defs.h | 18 |
2 files changed, 61 insertions, 0 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index 6d7ce4b138c4..43359bb1ca90 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
@@ -80,6 +80,49 @@ config CRC32_SELFTEST | |||
80 | and crc32_be over byte strings with random alignment and length | 80 | and crc32_be over byte strings with random alignment and length |
81 | and computes the total elapsed time and number of bytes processed. | 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 | config CRC7 | 126 | config CRC7 |
84 | tristate "CRC7 functions" | 127 | tristate "CRC7 functions" |
85 | help | 128 | help |
diff --git a/lib/crc32defs.h b/lib/crc32defs.h index 6fd191732fec..64cba2c3c700 100644 --- a/lib/crc32defs.h +++ b/lib/crc32defs.h | |||
@@ -13,6 +13,24 @@ | |||
13 | */ | 13 | */ |
14 | #define CRC32C_POLY_LE 0x82F63B78 | 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 | * How many bits at a time to use. Valid values are 1, 2, 4, 8, 32 and 64. | 35 | * How many bits at a time to use. Valid values are 1, 2, 4, 8, 32 and 64. |
18 | * For less performance-sensitive, use 4 or 8 to save table size. | 36 | * For less performance-sensitive, use 4 or 8 to save table size. |