Calculate a non-inverted CRC multiple bytes at a time on a little-endian * architecture. If you need inverted CRC, invert *before* calling and invert * *after* calling. * 64 bit crc = process 8 bytes at once; */
| 110 | * 64 bit crc = process 8 bytes at once; |
| 111 | */ |
| 112 | uint64_t crcspeed64little(uint64_t little_table[8][256], uint64_t crc, |
| 113 | void *buf, size_t len) { |
| 114 | unsigned char *next = buf; |
| 115 | |
| 116 | /* process individual bytes until we reach an 8-byte aligned pointer */ |
| 117 | while (len && ((uintptr_t)next & 7) != 0) { |
| 118 | crc = little_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8); |
| 119 | len--; |
| 120 | } |
| 121 | |
| 122 | /* fast middle processing, 8 bytes (aligned!) per loop */ |
| 123 | while (len >= 8) { |
| 124 | crc ^= *(uint64_t *)next; |
| 125 | crc = little_table[7][crc & 0xff] ^ |
| 126 | little_table[6][(crc >> 8) & 0xff] ^ |
| 127 | little_table[5][(crc >> 16) & 0xff] ^ |
| 128 | little_table[4][(crc >> 24) & 0xff] ^ |
| 129 | little_table[3][(crc >> 32) & 0xff] ^ |
| 130 | little_table[2][(crc >> 40) & 0xff] ^ |
| 131 | little_table[1][(crc >> 48) & 0xff] ^ |
| 132 | little_table[0][crc >> 56]; |
| 133 | next += 8; |
| 134 | len -= 8; |
| 135 | } |
| 136 | |
| 137 | /* process remaining bytes (can't be larger than 8) */ |
| 138 | while (len) { |
| 139 | crc = little_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8); |
| 140 | len--; |
| 141 | } |
| 142 | |
| 143 | return crc; |
| 144 | } |
| 145 | |
| 146 | uint16_t crcspeed16little(uint16_t little_table[8][256], uint16_t crc, |
| 147 | void *buf, size_t len) { |