Mercurial > crc32
diff crc32-test.c @ 3:6483683ac857 default tip
*: add profiling code too; expand x86 to use all eight XMM registers
basically ported verbatim from the assembly
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 09 Feb 2026 21:30:30 -0500 |
| parents | ead9f84d11db |
| children |
line wrap: on
line diff
--- a/crc32-test.c Mon Feb 09 01:21:00 2026 -0500 +++ b/crc32-test.c Mon Feb 09 21:30:30 2026 -0500 @@ -1,17 +1,22 @@ #include "crc32i.h" #include <stdio.h> +#include <inttypes.h> +#include <time.h> /* Test implementations and make sure they agree with each other */ int crc32_test(void) { /* Force alignment :) */ - static const __attribute__((__aligned__(CRC32_MAX_ALIGNMENT))) unsigned char testdata[1024] = + static const CRC32_ALIGN(CRC32_MAX_ALIGNMENT) unsigned char testdata[(1ul << 23) + 19] = #define DOUBLE(x) x x -DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE("\x01\x02\x04\x08\x10\x20\x40\x80"))))))) +DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE("\x01\x02\x04\x08\x10\x20\x40\x80")))))))) #undef DOUBLE ; - static const crc32_r_spec crc[] = { -#define CRC32_IMPL(name) crc32##name##_r, + static const struct { + crc32_r_spec f; + const char *name; + } crc[] = { +#define CRC32_IMPL(name) {crc32##name##_r, #name}, #include "crc32-impls.h" }; size_t i; @@ -19,10 +24,18 @@ uint32_t crcc = crc32(testdata, sizeof(testdata)); for (i = 0; i < ARRAY_SIZE(crc); i++) { - uint32_t thiscrc = ~crc[i](0xFFFFFFFF, testdata, sizeof(testdata)); + clock_t start, end; + + start = clock(); + uint32_t thiscrc = crc[i].f(0xFFFFFFFF, testdata, sizeof(testdata)); + end = clock(); + + printf("%s: took %f secs\n", crc[i].name, (double)(end - start) / CLOCKS_PER_SEC); + + thiscrc = ~thiscrc; if (thiscrc != crcc) { - fprintf(stderr, "%zu, mismatch: %08" PRIX32 ", %08" PRIx32 "\n", i, crcc, thiscrc); + fprintf(stderr, "%s: mismatch: %08" PRIX32 ", %08" PRIx32 "\n", crc[i].name, crcc, thiscrc); return -1; } }
