# HG changeset patch # User Paper # Date 1770617886 18000 # Node ID 90cb48b87dcc8b601c2318ad6562f9e6f039b07c # Parent 422835bc1acaa1cc9c7ff7850d0f0231f195e04b *: don't hardcode the list of impls in multiple places diff -r 422835bc1aca -r 90cb48b87dcc README --- a/README Mon Feb 09 01:15:00 2026 -0500 +++ b/README Mon Feb 09 01:18:06 2026 -0500 @@ -8,4 +8,6 @@ may cause this code to compile slowly on some machines or compilers. At the moment it is hardcoded for x86-64 and gcc, but it could be adapted to -other compilers if they also have features like e.g. alignas() or whatever. \ No newline at end of file +other compilers if they also have features like e.g. alignas() or whatever. +You'd also need to disable the x86 code which isn't difficult but is a bit +annoying. diff -r 422835bc1aca -r 90cb48b87dcc crc32-impls.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crc32-impls.h Mon Feb 09 01:18:06 2026 -0500 @@ -0,0 +1,7 @@ +#ifndef CRC32_IMPL +# define CRC32_IMPL(name) +#endif +CRC32_IMPL(c) +CRC32_IMPL(qw) +CRC32_IMPL(x86_vpclmulqdq) +#undef CRC32_IMPL \ No newline at end of file diff -r 422835bc1aca -r 90cb48b87dcc crc32-test.c --- a/crc32-test.c Mon Feb 09 01:15:00 2026 -0500 +++ b/crc32-test.c Mon Feb 09 01:18:06 2026 -0500 @@ -11,9 +11,8 @@ #undef DOUBLE ; static const crc32_r_spec crc[] = { - crc32c_r, - crc32qw_r, - crc32x86_vpclmulqdq_r +#define CRC32_IMPL(name) crc32##name##_r, +#include "crc32-impls.h" }; size_t i; diff -r 422835bc1aca -r 90cb48b87dcc crc32i.h --- a/crc32i.h Mon Feb 09 01:15:00 2026 -0500 +++ b/crc32i.h Mon Feb 09 01:18:06 2026 -0500 @@ -29,12 +29,9 @@ /* shared by crc32c and crc32qw */ extern const uint32_t crc32_tab[256]; -/* Calculates crc32 by bytes. Has no alignment requirement */ -uint32_t crc32c_r(uint32_t crc, const unsigned char *message, size_t sz); -/* Calculates crc32 in dwords. Requires 4-byte alignment */ -uint32_t crc32qw_r(uint32_t crc, const unsigned char *message, size_t sz); -/* Calculates crc32 using intel SIMD. Requires 16-byte alignment */ -uint32_t crc32x86_vpclmulqdq_r(uint32_t crc, const unsigned char *msg, size_t sz); +/* declare */ +#define CRC32_IMPL(name) uint32_t crc32##name##_r(uint32_t, const unsigned char *, size_t); +#include "crc32-impls.h" /* Maximum alignment value for each impl to work */ #define MAX(x, y) ((x)>(y)?(x):(y))