[libc-commits] [libc] 2156d33 - [libc] Fix memcpy inefficiency

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Tue Jan 17 03:06:45 PST 2023


Author: Guillaume Chatelet
Date: 2023-01-17T11:06:21Z
New Revision: 2156d33b49b8e5e782573695eca47b2c04d0ab9d

URL: https://github.com/llvm/llvm-project/commit/2156d33b49b8e5e782573695eca47b2c04d0ab9d
DIFF: https://github.com/llvm/llvm-project/commit/2156d33b49b8e5e782573695eca47b2c04d0ab9d.diff

LOG: [libc] Fix memcpy inefficiency

Added: 
    

Modified: 
    libc/src/string/memory_utils/memcpy_implementations.h

Removed: 
    


################################################################################
diff  --git a/libc/src/string/memory_utils/memcpy_implementations.h b/libc/src/string/memory_utils/memcpy_implementations.h
index 4372733a0f027..8ae237f5d781a 100644
--- a/libc/src/string/memory_utils/memcpy_implementations.h
+++ b/libc/src/string/memory_utils/memcpy_implementations.h
@@ -75,15 +75,15 @@ inline_memcpy_x86_maybe_interpose_repmovsb(Ptr __restrict dst,
 
   static constexpr size_t kRepMovsbThreshold =
       LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE;
-  if constexpr (kRepMovsbThreshold == 0)
+  if constexpr (kRepMovsbThreshold == 0) {
     return x86::Memcpy::repmovsb(dst, src, count);
-  else if constexpr (kRepMovsbThreshold > 0) {
+  } else if constexpr (kRepMovsbThreshold == size_t(-1)) {
+    return inline_memcpy_x86(dst, src, count);
+  } else {
     if (unlikely(count >= kRepMovsbThreshold))
       return x86::Memcpy::repmovsb(dst, src, count);
     else
       return inline_memcpy_x86(dst, src, count);
-  } else {
-    return inline_memcpy_x86(dst, src, count);
   }
 }
 #endif // defined(LLVM_LIBC_ARCH_X86)


        


More information about the libc-commits mailing list