~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/gen_crc64table.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Generate lookup table for the table-driven CRC64 calculation.
  4  *
  5  * gen_crc64table is executed in kernel build time and generates
  6  * lib/crc64table.h. This header is included by lib/crc64.c for
  7  * the table-driven CRC64 calculation.
  8  *
  9  * See lib/crc64.c for more information about which specification
 10  * and polynomial arithmetic that gen_crc64table.c follows to
 11  * generate the lookup table.
 12  *
 13  * Copyright 2018 SUSE Linux.
 14  *   Author: Coly Li <colyli@suse.de>
 15  */
 16 #include <inttypes.h>
 17 #include <stdio.h>
 18 
 19 #define CRC64_ECMA182_POLY 0x42F0E1EBA9EA3693ULL
 20 #define CRC64_ROCKSOFT_POLY 0x9A6C9329AC4BC9B5ULL
 21 
 22 static uint64_t crc64_table[256] = {0};
 23 static uint64_t crc64_rocksoft_table[256] = {0};
 24 
 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)
 44 {
 45         uint64_t i, j, c, crc;
 46 
 47         for (i = 0; i < 256; i++) {
 48                 crc = 0;
 49                 c = i << 56;
 50 
 51                 for (j = 0; j < 8; j++) {
 52                         if ((crc ^ c) & 0x8000000000000000ULL)
 53                                 crc = (crc << 1) ^ poly;
 54                         else
 55                                 crc <<= 1;
 56                         c <<= 1;
 57                 }
 58 
 59                 table[i] = crc;
 60         }
 61 }
 62 
 63 static void output_table(uint64_t table[256])
 64 {
 65         int i;
 66 
 67         for (i = 0; i < 256; i++) {
 68                 printf("\t0x%016" PRIx64 "ULL", table[i]);
 69                 if (i & 0x1)
 70                         printf(",\n");
 71                 else
 72                         printf(", ");
 73         }
 74         printf("};\n");
 75 }
 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 
 89 int main(int argc, char *argv[])
 90 {
 91         generate_crc64_table(crc64_table, CRC64_ECMA182_POLY);
 92         generate_reflected_crc64_table(crc64_rocksoft_table, CRC64_ROCKSOFT_POLY);
 93         print_crc64_tables();
 94         return 0;
 95 }
 96 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php