aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/arch/x86/lib/crc-pclmul-consts.h
blob: 089954988f977d1c019fa0dd48304abe412cda18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * CRC constants generated by:
 *
 *	./scripts/gen-crc-consts.py x86_pclmul crc16_msb_0x8bb7,crc32_lsb_0xedb88320
 *
 * Do not edit manually.
 */

/*
 * CRC folding constants generated for most-significant-bit-first CRC-16 using
 * G(x) = x^16 + x^15 + x^11 + x^9 + x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0
 */
static const struct {
	u8 bswap_mask[16];
	u64 fold_across_2048_bits_consts[2];
	u64 fold_across_1024_bits_consts[2];
	u64 fold_across_512_bits_consts[2];
	u64 fold_across_256_bits_consts[2];
	u64 fold_across_128_bits_consts[2];
	u8 shuf_table[48];
	u64 barrett_reduction_consts[2];
} crc16_msb_0x8bb7_consts ____cacheline_aligned __maybe_unused = {
	.bswap_mask = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
	.fold_across_2048_bits_consts = {
		0xdccf000000000000,	/* LO64_TERMS: (x^2000 mod G) * x^48 */
		0x4b0b000000000000,	/* HI64_TERMS: (x^2064 mod G) * x^48 */
	},
	.fold_across_1024_bits_consts = {
		0x9d9d000000000000,	/* LO64_TERMS: (x^976 mod G) * x^48 */
		0x7cf5000000000000,	/* HI64_TERMS: (x^1040 mod G) * x^48 */
	},
	.fold_across_512_bits_consts = {
		0x044c000000000000,	/* LO64_TERMS: (x^464 mod G) * x^48 */
		0xe658000000000000,	/* HI64_TERMS: (x^528 mod G) * x^48 */
	},
	.fold_across_256_bits_consts = {
		0x6ee3000000000000,	/* LO64_TERMS: (x^208 mod G) * x^48 */
		0xe7b5000000000000,	/* HI64_TERMS: (x^272 mod G) * x^48 */
	},
	.fold_across_128_bits_consts = {
		0x2d56000000000000,	/* LO64_TERMS: (x^80 mod G) * x^48 */
		0x06df000000000000,	/* HI64_TERMS: (x^144 mod G) * x^48 */
	},
	.shuf_table = {
		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
		 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
	},
	.barrett_reduction_consts = {
		0x8bb7000000000000,	/* LO64_TERMS: (G - x^16) * x^48 */
		0xf65a57f81d33a48a,	/* HI64_TERMS: (floor(x^79 / G) * x) - x^64 */
	},
};

/*
 * CRC folding constants generated for least-significant-bit-first CRC-32 using
 * G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 +
 *        x^5 + x^4 + x^2 + x^1 + x^0
 */
static const struct {
	u64 fold_across_2048_bits_consts[2];
	u64 fold_across_1024_bits_consts[2];
	u64 fold_across_512_bits_consts[2];
	u64 fold_across_256_bits_consts[2];
	u64 fold_across_128_bits_consts[2];
	u8 shuf_table[48];
	u64 barrett_reduction_consts[2];
} crc32_lsb_0xedb88320_consts ____cacheline_aligned __maybe_unused = {
	.fold_across_2048_bits_consts = {
		0x00000000ce3371cb,	/* HI64_TERMS: (x^2079 mod G) * x^32 */
		0x00000000e95c1271,	/* LO64_TERMS: (x^2015 mod G) * x^32 */
	},
	.fold_across_1024_bits_consts = {
		0x0000000033fff533,	/* HI64_TERMS: (x^1055 mod G) * x^32 */
		0x00000000910eeec1,	/* LO64_TERMS: (x^991 mod G) * x^32 */
	},
	.fold_across_512_bits_consts = {
		0x000000008f352d95,	/* HI64_TERMS: (x^543 mod G) * x^32 */
		0x000000001d9513d7,	/* LO64_TERMS: (x^479 mod G) * x^32 */
	},
	.fold_across_256_bits_consts = {
		0x00000000f1da05aa,	/* HI64_TERMS: (x^287 mod G) * x^32 */
		0x0000000081256527,	/* LO64_TERMS: (x^223 mod G) * x^32 */
	},
	.fold_across_128_bits_consts = {
		0x00000000ae689191,	/* HI64_TERMS: (x^159 mod G) * x^32 */
		0x00000000ccaa009e,	/* LO64_TERMS: (x^95 mod G) * x^32 */
	},
	.shuf_table = {
		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
		 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
	},
	.barrett_reduction_consts = {
		0xb4e5b025f7011641,	/* HI64_TERMS: floor(x^95 / G) */
		0x00000001db710640,	/* LO64_TERMS: (G - x^32) * x^31 */
	},
};