Permalink
Browse files

Add crcgen, which generates C code for each CRC definition.

crcgen generates a separate .h and .c file for each CRC
definition read from stdin. The source files are put in the src/
subdirectory. Test code is also generated and run by make test.
  • Loading branch information...
1 parent 15037a5 commit 6fe9f8c415f70b6b134699150da0dfb1e79e23bb @madler committed Jul 17, 2016
Showing with 493 additions and 31 deletions.
  1. +2 −0 .gitignore
  2. +10 −4 Makefile
  3. +33 −27 README.md
  4. +448 −0 crcgen.c
View
@@ -1,3 +1,5 @@
*.o
crcany
+crcgen
mincrc
+src/
View
@@ -1,14 +1,20 @@
-CFLAGS=-O3 -Wall -Wall -Wextra -Wcast-qual
-all: crcany mincrc
+CFLAGS=-O3 -Wall -Wextra -Wcast-qual
+all: crcany crcgen mincrc
crcany: crcany.o crc.o crcdbl.o model.o
crcany.o: crcany.c crc.h crcdbl.h model.h
+crcgen: crcgen.o crc.o model.o
+crcgen.o: crcgen.c crc.h model.h
mincrc: mincrc.o model.o
mincrc.o: mincrc.c model.h
crc.o: crc.c crc.h model.h
crcdbl.o: crcdbl.c crcdbl.h crc.h model.h
model.o: model.c model.h
-test: crcany mincrc
+test: crcany crcgen mincrc
./crcany < allcrcs-abbrev.txt
+ @rm -rf src
+ ./crcgen < allcrcs.txt
+ $(CC) $(CFLAGS) -o src/crc_test src/*.c
+ src/crc_test
./mincrc < allcrcs.txt | cmp - allcrcs-abbrev.txt
clean:
- @rm -f *.o crcany mincrc
+ @rm -rf *.o crcany crcgen mincrc src
View
@@ -1,47 +1,53 @@
Synopsis
--------
-_crcany_ can compute any CRC, given the parameters that describe it.
-Those parameters are given in the form used on Greg Cook's catalog
-of CRCs at http://reveng.sourceforge.net/crc-catalogue/all.htm , where
-that set of parameters were first defined by Ross Williams in his
-excellent tutorial on CRCs at http://zlib.net/crc_v3.txt .
-
-_crcany_ computes each CRC three different ways. First, computing a
-bit at a time, as you would in any self-respecting hardware
-implementation. Second, using the bit-at-a-time algorithm to create
-a table of 256 CRCs that can be used to compute that CRC a byte at a
-time. Third, using the byte-wise table to generate another _n-1_
-tables, where _n_ is the number of bytes in the largest
-integer, to enable computing a CRC a word at a time. The word-wise
-approach has two flavors, one for little-endian machines, and one
-for big-endian machines.
-
-The bit-wise calculation can be done on CRCs up to twice the word
-length, e.g. 128 bits on machines with 64-bit integers. The byte
-and word-wise calculations can be done on CRCs up to the word size,
-e.g. up to 64-bit CRCs using 64-bit integers.
+_crcany_ can compute any CRC, given the parameters that describe it. Those
+parameters are given in the form used on Greg Cook's catalog of CRCs at
+http://reveng.sourceforge.net/crc-catalogue/all.htm , where that set of
+parameters were first defined by Ross Williams in his excellent tutorial on
+CRCs at http://zlib.net/crc_v3.txt .
+
+_crcany_ computes each CRC three different ways. First, computing a bit at a
+time, as you would in any self-respecting hardware implementation. Second,
+using the bit-at-a-time algorithm to create a table of 256 CRCs that can be
+used to compute that CRC a byte at a time. Third, using the byte-wise table to
+generate another _n-1_ tables, where _n_ is the number of bytes in the largest
+integer, to enable computing a CRC a word at a time. The word-wise approach has
+two flavors, one for little-endian machines, and one for big-endian machines.
+
+The bit-wise calculation can be done on CRCs up to twice the word length, e.g.
+128 bits on machines with 64-bit integers. The byte and word-wise calculations
+can be done on CRCs up to the word size, e.g. up to 64-bit CRCs using 64-bit
+integers.
+
+_crcgen_ generates C code for each CRC definition read from stdin, putting the
+resulting code into .h and .c files for each definition in the src/
+subdirectory. Test code is also generated in src/crc_test.c. Code is generated
+for the machine being run on (e.g. with respect to the lengths of the integer
+types), and will generate code for any CRC whose width is less than or equal to
+the maximum integer size. The generated code provides both bit-wise and
+byte-wise routines.
Motivation
----------
-Provide once and for all a definitive reference for how to compute any
-CRC with any of bit, byte, or word-at-a-time algorithms, on any big or
-little-endian architecture. This code can then be dissected to produce
-specialized code for any application.
+Provide once and for all a definitive reference for how to compute any CRC with
+any of bit, byte, or word-at-a-time algorithms, on any big or little-endian
+architecture.
Installation
------------
-This will compile the crcany and mincrc executables:
+This will compile the crcany, crcgen, and mincrc executables:
make
Test
----
-Test crcany using the list of all catalogued CRCs, available here in the file
-allcrcs.txt, and test mincrc against the abbreviated list using the Makefile:
+Test crcany and crcgen using the list of all catalogued CRCs, available here in
+the file allcrcs.txt, and test mincrc against the abbreviated list using the
+Makefile:
make test
Oops, something went wrong.

0 comments on commit 6fe9f8c

Please sign in to comment.