annotate crc32-table.c @ 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 422835bc1aca
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
1 #include "crc32i.h"
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
2
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
3 /* This builds our CRC table at compile-time rather than runtime.
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
4 * Note: We should have a way to change the polynomial at runtime too. */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
5
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
6 #define CRC32_MASK(crc) (-((crc) & 1))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
7
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
8 /* Does one iteration of the 8-time loop to generate one byte of the CRC table. */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
9 #define CRC32_PRECALC_EX(crc) (((crc) >> 1) ^ ((CRC32_POLYNOMIAL) & CRC32_MASK(crc)))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
10
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
11 /* Does all eight iterations of the loop to generate one byte. */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
12 #define CRC32_PRECALC_E(byte) \
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
13 (CRC32_PRECALC_EX(CRC32_PRECALC_EX(CRC32_PRECALC_EX(CRC32_PRECALC_EX(CRC32_PRECALC_EX(CRC32_PRECALC_EX(CRC32_PRECALC_EX(CRC32_PRECALC_EX(byte)))))))))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
14
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
15 /* Simple wrapper of CRC32_PRECALC_E that converts everything to uint32_t */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
16 #define CRC32_PRECALC(byte) \
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
17 CRC32_PRECALC_E((uint32_t)(byte))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
18
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
19 #define CRC32_PRECALC_0(byte) \
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
20 CRC32_PRECALC(byte), CRC32_PRECALC((byte) | 0x01)
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
21
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
22 #define CRC32_PRECALC_1(byte) \
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
23 CRC32_PRECALC_0(byte), CRC32_PRECALC_0((byte) | UINT32_C(0x02))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
24
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
25 #define CRC32_PRECALC_2(byte) \
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
26 CRC32_PRECALC_1(byte), CRC32_PRECALC_1((byte) | UINT32_C(0x04))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
27
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
28 #define CRC32_PRECALC_3(byte) \
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
29 CRC32_PRECALC_2(byte), CRC32_PRECALC_2((byte) | UINT32_C(0x08))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
30
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
31 #define CRC32_PRECALC_4(byte) \
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
32 CRC32_PRECALC_3(byte), CRC32_PRECALC_3((byte) | UINT32_C(0x10))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
33
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
34 #define CRC32_PRECALC_5(byte) \
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
35 CRC32_PRECALC_4(byte), CRC32_PRECALC_4((byte) | UINT32_C(0x20))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
36
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
37 #define CRC32_PRECALC_6(byte) \
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
38 CRC32_PRECALC_5(byte), CRC32_PRECALC_5((byte) | UINT32_C(0x40))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
39
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
40 #define CRC32_PRECALC_7(byte) \
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
41 CRC32_PRECALC_6(byte), CRC32_PRECALC_6((byte) | UINT32_C(0x80))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
42
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
43 const uint32_t crc32_tab[256] = {
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
44 CRC32_PRECALC_7(0)
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
45 };
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
46
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
47 #undef CRC32_MASK
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
48 #undef CRC32_PRECALC_EX
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
49 #undef CRC32_PRECALC_E
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
50 #undef CRC32_PRECALC
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
51 #undef CRC32_PRECALC_0
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
52 #undef CRC32_PRECALC_1
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
53 #undef CRC32_PRECALC_2
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
54 #undef CRC32_PRECALC_3
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
55 #undef CRC32_PRECALC_4
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
56 #undef CRC32_PRECALC_5
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
57 #undef CRC32_PRECALC_6
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
58 #undef CRC32_PRECALC_7