annotate crc32i.h @ 0:422835bc1aca

*: checkin
author Paper <paper@tflc.us>
date Mon, 09 Feb 2026 01:15:00 -0500
parents
children 90cb48b87dcc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
1 /* internal crc32 definitions */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
2
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
3 #include "crc32.h"
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
4
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
5 #define CRC32_API __attribute__((__visibility__("default")))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
6
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
7 /* all LUTs etc. are generated at compile time.
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
8 * eventually, I'd like to have all internal info
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
9 * stored in one opaque pointer. this pointer will
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
10 * contain the LUTs (or maybe a pointer to one).
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
11 * We could also create these structures at compile
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
12 * time and have a flag that says whether it needs
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
13 * to be destroyed or if it can be cached. */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
14 #define CRC32_POLYNOMIAL 0xedb88320
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
15
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
16 /* crc32b.c */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
17 #ifdef __GNUC__
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
18 # define CRC32_PURE __attribute__((__pure__))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
19 #else
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
20 # define CRC32_PURE
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
21 #endif
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
22
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
23 #define ALIGNOF(type) offsetof(struct { type a; char b; }, b)
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
24 #define ALIGNED(ptr, alignment) (((uintptr_t)(ptr) % (alignment)) == 0)
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
25 #define ALIGNED_TYPE(ptr, type) ALIGNED(ptr, ALIGNOF(type))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
26
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
27 typedef uint32_t (*crc32_r_spec)(uint32_t, const unsigned char *, size_t);
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
28
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
29 /* shared by crc32c and crc32qw */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
30 extern const uint32_t crc32_tab[256];
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
31
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
32 /* Calculates crc32 by bytes. Has no alignment requirement */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
33 uint32_t crc32c_r(uint32_t crc, const unsigned char *message, size_t sz);
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
34 /* Calculates crc32 in dwords. Requires 4-byte alignment */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
35 uint32_t crc32qw_r(uint32_t crc, const unsigned char *message, size_t sz);
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
36 /* Calculates crc32 using intel SIMD. Requires 16-byte alignment */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
37 uint32_t crc32x86_vpclmulqdq_r(uint32_t crc, const unsigned char *msg, size_t sz);
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
38
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
39 /* Maximum alignment value for each impl to work */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
40 #define MAX(x, y) ((x)>(y)?(x):(y))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
41 #define MIN(x, y) ((x)<(y)?(x):(y))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
42 #define CRC32_MAX_ALIGNMENT MAX(16, ALIGNOF(uint32_t))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
43
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
44 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
45