linux/lib/gen_crc32table.c
<<
>>
Prefs
   1#include <stdio.h>
   2#include "../include/generated/autoconf.h"
   3#include "crc32defs.h"
   4#include <inttypes.h>
   5
   6#define ENTRIES_PER_LINE 4
   7
   8#if CRC_LE_BITS > 8
   9# define LE_TABLE_ROWS (CRC_LE_BITS/8)
  10# define LE_TABLE_SIZE 256
  11#else
  12# define LE_TABLE_ROWS 1
  13# define LE_TABLE_SIZE (1 << CRC_LE_BITS)
  14#endif
  15
  16#if CRC_BE_BITS > 8
  17# define BE_TABLE_ROWS (CRC_BE_BITS/8)
  18# define BE_TABLE_SIZE 256
  19#else
  20# define BE_TABLE_ROWS 1
  21# define BE_TABLE_SIZE (1 << CRC_BE_BITS)
  22#endif
  23
  24static uint32_t crc32table_le[LE_TABLE_ROWS][256];
  25static uint32_t crc32table_be[BE_TABLE_ROWS][256];
  26static uint32_t crc32ctable_le[LE_TABLE_ROWS][256];
  27
  28/**
  29 * crc32init_le() - allocate and initialize LE table data
  30 *
  31 * crc is the crc of the byte i; other entries are filled in based on the
  32 * fact that crctable[i^j] = crctable[i] ^ crctable[j].
  33 *
  34 */
  35static void crc32init_le_generic(const uint32_t polynomial,
  36                                 uint32_t (*tab)[256])
  37{
  38        unsigned i, j;
  39        uint32_t crc = 1;
  40
  41        tab[0][0] = 0;
  42
  43        for (i = LE_TABLE_SIZE >> 1; i; i >>= 1) {
  44                crc = (crc >> 1) ^ ((crc & 1) ? polynomial : 0);
  45                for (j = 0; j < LE_TABLE_SIZE; j += 2 * i)
  46                        tab[0][i + j] = crc ^ tab[0][j];
  47        }
  48        for (i = 0; i < LE_TABLE_SIZE; i++) {
  49                crc = tab[0][i];
  50                for (j = 1; j < LE_TABLE_ROWS; j++) {
  51                        crc = tab[0][crc & 0xff] ^ (crc >> 8);
  52                        tab[j][i] = crc;
  53                }
  54        }
  55}
  56
  57static void crc32init_le(void)
  58{
  59        crc32init_le_generic(CRCPOLY_LE, crc32table_le);
  60}
  61
  62static void crc32cinit_le(void)
  63{
  64        crc32init_le_generic(CRC32C_POLY_LE, crc32ctable_le);
  65}
  66
  67/**
  68 * crc32init_be() - allocate and initialize BE table data
  69 */
  70static void crc32init_be(void)
  71{
  72        unsigned i, j;
  73        uint32_t crc = 0x80000000;
  74
  75        crc32table_be[0][0] = 0;
  76
  77        for (i = 1; i < BE_TABLE_SIZE; i <<= 1) {
  78                crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0);
  79                for (j = 0; j < i; j++)
  80                        crc32table_be[0][i + j] = crc ^ crc32table_be[0][j];
  81        }
  82        for (i = 0; i < BE_TABLE_SIZE; i++) {
  83                crc = crc32table_be[0][i];
  84                for (j = 1; j < BE_TABLE_ROWS; j++) {
  85                        crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8);
  86                        crc32table_be[j][i] = crc;
  87                }
  88        }
  89}
  90
  91static void output_table(uint32_t (*table)[256], int rows, int len, char *trans)
  92{
  93        int i, j;
  94
  95        for (j = 0 ; j < rows; j++) {
  96                printf("{");
  97                for (i = 0; i < len - 1; i++) {
  98                        if (i % ENTRIES_PER_LINE == 0)
  99                                printf("\n");
 100                        printf("%s(0x%8.8xL), ", trans, table[j][i]);
 101                }
 102                printf("%s(0x%8.8xL)},\n", trans, table[j][len - 1]);
 103        }
 104}
 105
 106int main(int argc, charA* 617kg2ef">trans, 
  
  ("%s(0/* 
	  in becrc d/autocon);
  19<09a>int9href="lib/gen_crc32table.c#L106" id="L10" classs="line" name="L10">  10<#11             ref="+code=i" classITS" class="sref">CRC_LE_BITS > 8
  11  1             }
crc32init_le_generican clef="lib/gen_crc32table.c#L100" id="L12" classs="line" name="L12">  12<#11             printf("%s(0oid   13<#11             "%s(0le_le);
<[xL)},d][xL)},d] hr/span>);
  14<#11             for (LE_TABLE_ROWS; LE_TABLE_SIZE;   15<
11                     "+code=output_table" class="sref">output_table(crc32table_le);
LE_TABLE_ROWS;   16<#11                              LE_TABLE_SIZE; "%s(0tolespan>);
  17<#11             for (printf("%s(0};);
  18<#11     }
  19<#119href="lib/gen_crc32table.c#L106" id="L20" clas1s="line" name="L20">  201#12             ref="+code=i" classITS" class="sref">CRC_BE_BITS > 8
  211#12             }
crc32init_be(void)
  12#12             printf("%s(0oid   231
12             "%s(0le_le);b<[xL)},d][xL)},d] hr/span>);
  241s12             for (BE_TABLE_ROWS; BE_TABLE_SIZE;   251s12                     "+code=output_table" class="sref">output_table(crc32table_be[LE_TABLE_ROWS;   261s12                              BE_TABLE_SIZE; "%s(0tobespan>);
  271
12             for (printf("%s(0};);
  281<12     }
  291<129            ref="+code=i" classITS" class="sref">CRC_LE_BITS > 8
  301<13                     "+code=uint32_tle_le" class="sref">crc32cinit_le(void)
  311<13             }
printf("%s(0oid   321<13                     "%s(0le_lec);
<[xL)},d][xL)},d] hr/span>);
  331<13             LE_TABLE_ROWS; LE_TABLE_SIZE;   341<13             output_table(crc32ctable_le);
LE_TABLE_ROWS;   351s13                     LE_TABLE_SIZE; "%s(0tolespan>);
  361 1                      "+code=printf" class="sref">printf("%s(0};);
  371{13     }
  381 1      ="lib/gen_crc32table.c#L48" id="1L29" clas1s="line" name="L39">  391 1      ef="lib/gen_crc32table.c#L76" id="1L40" clas1s="line" name="L40">  401
14a href="lib/gen_crc32table.c#L61" id="1L41" clas1s="line" name="L41">  411 1      
The original LXR softwed ibye i; "lib/gen_http://sourceforge.net/projects/lxr">LXR > */ua>(y hre,= iexperi/lxr@l6.9/.no hre.
lxr.l6.9/.no kindly hosconRedpill L6.pro Aa href=providerbyteL6.9/ hreultot;tialioputoce="s services since 1995.