- while (bytes--) {
- __asm__ __volatile__ (
- ".byte 0xf2, 0xf, 0x38, 0xf0, 0xf1"
- : "=S"(crc)
- : "0"(crc), "c"(*p)
- );
- p++;
- }
-
- return crc;
-}
-
-#if BITS_PER_LONG > 32
-#define WORD_SHIFT 3
-#define WORD_MASK 7
-#define REX "0x48, "
-#else
-#define WORD_SHIFT 2
-#define WORD_MASK 3
-#define REX ""
-#endif
-
-/* Do we need to worry about unaligned input data here? */
-static inline __u32 crc32c_hw(__u32 crc, unsigned char const *p, size_t len)
-{
- unsigned int words = len >> WORD_SHIFT;
- unsigned int bytes = len & WORD_MASK;
- long *ptmp = (long *)p;
-
- while (words--) {
- __asm__ __volatile__(
- ".byte 0xf2, " REX "0xf, 0x38, 0xf1, 0xf1;"
- : "=S"(crc)
- : "0"(crc), "c"(*ptmp)
- );
- ptmp++;
- }
-
- if (bytes)
- crc = crc32c_hw_byte(crc, (unsigned char *)ptmp, bytes);
-
- return crc;
-}
-#else
-/* We should never call this unless the CPU has previously been detected to
- * support this instruction in the SSE4.2 feature set. b=23549 */
-static inline __u32 crc32c_hw(__u32 crc, unsigned char const *p,size_t len)
-{
- LBUG();
-}
-#endif
-
-static inline __u32 init_checksum(cksum_type_t cksum_type)
-{
- switch(cksum_type) {
- case OBD_CKSUM_CRC32C:
- return ~0U;
-#ifdef HAVE_ADLER
- case OBD_CKSUM_ADLER:
- return 1U;
-#endif
- case OBD_CKSUM_CRC32:
- return ~0U;
- default:
- CERROR("Unknown checksum type (%x)!!!\n", cksum_type);
- LBUG();
- }
- return 0;
-}
-
-static inline __u32 fini_checksum(__u32 cksum, cksum_type_t cksum_type)
-{
- if (cksum_type == OBD_CKSUM_CRC32C)
- return ~cksum;
- return cksum;
-}
-
-static inline __u32 compute_checksum(__u32 cksum, unsigned char const *p,
- size_t len, cksum_type_t cksum_type)
-{
- switch(cksum_type) {
- case OBD_CKSUM_CRC32C:
- return crc32c_hw(cksum, p, len);
-#ifdef HAVE_ADLER
- case OBD_CKSUM_ADLER:
- return adler32(cksum, p, len);
-#endif
- case OBD_CKSUM_CRC32:
- return crc32_le(cksum, p, len);
- default:
- CERROR("Unknown checksum type (%x)!!!\n", cksum_type);
- LBUG();
- }
- return 0;