1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <inttypes.h>
17#include <stdio.h>
18
19#define CRC64_ECMA182_POLY 0x42F0E1EBA9EA3693ULL
20
21static uint64_t crc64_table[256] = {0};
22
23static void generate_crc64_table(void)
24{
25 uint64_t i, j, c, crc;
26
27 for (i = 0; i < 256; i++) {
28 crc = 0;
29 c = i << 56;
30
31 for (j = 0; j < 8; j++) {
32 if ((crc ^ c) & 0x8000000000000000ULL)
33 crc = (crc << 1) ^ CRC64_ECMA182_POLY;
34 else
35 crc <<= 1;
36 c <<= 1;
37 }
38
39 crc64_table[i] = crc;
40 }
41}
42
43static void print_crc64_table(void)
44{
45 int i;
46
47 printf("/* this file is generated - do not edit */\n\n");
48 printf("#include <linux/types.h>\n");
49 printf("#include <linux/cache.h>\n\n");
50 printf("static const u64 ____cacheline_aligned crc64table[256] = {\n");
51 for (i = 0; i < 256; i++) {
52 printf("\t0x%016" PRIx64 "ULL", crc64_table[i]);
53 if (i & 0x1)
54 printf(",\n");
55 else
56 printf(", ");
57 }
58 printf("};\n");
59}
60
61int main(int argc, char *argv[])
62{
63 generate_crc64_table();
64 print_crc64_table();
65 return 0;
66}
67