| 144 | } |
| 145 | |
| 146 | uint16_t crcspeed16little(uint16_t little_table[8][256], uint16_t crc, |
| 147 | void *buf, size_t len) { |
| 148 | unsigned char *next = buf; |
| 149 | |
| 150 | /* process individual bytes until we reach an 8-byte aligned pointer */ |
| 151 | while (len && ((uintptr_t)next & 7) != 0) { |
| 152 | crc = little_table[0][((crc >> 8) ^ *next++) & 0xff] ^ (crc << 8); |
| 153 | len--; |
| 154 | } |
| 155 | |
| 156 | /* fast middle processing, 8 bytes (aligned!) per loop */ |
| 157 | while (len >= 8) { |
| 158 | uint64_t n = *(uint64_t *)next; |
| 159 | crc = little_table[7][(n & 0xff) ^ ((crc >> 8) & 0xff)] ^ |
| 160 | little_table[6][((n >> 8) & 0xff) ^ (crc & 0xff)] ^ |
| 161 | little_table[5][(n >> 16) & 0xff] ^ |
| 162 | little_table[4][(n >> 24) & 0xff] ^ |
| 163 | little_table[3][(n >> 32) & 0xff] ^ |
| 164 | little_table[2][(n >> 40) & 0xff] ^ |
| 165 | little_table[1][(n >> 48) & 0xff] ^ |
| 166 | little_table[0][n >> 56]; |
| 167 | next += 8; |
| 168 | len -= 8; |
| 169 | } |
| 170 | |
| 171 | /* process remaining bytes (can't be larger than 8) */ |
| 172 | while (len) { |
| 173 | crc = little_table[0][((crc >> 8) ^ *next++) & 0xff] ^ (crc << 8); |
| 174 | len--; |
| 175 | } |
| 176 | |
| 177 | return crc; |
| 178 | } |
| 179 | |
| 180 | /* Calculate a non-inverted CRC eight bytes at a time on a big-endian |
| 181 | * architecture. |