diff options
author | Nathan Moinvaziri <nathan@nathanm.com> | 2020-11-09 17:02:38 -0800 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2020-11-22 20:33:54 +0100 |
commit | 2eae5ba3f8003c58d0675a9f23da40d65d1d16db (patch) | |
tree | 0028544990471514ef5541024f0c46aebdbef0ba /tools | |
parent | ed88b15de28855f0506959b4ec0a38713844d756 (diff) |
Separate crc32 and crc32_combine tables so the crc32_combine tables are not included when not used if statically linking. Reduces code size by 4k.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/makecrct.c | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/tools/makecrct.c b/tools/makecrct.c index 77116f7..323d0c0 100644 --- a/tools/makecrct.c +++ b/tools/makecrct.c @@ -14,7 +14,9 @@ static uint32_t crc_comb[GF2_DIM][GF2_DIM]; static void gf2_matrix_square(uint32_t *square, const uint32_t *mat); static void make_crc_table(void); -static void print_crc32_tables(); +static void make_crc_combine_table(void); +static void print_crc_table(void); +static void print_crc_combine_table(void); static void write_table(const uint32_t *, int); @@ -52,7 +54,7 @@ static void gf2_matrix_square(uint32_t *square, const uint32_t *mat) { allow for word-at-a-time CRC calculation for both big-endian and little- endian machines, where a word is four bytes. */ -static void make_crc_table() { +static void make_crc_table(void) { int n, k; uint32_t c; uint32_t poly; /* polynomial exclusive-or pattern */ @@ -83,7 +85,10 @@ static void make_crc_table() { crc_table[k + 4][n] = ZSWAP32(c); } } +} +static void make_crc_combine_table(void) { + int n, k; /* generate zero operators table for crc32_combine() */ /* generate the operator to apply a single zero bit to a CRC -- the @@ -110,7 +115,16 @@ static void make_crc_table() { gf2_matrix_square(crc_comb[n], crc_comb[n - 1]); } -static void print_crc32_tables() { +static void write_table(const uint32_t *table, int k) { + int n; + + for (n = 0; n < k; n++) + printf("%s0x%08" PRIx32 "%s", n % 5 ? "" : " ", + (uint32_t)(table[n]), + n == k - 1 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); +} + +static void print_crc_table(void) { int k; printf("#ifndef CRC32_TBL_H_\n"); printf("#define CRC32_TBL_H_\n\n"); @@ -125,32 +139,39 @@ static void print_crc32_tables() { printf(" },\n {\n"); write_table(crc_table[k], 256); } - printf(" }\n};\n"); + printf(" }\n};\n\n"); + + printf("#endif /* CRC32_TBL_H_ */\n"); +} + +static void print_crc_combine_table(void) { + int k; + printf("#ifndef CRC32_COMB_TBL_H_\n"); + printf("#define CRC32_COMB_TBL_H_\n\n"); + printf("/* crc32_comb_tbl.h -- zero operators table for CRC combine\n"); + printf(" * Generated automatically by makecrct.c\n */\n\n"); /* print zero operator table */ - printf("\nstatic const uint32_t "); + printf("static const uint32_t "); printf("crc_comb[%d][%d] =\n{\n {\n", GF2_DIM, GF2_DIM); write_table(crc_comb[0], GF2_DIM); for (k = 1; k < GF2_DIM; k++) { printf(" },\n {\n"); write_table(crc_comb[k], GF2_DIM); } - printf(" }\n};\n"); - printf("#endif /* CRC32_TBL_H_ */\n"); -} - -static void write_table(const uint32_t *table, int k) { - int n; + printf(" }\n};\n\n"); - for (n = 0; n < k; n++) - printf("%s0x%08" PRIx32 "%s", n % 5 ? "" : " ", - (uint32_t)(table[n]), - n == k - 1 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); + printf("#endif /* CRC32_COMB_TBL_H_ */\n"); } // The output of this application can be piped out to recreate crc32.h -int main() { - make_crc_table(); - print_crc32_tables(); +int main(int argc, char *argv[]) { + if (argc > 1 && strcmp(argv[1], "-c") == 0) { + make_crc_combine_table(); + print_crc_combine_table(); + } else { + make_crc_table(); + print_crc_table(); + } return 0; } |