Mercurial > crc32
annotate crc32i.h @ 3:6483683ac857 default tip
*: add profiling code too; expand x86 to use all eight XMM registers
basically ported verbatim from the assembly
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 09 Feb 2026 21:30:30 -0500 |
| parents | 90cb48b87dcc |
| children |
| 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 | |
|
3
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
16 #if (__STDC_VERSION__ >= 201112L) |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
17 # define CRC32_ALIGN(N) alignas(N) |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
18 #elif defined(__GNUC__) |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
19 # define CRC32_ALIGN(N) __attribute__((__aligned__(N))) |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
20 #elif defined(_MSC_VER) |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
21 # define CRC32_ALIGN(N) __declspec(align(N)) |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
22 #else |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
23 # error fuck |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
24 #endif |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
25 |
| 0 | 26 #ifdef __GNUC__ |
|
3
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
27 # define CRC32_FORCEINLINE static inline __attribute__((__always_inline__)) |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
28 #elif defined(_MSC_VER) |
|
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
29 # define CRC32_FORCEINLINE static __forceinline |
| 0 | 30 #else |
|
3
6483683ac857
*: add profiling code too; expand x86 to use all eight XMM registers
Paper <paper@tflc.us>
parents:
1
diff
changeset
|
31 # define CRC32_FORCEINLINE static inline |
| 0 | 32 #endif |
| 33 | |
| 34 #define ALIGNOF(type) offsetof(struct { type a; char b; }, b) | |
| 35 #define ALIGNED(ptr, alignment) (((uintptr_t)(ptr) % (alignment)) == 0) | |
| 36 #define ALIGNED_TYPE(ptr, type) ALIGNED(ptr, ALIGNOF(type)) | |
| 37 | |
| 38 typedef uint32_t (*crc32_r_spec)(uint32_t, const unsigned char *, size_t); | |
| 39 | |
| 40 /* shared by crc32c and crc32qw */ | |
| 41 extern const uint32_t crc32_tab[256]; | |
| 42 | |
|
1
90cb48b87dcc
*: don't hardcode the list of impls in multiple places
Paper <paper@tflc.us>
parents:
0
diff
changeset
|
43 /* declare */ |
|
90cb48b87dcc
*: don't hardcode the list of impls in multiple places
Paper <paper@tflc.us>
parents:
0
diff
changeset
|
44 #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
|
45 #include "crc32-impls.h" |
| 0 | 46 |
| 47 /* Maximum alignment value for each impl to work */ | |
| 48 #define MAX(x, y) ((x)>(y)?(x):(y)) | |
| 49 #define MIN(x, y) ((x)<(y)?(x):(y)) | |
| 50 #define CRC32_MAX_ALIGNMENT MAX(16, ALIGNOF(uint32_t)) | |
| 51 | |
| 52 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) | |
| 53 |
