From fcedfddf00b3f994e4f4e40332ac7fc192c63244 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 5 Oct 2025 21:56:51 +0700 Subject: claude is gud --- vere/ext/nasm/misc/crcgen.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 vere/ext/nasm/misc/crcgen.c (limited to 'vere/ext/nasm/misc/crcgen.c') diff --git a/vere/ext/nasm/misc/crcgen.c b/vere/ext/nasm/misc/crcgen.c new file mode 100644 index 0000000..f11e252 --- /dev/null +++ b/vere/ext/nasm/misc/crcgen.c @@ -0,0 +1,44 @@ +#include +#include + +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; +} -- cgit v1.2.3