NASM 2.15rc10
[nasm.git] / misc / crcgen.c
blobf11e252fb592134ba93f8386b73ee82a49b0f2f6
1 #include <inttypes.h>
2 #include <stdio.h>
4 int main(int argc, char *argv[])
6 /* Polynomial in bit-reversed notation */
7 uint64_t poly;
8 uint64_t crctab[256], v;
9 int i, j;
11 poly = strtoumax(argv[1], NULL, 0);
13 printf("/* C */\n");
14 printf("static const uint64_t crc64_tab[256] = {\n");
15 for (i = 0; i < 256; i++) {
16 v = i;
17 for (j = 0; j < 8; j++)
18 v = (v >> 1) ^ ((v & 1) ? poly : 0);
19 crctab[i] = v;
22 for (i = 0; i < 256; i += 2) {
23 printf(" /* %02x */ UINT64_C(0x%016"PRIx64"), "
24 "UINT64_C(0x%016"PRIx64")%s\n",
25 i, crctab[i], crctab[i+1], (i == 254) ? "" : ",");
27 printf("};\n\n");
29 printf("# perl\n");
30 printf("@crc64_tab = (\n");
31 for (i = 0; i < 256; i += 2) {
32 printf(" [0x%08"PRIx32", 0x%08"PRIx32"], "
33 "[0x%08"PRIx32", 0x%08"PRIx32"]%-1s # %02x\n",
34 (uint32_t)(crctab[i] >> 32),
35 (uint32_t)(crctab[i]),
36 (uint32_t)(crctab[i+1] >> 32),
37 (uint32_t)(crctab[i+1]),
38 (i == 254) ? "" : ",",
39 i);
41 printf(");\n");
43 return 0;