]> git.proxmox.com Git - ceph.git/blame - ceph/src/include/crc32c.h
update sources to v12.1.0
[ceph.git] / ceph / src / include / crc32c.h
CommitLineData
7c673cae
FG
1#ifndef CEPH_CRC32C_H
2#define CEPH_CRC32C_H
3
4#include <stdint.h>
5
31f18b77
FG
6#ifdef __cplusplus
7extern "C" {
8#endif
9
7c673cae
FG
10typedef 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 */
16extern ceph_crc32c_func_t ceph_crc32c_func;
17
18extern ceph_crc32c_func_t ceph_choose_crc32(void);
19
31f18b77
FG
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 */
31uint32_t ceph_crc32c_zeros(uint32_t crc, unsigned length);
32
7c673cae
FG
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 */
43static inline uint32_t ceph_crc32c(uint32_t crc, unsigned char const *data, unsigned length)
44{
31f18b77
FG
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);
7c673cae
FG
51}
52
31f18b77
FG
53#ifdef __cplusplus
54}
55#endif
56
7c673cae 57#endif