Mercurial > crc32
annotate crc32i.h @ 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 |
| rev | line source |
|---|---|
| 0 | 1 /* internal crc32 definitions */ |
| 2 | |
| 3 #include "crc32.h" | |
| 4 | |
| 5 #define CRC32_API __attribute__((__visibility__("default"))) | |
| 6 | |
| 7 /* all LUTs etc. are generated at compile time. | |
| 8 * eventually, I'd like to have all internal info | |
| 9 * stored in one opaque pointer. this pointer will | |
| 10 * contain the LUTs (or maybe a pointer to one). | |
| 11 * We could also create these structures at compile | |
| 12 * time and have a flag that says whether it needs | |
| 13 * to be destroyed or if it can be cached. */ | |
| 14 #define CRC32_POLYNOMIAL 0xedb88320 | |
| 15 | |
| 16 /* crc32b.c */ | |
| 17 #ifdef __GNUC__ | |
| 18 # define CRC32_PURE __attribute__((__pure__)) | |
| 19 #else | |
| 20 # define CRC32_PURE | |
| 21 #endif | |
| 22 | |
| 23 #define ALIGNOF(type) offsetof(struct { type a; char b; }, b) | |
| 24 #define ALIGNED(ptr, alignment) (((uintptr_t)(ptr) % (alignment)) == 0) | |
| 25 #define ALIGNED_TYPE(ptr, type) ALIGNED(ptr, ALIGNOF(type)) | |
| 26 | |
| 27 typedef uint32_t (*crc32_r_spec)(uint32_t, const unsigned char *, size_t); | |
| 28 | |
| 29 /* shared by crc32c and crc32qw */ | |
| 30 extern const uint32_t crc32_tab[256]; | |
| 31 | |
|
1
90cb48b87dcc
*: don't hardcode the list of impls in multiple places
Paper <paper@tflc.us>
parents:
0
diff
changeset
|
32 /* declare */ |
|
90cb48b87dcc
*: don't hardcode the list of impls in multiple places
Paper <paper@tflc.us>
parents:
0
diff
changeset
|
33 #define CRC32_IMPL(name) uint32_t crc32##name##_r(uint32_t, const unsigned char *, size_t); |
|
90cb48b87dcc
*: don't hardcode the list of impls in multiple places
Paper <paper@tflc.us>
parents:
0
diff
changeset
|
34 #include "crc32-impls.h" |
| 0 | 35 |
| 36 /* Maximum alignment value for each impl to work */ | |
| 37 #define MAX(x, y) ((x)>(y)?(x):(y)) | |
| 38 #define MIN(x, y) ((x)<(y)?(x):(y)) | |
| 39 #define CRC32_MAX_ALIGNMENT MAX(16, ALIGNOF(uint32_t)) | |
| 40 | |
| 41 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) | |
| 42 |
