Skip to content
Snippets Groups Projects
Select Git revision
  • a1eae7800eb73b76fb604d5510cbc42a5265be86
  • master default protected
  • android-msm-bullhead-3.10-nougat_kgdb_less_changes
  • android-msm-bullhead-3.10-nougat_kgdb
  • android-msm-bullhead-3.10-nougat_klist
  • android-4.4
  • android-msm-vega-4.4-oreo-daydream
  • android-msm-wahoo-4.4-p-preview-5
  • android-msm-wahoo-4.4-pie
  • android-msm-marlin-3.18-p-preview-5
  • android-msm-marlin-3.18-pie
  • android-msm-wahoo-2018.07-oreo-m2
  • android-msm-wahoo-2018.07-oreo-m4
  • android-msm-wahoo-4.4-p-preview-4
  • android-msm-bullhead-3.10-oreo-m6
  • android-msm-angler-3.10-oreo-m6
  • android-msm-marlin-3.18-p-preview-4
  • android-msm-stargazer-3.18-oreo-wear-dr
  • android-msm-catshark-3.18-oreo-wear-dr
  • android-msm-wahoo-4.4-oreo-m2
  • android-msm-wahoo-4.4-oreo-m4
  • android-daydreamos-8.0.0_r0.5
  • android-8.1.0_r0.92
  • android-8.1.0_r0.91
  • android-daydreamos-8.0.0_r0.4
  • android-p-preview-5_r0.2
  • android-p-preview-5_r0.1
  • android-9.0.0_r0.5
  • android-9.0.0_r0.4
  • android-9.0.0_r0.2
  • android-9.0.0_r0.1
  • android-8.1.0_r0.81
  • android-8.1.0_r0.80
  • android-8.1.0_r0.78
  • android-8.1.0_r0.76
  • android-8.1.0_r0.75
  • android-8.1.0_r0.72
  • android-8.1.0_r0.70
  • android-p-preview-4_r0.2
  • android-p-preview-4_r0.1
  • android-wear-8.0.0_r0.30
41 results

gen_crc32table.c

Blame
  • user avatar
    Darrick J. Wong authored and Linus Torvalds committed
    Reuse the existing crc32 code to stamp out a crc32c implementation.
    
    Signed-off-by: default avatarDarrick J. Wong <djwong@us.ibm.com>
    Cc: Herbert Xu <herbert@gondor.apana.org.au>
    Cc: Bob Pearson <rpearson@systemfabricworks.com>
    Cc: Randy Dunlap <rdunlap@xenotime.net>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    46c5801e
    History
    gen_crc32table.c 3.24 KiB
    #include <stdio.h>
    #include "../include/generated/autoconf.h"
    #include "crc32defs.h"
    #include <inttypes.h>
    
    #define ENTRIES_PER_LINE 4
    
    #if CRC_LE_BITS > 8
    # define LE_TABLE_ROWS (CRC_LE_BITS/8)
    # define LE_TABLE_SIZE 256
    #else
    # define LE_TABLE_ROWS 1
    # define LE_TABLE_SIZE (1 << CRC_LE_BITS)
    #endif
    
    #if CRC_BE_BITS > 8
    # define BE_TABLE_ROWS (CRC_BE_BITS/8)
    # define BE_TABLE_SIZE 256
    #else
    # define BE_TABLE_ROWS 1
    # define BE_TABLE_SIZE (1 << CRC_BE_BITS)
    #endif
    
    static uint32_t crc32table_le[LE_TABLE_ROWS][256];
    static uint32_t crc32table_be[BE_TABLE_ROWS][256];
    static uint32_t crc32ctable_le[LE_TABLE_ROWS][256];
    
    /**
     * crc32init_le() - allocate and initialize LE table data
     *
     * crc is the crc of the byte i; other entries are filled in based on the
     * fact that crctable[i^j] = crctable[i] ^ crctable[j].
     *
     */
    static void crc32init_le_generic(const uint32_t polynomial,
    				 uint32_t (*tab)[256])
    {
    	unsigned i, j;
    	uint32_t crc = 1;
    
    	tab[0][0] = 0;
    
    	for (i = LE_TABLE_SIZE >> 1; i; i >>= 1) {
    		crc = (crc >> 1) ^ ((crc & 1) ? polynomial : 0);
    		for (j = 0; j < LE_TABLE_SIZE; j += 2 * i)
    			tab[0][i + j] = crc ^ tab[0][j];
    	}
    	for (i = 0; i < LE_TABLE_SIZE; i++) {
    		crc = tab[0][i];
    		for (j = 1; j < LE_TABLE_ROWS; j++) {
    			crc = tab[0][crc & 0xff] ^ (crc >> 8);
    			tab[j][i] = crc;
    		}
    	}
    }
    
    static void crc32init_le(void)
    {
    	crc32init_le_generic(CRCPOLY_LE, crc32table_le);
    }
    
    static void crc32cinit_le(void)
    {
    	crc32init_le_generic(CRC32C_POLY_LE, crc32ctable_le);
    }
    
    /**
     * crc32init_be() - allocate and initialize BE table data
     */
    static void crc32init_be(void)
    {
    	unsigned i, j;
    	uint32_t crc = 0x80000000;
    
    	crc32table_be[0][0] = 0;
    
    	for (i = 1; i < BE_TABLE_SIZE; i <<= 1) {
    		crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0);
    		for (j = 0; j < i; j++)
    			crc32table_be[0][i + j] = crc ^ crc32table_be[0][j];
    	}
    	for (i = 0; i < BE_TABLE_SIZE; i++) {
    		crc = crc32table_be[0][i];
    		for (j = 1; j < BE_TABLE_ROWS; j++) {
    			crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8);
    			crc32table_be[j][i] = crc;
    		}
    	}
    }
    
    static void output_table(uint32_t (*table)[256], int rows, int len, char *trans)
    {
    	int i, j;
    
    	for (j = 0 ; j < rows; j++) {
    		printf("{");
    		for (i = 0; i < len - 1; i++) {
    			if (i % ENTRIES_PER_LINE == 0)
    				printf("\n");
    			printf("%s(0x%8.8xL), ", trans, table[j][i]);
    		}
    		printf("%s(0x%8.8xL)},\n", trans, table[j][len - 1]);
    	}
    }
    
    int main(int argc, char** argv)
    {
    	printf("/* this file is generated - do not edit */\n\n");
    
    	if (CRC_LE_BITS > 1) {
    		crc32init_le();
    		printf("static const u32 __cacheline_aligned "
    		       "crc32table_le[%d][%d] = {",
    		       LE_TABLE_ROWS, LE_TABLE_SIZE);
    		output_table(crc32table_le, LE_TABLE_ROWS,
    			     LE_TABLE_SIZE, "tole");
    		printf("};\n");
    	}
    
    	if (CRC_BE_BITS > 1) {
    		crc32init_be();
    		printf("static const u32 __cacheline_aligned "
    		       "crc32table_be[%d][%d] = {",
    		       BE_TABLE_ROWS, BE_TABLE_SIZE);
    		output_table(crc32table_be, LE_TABLE_ROWS,
    			     BE_TABLE_SIZE, "tobe");
    		printf("};\n");
    	}
    	if (CRC_LE_BITS > 1) {
    		crc32cinit_le();
    		printf("static const u32 __cacheline_aligned "
    		       "crc32ctable_le[%d][%d] = {",
    		       LE_TABLE_ROWS, LE_TABLE_SIZE);
    		output_table(crc32ctable_le, LE_TABLE_ROWS,
    			     LE_TABLE_SIZE, "tole");
    		printf("};\n");
    	}
    
    	return 0;
    }