| 1 |
#ifndef CRC32_BRAID_COMB_P_H_ |
| 2 |
#define CRC32_BRAID_COMB_P_H_ |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
static uint32_t multmodp(uint32_t a, uint32_t b) { |
| 9 |
uint32_t m, p; |
| 10 |
|
| 11 |
m = (uint32_t)1 << 31; |
| 12 |
p = 0; |
| 13 |
for (;;) { |
| 14 |
if (a & m) { |
| 15 |
p ^= b; |
| 16 |
if ((a & (m - 1)) == 0) |
| 17 |
break; |
| 18 |
} |
| 19 |
m >>= 1; |
| 20 |
b = b & 1 ? (b >> 1) ^ POLY : b >> 1; |
| 21 |
} |
| 22 |
return p; |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
static uint32_t x2nmodp(z_off64_t n, unsigned k) { |
| 30 |
uint32_t p; |
| 31 |
|
| 32 |
p = (uint32_t)1 << 31; |
| 33 |
while (n) { |
| 34 |
if (n & 1) |
| 35 |
p = multmodp(x2n_table[k & 31], p); |
| 36 |
n >>= 1; |
| 37 |
k++; |
| 38 |
} |
| 39 |
return p; |
| 40 |
} |
| 41 |
|
| 42 |
#endif |