xref: /linux/arch/riscv/lib/crc-clmul-consts.h (revision 4f9786035f9e519db41375818e1d0b5f20da2f10)
172acff5fSEric Biggers /* SPDX-License-Identifier: GPL-2.0-or-later */
272acff5fSEric Biggers /*
372acff5fSEric Biggers  * CRC constants generated by:
472acff5fSEric Biggers  *
5*511484faSEric Biggers  *	./scripts/gen-crc-consts.py riscv_clmul crc16_msb_0x8bb7,crc32_msb_0x04c11db7,crc32_lsb_0xedb88320,crc32_lsb_0x82f63b78,crc64_msb_0x42f0e1eba9ea3693,crc64_lsb_0x9a6c9329ac4bc9b5
672acff5fSEric Biggers  *
772acff5fSEric Biggers  * Do not edit manually.
872acff5fSEric Biggers  */
972acff5fSEric Biggers 
1072acff5fSEric Biggers struct crc_clmul_consts {
1172acff5fSEric Biggers 	unsigned long fold_across_2_longs_const_hi;
1272acff5fSEric Biggers 	unsigned long fold_across_2_longs_const_lo;
1372acff5fSEric Biggers 	unsigned long barrett_reduction_const_1;
1472acff5fSEric Biggers 	unsigned long barrett_reduction_const_2;
1572acff5fSEric Biggers };
1672acff5fSEric Biggers 
1772acff5fSEric Biggers /*
188bf3e178SEric Biggers  * Constants generated for most-significant-bit-first CRC-16 using
198bf3e178SEric Biggers  * G(x) = x^16 + x^15 + x^11 + x^9 + x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0
208bf3e178SEric Biggers  */
218bf3e178SEric Biggers static const struct crc_clmul_consts crc16_msb_0x8bb7_consts __maybe_unused = {
228bf3e178SEric Biggers #ifdef CONFIG_64BIT
238bf3e178SEric Biggers 	.fold_across_2_longs_const_hi = 0x0000000000001faa, /* x^192 mod G */
248bf3e178SEric Biggers 	.fold_across_2_longs_const_lo = 0x000000000000a010, /* x^128 mod G */
258bf3e178SEric Biggers 	.barrett_reduction_const_1 = 0xfb2d2bfc0e99d245, /* floor(x^79 / G) */
268bf3e178SEric Biggers 	.barrett_reduction_const_2 = 0x0000000000008bb7, /* G - x^16 */
278bf3e178SEric Biggers #else
288bf3e178SEric Biggers 	.fold_across_2_longs_const_hi = 0x00005890, /* x^96 mod G */
298bf3e178SEric Biggers 	.fold_across_2_longs_const_lo = 0x0000f249, /* x^64 mod G */
308bf3e178SEric Biggers 	.barrett_reduction_const_1 = 0xfb2d2bfc, /* floor(x^47 / G) */
318bf3e178SEric Biggers 	.barrett_reduction_const_2 = 0x00008bb7, /* G - x^16 */
328bf3e178SEric Biggers #endif
338bf3e178SEric Biggers };
348bf3e178SEric Biggers 
358bf3e178SEric Biggers /*
3672acff5fSEric Biggers  * Constants generated for most-significant-bit-first CRC-32 using
3772acff5fSEric Biggers  * G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 +
3872acff5fSEric Biggers  *        x^5 + x^4 + x^2 + x^1 + x^0
3972acff5fSEric Biggers  */
4072acff5fSEric Biggers static const struct crc_clmul_consts crc32_msb_0x04c11db7_consts __maybe_unused = {
4172acff5fSEric Biggers #ifdef CONFIG_64BIT
4272acff5fSEric Biggers 	.fold_across_2_longs_const_hi = 0x00000000c5b9cd4c, /* x^192 mod G */
4372acff5fSEric Biggers 	.fold_across_2_longs_const_lo = 0x00000000e8a45605, /* x^128 mod G */
4472acff5fSEric Biggers 	.barrett_reduction_const_1 = 0x826880efa40da72d, /* floor(x^95 / G) */
4572acff5fSEric Biggers 	.barrett_reduction_const_2 = 0x0000000004c11db7, /* G - x^32 */
4672acff5fSEric Biggers #else
4772acff5fSEric Biggers 	.fold_across_2_longs_const_hi = 0xf200aa66, /* x^96 mod G */
4872acff5fSEric Biggers 	.fold_across_2_longs_const_lo = 0x490d678d, /* x^64 mod G */
4972acff5fSEric Biggers 	.barrett_reduction_const_1 = 0x826880ef, /* floor(x^63 / G) */
5072acff5fSEric Biggers 	.barrett_reduction_const_2 = 0x04c11db7, /* G - x^32 */
5172acff5fSEric Biggers #endif
5272acff5fSEric Biggers };
5372acff5fSEric Biggers 
5472acff5fSEric Biggers /*
5572acff5fSEric Biggers  * Constants generated for least-significant-bit-first CRC-32 using
5672acff5fSEric Biggers  * G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 +
5772acff5fSEric Biggers  *        x^5 + x^4 + x^2 + x^1 + x^0
5872acff5fSEric Biggers  */
5972acff5fSEric Biggers static const struct crc_clmul_consts crc32_lsb_0xedb88320_consts __maybe_unused = {
6072acff5fSEric Biggers #ifdef CONFIG_64BIT
6172acff5fSEric Biggers 	.fold_across_2_longs_const_hi = 0x65673b4600000000, /* x^191 mod G */
6272acff5fSEric Biggers 	.fold_across_2_longs_const_lo = 0x9ba54c6f00000000, /* x^127 mod G */
6372acff5fSEric Biggers 	.barrett_reduction_const_1 = 0xb4e5b025f7011641, /* floor(x^95 / G) */
6472acff5fSEric Biggers 	.barrett_reduction_const_2 = 0x00000000edb88320, /* (G - x^32) * x^32 */
6572acff5fSEric Biggers #else
6672acff5fSEric Biggers 	.fold_across_2_longs_const_hi = 0xccaa009e, /* x^95 mod G */
6772acff5fSEric Biggers 	.fold_across_2_longs_const_lo = 0xb8bc6765, /* x^63 mod G */
6872acff5fSEric Biggers 	.barrett_reduction_const_1 = 0xf7011641, /* floor(x^63 / G) */
6972acff5fSEric Biggers 	.barrett_reduction_const_2 = 0xedb88320, /* (G - x^32) * x^0 */
7072acff5fSEric Biggers #endif
7172acff5fSEric Biggers };
7272acff5fSEric Biggers 
7372acff5fSEric Biggers /*
7472acff5fSEric Biggers  * Constants generated for least-significant-bit-first CRC-32 using
7572acff5fSEric Biggers  * G(x) = x^32 + x^28 + x^27 + x^26 + x^25 + x^23 + x^22 + x^20 + x^19 + x^18 +
7672acff5fSEric Biggers  *        x^14 + x^13 + x^11 + x^10 + x^9 + x^8 + x^6 + x^0
7772acff5fSEric Biggers  */
7872acff5fSEric Biggers static const struct crc_clmul_consts crc32_lsb_0x82f63b78_consts __maybe_unused = {
7972acff5fSEric Biggers #ifdef CONFIG_64BIT
8072acff5fSEric Biggers 	.fold_across_2_longs_const_hi = 0x3743f7bd00000000, /* x^191 mod G */
8172acff5fSEric Biggers 	.fold_across_2_longs_const_lo = 0x3171d43000000000, /* x^127 mod G */
8272acff5fSEric Biggers 	.barrett_reduction_const_1 = 0x4869ec38dea713f1, /* floor(x^95 / G) */
8372acff5fSEric Biggers 	.barrett_reduction_const_2 = 0x0000000082f63b78, /* (G - x^32) * x^32 */
8472acff5fSEric Biggers #else
8572acff5fSEric Biggers 	.fold_across_2_longs_const_hi = 0x493c7d27, /* x^95 mod G */
8672acff5fSEric Biggers 	.fold_across_2_longs_const_lo = 0xdd45aab8, /* x^63 mod G */
8772acff5fSEric Biggers 	.barrett_reduction_const_1 = 0xdea713f1, /* floor(x^63 / G) */
8872acff5fSEric Biggers 	.barrett_reduction_const_2 = 0x82f63b78, /* (G - x^32) * x^0 */
8972acff5fSEric Biggers #endif
9072acff5fSEric Biggers };
91*511484faSEric Biggers 
92*511484faSEric Biggers /*
93*511484faSEric Biggers  * Constants generated for most-significant-bit-first CRC-64 using
94*511484faSEric Biggers  * G(x) = x^64 + x^62 + x^57 + x^55 + x^54 + x^53 + x^52 + x^47 + x^46 + x^45 +
95*511484faSEric Biggers  *        x^40 + x^39 + x^38 + x^37 + x^35 + x^33 + x^32 + x^31 + x^29 + x^27 +
96*511484faSEric Biggers  *        x^24 + x^23 + x^22 + x^21 + x^19 + x^17 + x^13 + x^12 + x^10 + x^9 +
97*511484faSEric Biggers  *        x^7 + x^4 + x^1 + x^0
98*511484faSEric Biggers  */
99*511484faSEric Biggers #ifdef CONFIG_64BIT
100*511484faSEric Biggers static const struct crc_clmul_consts crc64_msb_0x42f0e1eba9ea3693_consts __maybe_unused = {
101*511484faSEric Biggers 	.fold_across_2_longs_const_hi = 0x4eb938a7d257740e, /* x^192 mod G */
102*511484faSEric Biggers 	.fold_across_2_longs_const_lo = 0x05f5c3c7eb52fab6, /* x^128 mod G */
103*511484faSEric Biggers 	.barrett_reduction_const_1 = 0xabc694e836627c39, /* floor(x^127 / G) */
104*511484faSEric Biggers 	.barrett_reduction_const_2 = 0x42f0e1eba9ea3693, /* G - x^64 */
105*511484faSEric Biggers };
106*511484faSEric Biggers #endif
107*511484faSEric Biggers 
108*511484faSEric Biggers /*
109*511484faSEric Biggers  * Constants generated for least-significant-bit-first CRC-64 using
110*511484faSEric Biggers  * G(x) = x^64 + x^63 + x^61 + x^59 + x^58 + x^56 + x^55 + x^52 + x^49 + x^48 +
111*511484faSEric Biggers  *        x^47 + x^46 + x^44 + x^41 + x^37 + x^36 + x^34 + x^32 + x^31 + x^28 +
112*511484faSEric Biggers  *        x^26 + x^23 + x^22 + x^19 + x^16 + x^13 + x^12 + x^10 + x^9 + x^6 +
113*511484faSEric Biggers  *        x^4 + x^3 + x^0
114*511484faSEric Biggers  */
115*511484faSEric Biggers #ifdef CONFIG_64BIT
116*511484faSEric Biggers static const struct crc_clmul_consts crc64_lsb_0x9a6c9329ac4bc9b5_consts __maybe_unused = {
117*511484faSEric Biggers 	.fold_across_2_longs_const_hi = 0xeadc41fd2ba3d420, /* x^191 mod G */
118*511484faSEric Biggers 	.fold_across_2_longs_const_lo = 0x21e9761e252621ac, /* x^127 mod G */
119*511484faSEric Biggers 	.barrett_reduction_const_1 = 0x27ecfa329aef9f77, /* floor(x^127 / G) */
120*511484faSEric Biggers 	.barrett_reduction_const_2 = 0x9a6c9329ac4bc9b5, /* (G - x^64) * x^0 */
121*511484faSEric Biggers };
122*511484faSEric Biggers #endif
123