[libc-commits] [libc] [libc] Process words in inline_strcmp 8 bytes at a time (PR #214363)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Mon Aug 17 10:20:40 PDT 2026


================
@@ -31,14 +67,45 @@ LIBC_INLINE constexpr int inline_strncmp(const char *left, const char *right,
   if (n == 0)
     return 0;
 
-  // TODO: Look at benefits for comparing words at a time.
-  for (; n > 1; --n, ++left, ++right) {
+  if (LIBC_UNLIKELY((reinterpret_cast<uintptr_t>(left) & 4095) > 4088 ||
+                    (reinterpret_cast<uintptr_t>(right) & 4095) > 4088)) {
+    for (; n > 1; --n, ++left, ++right) {
+      char lc = *left;
+      if (!comp(lc, '\0') || comp(lc, *right))
+        break;
+    }
+    return comp(static_cast<unsigned char>(*left),
+                static_cast<unsigned char>(*right));
+  }
+
+  constexpr size_t block_size = sizeof(uint64_t) / 8;
----------------
michaelrj-google wrote:

as a constant `BLOCK_SIZE` should be upper case

https://github.com/llvm/llvm-project/pull/214363


More information about the libc-commits mailing list