37#include <sys/kernel.h>
39#include <sys/gsb_crc32.h>
41static __inline uint32_t
51 __asm(
"crc32b %1,%0" :
"+r" (x) :
"r" (y));
56static __inline uint64_t
57_mm_crc32_u64(uint64_t x, uint64_t y)
59 __asm(
"crc32q %1,%0" :
"+r" (x) :
"r" (y));
63static __inline uint32_t
66 __asm(
"crc32l %1,%0" :
"+r" (x) :
"r" (y));
72#define POLY 0x82f63b78
121 for (n = 0; n < 32; n++)
142 for (n = 1; n < 32; n++) {
168 for (n = 0; n < 32; n++)
183 for (n = 0; n < 256; n++) {
192static inline uint32_t
196 return (zeros[0][crc & 0xff] ^ zeros[1][(crc >> 8) & 0xff] ^
197 zeros[2][(crc >> 16) & 0xff] ^ zeros[3][crc >> 24]);
221 const size_t align = 8;
223 const size_t align = 4;
225 const unsigned char *next, *end;
227 uint64_t crc0, crc1, crc2;
229 uint32_t crc0, crc1, crc2;
236 while (len && ((uintptr_t)next & (align - 1)) != 0) {
251 while (len >=
LONG * 3) {
257 crc0 = _mm_crc32_u64(crc0, *(
const uint64_t *)next);
258 crc1 = _mm_crc32_u64(crc1,
259 *(
const uint64_t *)(next +
LONG));
260 crc2 = _mm_crc32_u64(crc2,
261 *(
const uint64_t *)(next + (
LONG * 2)));
265 *(
const uint32_t *)(next +
LONG));
267 *(
const uint32_t *)(next + (
LONG * 2)));
270 }
while (next < end);
329 while (len >=
SHORT * 3) {
335 crc0 = _mm_crc32_u64(crc0, *(
const uint64_t *)next);
336 crc1 = _mm_crc32_u64(crc1,
337 *(
const uint64_t *)(next +
SHORT));
338 crc2 = _mm_crc32_u64(crc2,
339 *(
const uint64_t *)(next + (
SHORT * 2)));
343 *(
const uint32_t *)(next +
SHORT));
345 *(
const uint32_t *)(next + (
SHORT * 2)));
348 }
while (next < end);
359 end = next + (len - (len & (align - 1)));
362 crc0 = _mm_crc32_u64(crc0, *(
const uint64_t *)next);
377 return ((uint32_t)crc0);
static uint32_t crc32c_short[4][256]
static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec)
static __inline uint32_t _mm_crc32_u32(uint32_t x, uint32_t y)
static uint32_t crc32c_2short[4][256]
static uint32_t crc32c_shift(uint32_t zeros[][256], uint32_t crc)
static uint32_t crc32c_long[4][256]
static void gf2_matrix_square(uint32_t *square, uint32_t *mat)
static void crc32c_init_hw(void)
static void crc32c_zeros_op(uint32_t *even, size_t len)
static void crc32c_zeros(uint32_t zeros[][256], size_t len)
static __inline uint32_t _mm_crc32_u8(uint32_t x, uint8_t y)
SYSINIT(crc32c_sse42, SI_SUB_LOCK, SI_ORDER_ANY, crc32c_init_hw, NULL)
uint32_t sse42_crc32c(uint32_t crc, const unsigned char *buf, unsigned len)
static uint32_t crc32c_2long[4][256]