changeset 1:90cb48b87dcc

*: don't hardcode the list of impls in multiple places
author Paper <paper@tflc.us>
date Mon, 09 Feb 2026 01:18:06 -0500
parents 422835bc1aca
children ead9f84d11db
files README crc32-impls.h crc32-test.c crc32i.h
diffstat 4 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- /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
--- 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;
 
--- 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))