1 /*-
2 * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or
3 * code or tables extracted from it, as desired without restriction.
4 *
5 * $FreeBSD$
6 */
7
8 #ifndef _SYS_GSB_CRC32_H_
9 #define _SYS_GSB_CRC32_H_
10
11 #include <sys/types.h>
12
13 #ifdef _KERNEL
14
15 extern const uint32_t crc32_tab[];
16
17 static __inline uint32_t
crc32_raw(const void * buf,size_t size,uint32_t crc)18 crc32_raw(const void *buf, size_t size, uint32_t crc)
19 {
20 const uint8_t *p = (const uint8_t *)buf;
21
22 while (size--)
23 crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
24 return (crc);
25 }
26
27 static __inline uint32_t
crc32(const void * buf,size_t size)28 crc32(const void *buf, size_t size)
29 {
30 uint32_t crc;
31
32 crc = crc32_raw(buf, size, ~0U);
33 return (crc ^ ~0U);
34 }
35
36 uint32_t calculate_crc32c(uint32_t crc32c, const unsigned char *buffer,
37 unsigned int length);
38 #endif
39
40 #if defined(__amd64__) || defined(__i386__)
41 uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned);
42 #endif
43 #if defined(__aarch64__)
44 uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned int);
45 #endif
46
47 #endif /* !_SYS_GSB_CRC32_H_ */
48