changeset 2:ead9f84d11db

*: make it work on non-x86 too
author Paper <paper@tflc.us>
date Mon, 09 Feb 2026 01:21:00 -0500
parents 90cb48b87dcc
children 6483683ac857
files README crc32-impls.h crc32-test.c crc32x86.c
diffstat 4 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/README	Mon Feb 09 01:18:06 2026 -0500
+++ b/README	Mon Feb 09 01:21:00 2026 -0500
@@ -7,7 +7,9 @@
 through a combination of enums and preprocessor trickery. Note that this
 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.
-You'd also need to disable the x86 code which isn't difficult but is a bit
-annoying.
+At the moment it is hardcoded for gcc, but it could be adapted to other
+compilers if they also have features like e.g. alignas() or whatever.
+The code relies on C99 stdint.h but if that's not available you can just
+typedef to the suitable C89 types on your system.
+
+--paper <paper@tflc.us>
--- a/crc32-impls.h	Mon Feb 09 01:18:06 2026 -0500
+++ b/crc32-impls.h	Mon Feb 09 01:21:00 2026 -0500
@@ -3,5 +3,7 @@
 #endif
 CRC32_IMPL(c)
 CRC32_IMPL(qw)
+#ifdef __x86_64__
 CRC32_IMPL(x86_vpclmulqdq)
+#endif
 #undef CRC32_IMPL
\ No newline at end of file
--- a/crc32-test.c	Mon Feb 09 01:18:06 2026 -0500
+++ b/crc32-test.c	Mon Feb 09 01:21:00 2026 -0500
@@ -22,7 +22,7 @@
 		uint32_t thiscrc = ~crc[i](0xFFFFFFFF, testdata, sizeof(testdata));
 
 		if (thiscrc != crcc) {
-			fprintf(stderr, "%zu, mismatch: %08x, %08x\n", i, crcc, thiscrc);
+			fprintf(stderr, "%zu, mismatch: %08" PRIX32 ", %08" PRIx32 "\n", i, crcc, thiscrc);
 			return -1;
 		}
 	}
--- a/crc32x86.c	Mon Feb 09 01:18:06 2026 -0500
+++ b/crc32x86.c	Mon Feb 09 01:21:00 2026 -0500
@@ -1,5 +1,7 @@
 /* x86-specific CRC routines */
 
+#ifdef __x86_64__
+
 #include "crc32.h"
 #include "crc32i.h"
 #include <stdio.h>
@@ -201,3 +203,5 @@
 	 * need to align any more (or use crc32c_r). */
 	return crc32qw_r(crc, msg, sz);
 }
+
+#endif