]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/crc32c.h
update sources to v12.1.0
[ceph.git] / ceph / src / include / crc32c.h
1 #ifndef CEPH_CRC32C_H
2 #define CEPH_CRC32C_H
3
4 #include <stdint.h>
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 typedef uint32_t (*ceph_crc32c_func_t)(uint32_t crc, unsigned char const *data, unsigned length);
11
12 /*
13 * this is a static global with the chosen crc32c implementation for
14 * the given architecture.
15 */
16 extern ceph_crc32c_func_t ceph_crc32c_func;
17
18 extern ceph_crc32c_func_t ceph_choose_crc32(void);
19
20 /**
21 * calculate crc32c for data that is entirely 0 (ZERO)
22 *
23 * Note: works the same as ceph_crc32c_func for data == nullptr,
24 * but faster than the optimized assembly on certain architectures.
25 * This is faster than intel optimized assembly, but not as fast as
26 * ppc64le optimized assembly.
27 *
28 * @param crc initial value
29 * @param length length of buffer
30 */
31 uint32_t ceph_crc32c_zeros(uint32_t crc, unsigned length);
32
33 /**
34 * calculate crc32c
35 *
36 * Note: if the data pointer is NULL, we calculate a crc value as if
37 * it were zero-filled.
38 *
39 * @param crc initial value
40 * @param data pointer to data buffer
41 * @param length length of buffer
42 */
43 static inline uint32_t ceph_crc32c(uint32_t crc, unsigned char const *data, unsigned length)
44 {
45 #ifndef HAVE_POWER8
46 if (!data && length > 16)
47 return ceph_crc32c_zeros(crc, length);
48 #endif /* HAVE_POWER8 */
49
50 return ceph_crc32c_func(crc, data, length);
51 }
52
53 #ifdef __cplusplus
54 }
55 #endif
56
57 #endif