]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/include/crc32c.h
update sources to v12.1.0
[ceph.git] / ceph / src / include / crc32c.h
index 35b6cafcc3a58326109a380ae93c004152ee3642..dd4ede666ec1dca7cb346615aaa955a510fb1a98 100644 (file)
@@ -3,6 +3,10 @@
 
 #include <stdint.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef uint32_t (*ceph_crc32c_func_t)(uint32_t crc, unsigned char const *data, unsigned length);
 
 /*
@@ -13,6 +17,19 @@ extern ceph_crc32c_func_t ceph_crc32c_func;
 
 extern ceph_crc32c_func_t ceph_choose_crc32(void);
 
+/**
+ * calculate crc32c for data that is entirely 0 (ZERO)
+ *
+ * Note: works the same as ceph_crc32c_func for data == nullptr, 
+ * but faster than the optimized assembly on certain architectures.
+ * This is faster than intel optimized assembly, but not as fast as 
+ * ppc64le optimized assembly.  
+ *
+ * @param crc initial value
+ * @param length length of buffer
+ */
+uint32_t ceph_crc32c_zeros(uint32_t crc, unsigned length);
+
 /**
  * calculate crc32c
  *
@@ -25,7 +42,16 @@ extern ceph_crc32c_func_t ceph_choose_crc32(void);
  */
 static inline uint32_t ceph_crc32c(uint32_t crc, unsigned char const *data, unsigned length)
 {
-       return ceph_crc32c_func(crc, data, length);
+#ifndef HAVE_POWER8
+  if (!data && length > 16)
+    return ceph_crc32c_zeros(crc, length);
+#endif /* HAVE_POWER8 */
+
+  return ceph_crc32c_func(crc, data, length);
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif