| @@ -17,10 +17,30 @@ · 16 unmodified lines |
| 17 | #include <stdio.h> | 17 | #include <stdio.h> |
| 18 | | 18 | |
| 19 | #define CRC64_ECMA182_POLY 0x42F0E1EBA9EA3693ULL | 19 | #define CRC64_ECMA182_POLY 0x42F0E1EBA9EA3693ULL |
| | 20 | #define CRC64_ROCKSOFT_POLY 0x9A6C9329AC4BC9B5ULL |
| 20 | | 21 | |
| 21 | static uint64_t crc64_table[256] = {0}; | 22 | static uint64_t crc64_table[256] = {0}; |
| | 23 | static uint64_t crc64_rocksoft_table[256] = {0}; |
| 22 | | 24 | |
| 23 | static void generate_crc64_table(void) | 25 | static void generate_reflected_crc64_table(uint64_t table[256], uint64_t poly) |
| | 26 | { |
| | 27 | uint64_t i, j, c, crc; |
| | 28 | |
| | 29 | for (i = 0; i < 256; i++) { |
| | 30 | crc = 0ULL; |
| | 31 | c = i; |
| | 32 | |
| | 33 | for (j = 0; j < 8; j++) { |
| | 34 | if ((crc ^ (c >> j)) & 1) |
| | 35 | crc = (crc >> 1) ^ poly; |
| | 36 | else |
| | 37 | crc >>= 1; |
| | 38 | } |
| | 39 | table[i] = crc; |
| | 40 | } |
| | 41 | } |
| | 42 | |
| | 43 | static void generate_crc64_table(uint64_t table[256], uint64_t poly) |
| 24 | { | 44 | { |
| 25 | uint64_t i, j, c, crc; | 45 | uint64_t i, j, c, crc; |
| 26 | | 46 | |
| @@ -30,26 +50,22 @@ static void generate_crc64_table(void) · 3 unmodified lines |
| 30 | | 50 | |
| 31 | for (j = 0; j < 8; j++) { | 51 | for (j = 0; j < 8; j++) { |
| 32 | if ((crc ^ c) & 0x8000000000000000ULL) | 52 | if ((crc ^ c) & 0x8000000000000000ULL) |
| 33 | crc = (crc << 1) ^ CRC64_ECMA182_POLY; | 53 | crc = (crc << 1) ^ poly; |
| 34 | else | 54 | else |
| 35 | crc <<= 1; | 55 | crc <<= 1; |
| 36 | c <<= 1; | 56 | c <<= 1; |
| 37 | } | 57 | } |
| 38 | | 58 | |
| 39 | crc64_table[i] = crc; | 59 | table[i] = crc; |
| 40 | } | 60 | } |
| 41 | } | 61 | } |
| 42 | | 62 | |
| 43 | static void print_crc64_table(void) | 63 | static void output_table(uint64_t table[256]) |
| 44 | { | 64 | { |
| 45 | int i; | 65 | int i; |
| 46 | | 66 | |
| 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++) { | 67 | for (i = 0; i < 256; i++) { |
| 52 | printf("\t0x%016" PRIx64 "ULL", crc64_table[i]); | 68 | printf("\t0x%016" PRIx64 "ULL", table[i]); |
| 53 | if (i & 0x1) | 69 | if (i & 0x1) |
| 54 | printf(",\n"); | 70 | printf(",\n"); |
| 55 | else | 71 | else |
| @@ -58,9 +74,22 @@ static void print_crc64_table(void) · 2 unmodified lines |
| 58 | printf("};\n"); | 74 | printf("};\n"); |
| 59 | } | 75 | } |
| 60 | | 76 | |
| | 77 | static void print_crc64_tables(void) |
| | 78 | { |
| | 79 | printf("/* this file is generated - do not edit */\n\n"); |
| | 80 | printf("#include <linux/types.h>\n"); |
| | 81 | printf("#include <linux/cache.h>\n\n"); |
| | 82 | printf("static const u64 ____cacheline_aligned crc64table[256] = {\n"); |
| | 83 | output_table(crc64_table); |
| | 84 | |
| | 85 | printf("\nstatic const u64 ____cacheline_aligned crc64rocksofttable[256] = {\n"); |
| | 86 | output_table(crc64_rocksoft_table); |
| | 87 | } |
| | 88 | |
| 61 | int main(int argc, char *argv[]) | 89 | int main(int argc, char *argv[]) |
| 62 | { | 90 | { |
| 63 | generate_crc64_table(); | 91 | generate_crc64_table(crc64_table, CRC64_ECMA182_POLY); |
| 64 | print_crc64_table(); | 92 | generate_reflected_crc64_table(crc64_rocksoft_table, CRC64_ROCKSOFT_POLY); |
| | 93 | print_crc64_tables(); |
| 65 | return 0; | 94 | return 0; |
| 66 | } | 95 | } |