]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
inline_memory: optimized mem_is_zero for non-X64 15307/head
authorPiotr Dałek <piotr.dalek@corp.ovh.com>
Fri, 26 May 2017 09:39:58 +0000 (11:39 +0200)
committerPiotr Dałek <piotr.dalek@corp.ovh.com>
Fri, 26 May 2017 09:39:58 +0000 (11:39 +0200)
mem_is_zero is fast for X64 where 128-bit registers are available,
but it's very easy to optimze it for 32-bit Intel and ARM CPUs as
well, the speed won't be anywhere near the fastest one but still almost
7x faster than regular byte-by-byte check.
Now with extra test to check for corner cases that may pop with such
implementations.

Signed-off-by: Piotr Dałek <piotr.dalek@corp.ovh.com>
src/include/inline_memory.h
src/test/bufferlist.cc

index f2166826b76d2e8a8f09a0d71ef1f1b62874f516..f2433f03edf788d818b7c84fd26cd911b525862d 100644 (file)
@@ -124,6 +124,15 @@ bool mem_is_zero(const char *data, size_t len)
 
 static inline bool mem_is_zero(const char *data, size_t len) {
   const char *end = data + len;
+  const char* end64 = data + (len / sizeof(uint64_t))*sizeof(uint64_t);
+
+  while (data < end64) {
+    if (*(uint64_t*)data != 0) {
+      return false;
+    }
+    data += sizeof(uint64_t);
+  }
+
   while (data < end) {
     if (*data != 0) {
       return false;
index 907a194229e494801e1ff94509239dd925a62279..b2d408e26450d026b6bfbe45e5d14c3e0cb6de1a 100644 (file)
@@ -1764,6 +1764,17 @@ TEST(BufferList, is_zero) {
     bl.append_zero(1);
     EXPECT_TRUE(bl.is_zero());
   }
+
+  for (size_t i = 1; i <= 256; ++i) {
+    bufferlist bl;
+    bl.append_zero(i);
+    EXPECT_TRUE(bl.is_zero());
+    bl.append('A');
+    // ensure buffer is a single, contiguous before testing
+    bl.rebuild();
+    EXPECT_FALSE(bl.is_zero());
+  }
+
 }
 
 TEST(BufferList, clear) {