summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-07-16 10:20:14 -0400
committerH. Peter Anvin <hpa@zytor.com>2009-07-16 10:20:14 -0400
commit395d3811143d61f6d0765e678d766185981aae97 (patch)
treeab5906857aa42ded87daae4dba0ec55c3fee10f5 /misc
parent80d0fd371f4d70d68ea76e60b79e0845544e230a (diff)
downloadnasm-395d3811143d61f6d0765e678d766185981aae97.tar.gz
crcgen: utility program to generate CRC tables
Small utility program to generate CRC tables in both C and Perl formats. Note: we don't actually need a true CRC, which is what this generates. We may want to consider going to a "generalized CRC", meaning a randomly generated set of 8 bytewise permutations. These have the advantage of not being linear, while having the same software implementation as a true CRC. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'misc')
-rw-r--r--misc/crcgen.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/misc/crcgen.c b/misc/crcgen.c
new file mode 100644
index 00000000..df8b0c30
--- /dev/null
+++ b/misc/crcgen.c
@@ -0,0 +1,47 @@
+#include <inttypes.h>
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ /* Polynomial in bit-reversed notation */
+ uint64_t poly;
+ uint64_t crctab[256], v;
+ int i, j;
+
+ poly = strtoumax(argv[1], NULL, 0);
+
+ printf("/* C */\n");
+ printf("static const uint64_t crc64_tab[256] = {\n");
+ for (i = 0; i < 256; i++) {
+ v = i;
+ for (j = 0; j < 8; j++)
+ v = (v >> 1) ^ ((v & 1) ? poly : 0);
+ crctab[i] = v;
+ }
+
+ for (i = 0; i < 256; i += 2) {
+ printf(" /* %02x */ UINT64_C(0x%016"PRIx64"), "
+ "UINT64_C(0x%016"PRIx64")%s\n",
+ i, crctab[i], crctab[i+1], (i == 254) ? "" : ",");
+ }
+ printf("};\n\n");
+
+ printf("# perl\n");
+ printf("@crc64_tab = (\n");
+ for (i = 0; i < 256; i += 2) {
+ printf(" [0x%08"PRIx32", 0x%08"PRIx32"], "
+ "[0x%08"PRIx32", 0x%08"PRIx32"]%-1s # %02x\n",
+ (uint32_t)(crctab[i] >> 32),
+ (uint32_t)(crctab[i]),
+ (uint32_t)(crctab[i+1] >> 32),
+ (uint32_t)(crctab[i+1]),
+ (i == 254) ? "" : ",",
+ i);
+ }
+ printf(");\n");
+
+ return 0;
+}
+
+
+