]>
Commit | Line | Data |
---|---|---|
033c3384 DW |
1 | /* |
2 | * There are multiple 16-bit CRC polynomials in common use, but this is | |
3 | * *the* standard CRC-32 polynomial, first popularized by Ethernet. | |
4 | * x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0 | |
5 | */ | |
6 | #define CRCPOLY_LE 0xedb88320 | |
7 | #define CRCPOLY_BE 0x04c11db7 | |
8 | ||
db8bbf27 DW |
9 | /* |
10 | * This is the CRC32c polynomial, as outlined by Castagnoli. | |
11 | * x^32+x^28+x^27+x^26+x^25+x^23+x^22+x^20+x^19+x^18+x^14+x^13+x^11+x^10+x^9+ | |
12 | * x^8+x^6+x^0 | |
13 | */ | |
033c3384 DW |
14 | #define CRC32C_POLY_LE 0x82F63B78 |
15 | #define CRC32C_POLY_BE 0x1EDC6F41 | |
db8bbf27 DW |
16 | |
17 | /* How many bits at a time to use. Valid values are 1, 2, 4, 8, 32 and 64. */ | |
18 | /* For less performance-sensitive, use 4 */ | |
19 | #ifndef CRC_LE_BITS | |
20 | # define CRC_LE_BITS 64 | |
21 | #endif | |
22 | #ifndef CRC_BE_BITS | |
23 | # define CRC_BE_BITS 64 | |
24 | #endif | |
25 | ||
26 | /* | |
27 | * Little-endian CRC computation. Used with serial bit streams sent | |
28 | * lsbit-first. Be sure to use cpu_to_le32() to append the computed CRC. | |
29 | */ | |
30 | #if CRC_LE_BITS > 64 || CRC_LE_BITS < 1 || CRC_LE_BITS == 16 || \ | |
31 | CRC_LE_BITS & CRC_LE_BITS-1 | |
32 | # error "CRC_LE_BITS must be one of {1, 2, 4, 8, 32, 64}" | |
33 | #endif | |
34 | ||
35 | /* | |
36 | * Big-endian CRC computation. Used with serial bit streams sent | |
37 | * msbit-first. Be sure to use cpu_to_be32() to append the computed CRC. | |
38 | */ | |
39 | #if CRC_BE_BITS > 64 || CRC_BE_BITS < 1 || CRC_BE_BITS == 16 || \ | |
40 | CRC_BE_BITS & CRC_BE_BITS-1 | |
41 | # error "CRC_BE_BITS must be one of {1, 2, 4, 8, 32, 64}" | |
42 | #endif | |
43 | ||
44 | ||
45 | #define ___constant_swab32(x) \ | |
46 | ((uint32_t)( \ | |
47 | (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ | |
48 | (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ | |
49 | (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ | |
50 | (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))) | |
51 | ||
52 | ||
db8bbf27 DW |
53 | #if (__GNUC__ >= 3) |
54 | #define likely(x) __builtin_expect(!!(x), 1) | |
55 | #define unlikely(x) __builtin_expect(!!(x), 0) | |
56 | #else | |
57 | #define likely(x) (x) | |
58 | #define unlikely(x) (x) | |
59 | #endif |