Revert "[libc] Templatize str{,n}cmp"
authorAlex Brachet <abrachet@google.com>
Mon, 9 Jan 2023 20:24:16 +0000 (20:24 +0000)
committerAlex Brachet <abrachet@google.com>
Mon, 9 Jan 2023 20:24:16 +0000 (20:24 +0000)
This reverts commit c6dcbed2e5327f0c11962bdbbcd02f1b5c570fea.

Broke tests on arm and aarch64

libc/src/__support/CPP/functional.h
libc/src/string/CMakeLists.txt
libc/src/string/memory_utils/CMakeLists.txt
libc/src/string/memory_utils/strcmp_implementations.h [deleted file]
libc/src/string/strcmp.cpp
libc/src/string/strncmp.cpp
utils/bazel/llvm-project-overlay/libc/BUILD.bazel

index b77100c..5919306 100644 (file)
@@ -24,10 +24,6 @@ public:
   constexpr R operator()(Args... params) { return func(params...); }
 };
 
-template <class T> struct minus {
-  constexpr T operator()(const T &lhs, const T &rhs) const { return lhs - rhs; }
-};
-
 } // namespace cpp
 } // namespace __llvm_libc
 
index 93357be..0faa1db 100644 (file)
@@ -111,9 +111,6 @@ add_entrypoint_object(
     strcmp.cpp
   HDRS
     strcmp.h
-  DEPENDS
-    .memory_utils.strcmp_implementation
-    libc.src.__support.CPP.functional
 )
 
 add_entrypoint_object(
@@ -229,9 +226,6 @@ add_entrypoint_object(
     strncmp.cpp
   HDRS
     strncmp.h
-  DEPENDS
-    .memory_utils.strcmp_implementation
-    libc.src.__support.CPP.functional
 )
 
 add_entrypoint_object(
index 10e14e1..3bf81e9 100644 (file)
@@ -60,9 +60,3 @@ add_header_library(
   DEPS
     .memset_implementation
 )
-
-add_header_library(
-  strcmp_implementation
-  HDRS
-    strcmp_implementations.h
-)
diff --git a/libc/src/string/memory_utils/strcmp_implementations.h b/libc/src/string/memory_utils/strcmp_implementations.h
deleted file mode 100644 (file)
index 3a7caee..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-//===-- str{,case}cmp implementation ----------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_STRCMP_IMPLEMENTATIONS_H
-#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_STRCMP_IMPLEMENTATIONS_H
-
-#include <stddef.h>
-
-namespace __llvm_libc {
-
-template <typename Comp>
-constexpr static int strcmp_implementation(const char *left, const char *right,
-                                           Comp &&comp) {
-  // TODO: Look at benefits for comparing words at a time.
-  for (; *left && !comp(*left, *right); ++left, ++right)
-    ;
-  return comp(*reinterpret_cast<const unsigned char *>(left),
-              *reinterpret_cast<const unsigned char *>(right));
-}
-
-template <typename Comp>
-constexpr static int strncmp_implementation(const char *left, const char *right,
-                                            size_t n, Comp &&comp) {
-  if (n == 0)
-    return 0;
-
-  // TODO: Look at benefits for comparing words at a time.
-  for (; n > 1; --n, ++left, ++right) {
-    char lc = *left;
-    if (!comp(lc, '\0') || comp(lc, *right))
-      break;
-  }
-  return comp(*reinterpret_cast<const unsigned char *>(left),
-              *reinterpret_cast<const unsigned char *>(right));
-}
-
-} // namespace __llvm_libc
-
-#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_STRCMP_IMPLEMENTATIONS_H
index 738b578..8468b3c 100644 (file)
@@ -8,14 +8,16 @@
 
 #include "src/string/strcmp.h"
 
-#include "src/__support/CPP/functional.h"
 #include "src/__support/common.h"
-#include "src/string/memory_utils/strcmp_implementations.h"
 
 namespace __llvm_libc {
 
+// TODO: Look at benefits for comparing words at a time.
 LLVM_LIBC_FUNCTION(int, strcmp, (const char *left, const char *right)) {
-  return strcmp_implementation(left, right, cpp::minus<char>{});
+  for (; *left && *left == *right; ++left, ++right)
+    ;
+  return *reinterpret_cast<const unsigned char *>(left) -
+         *reinterpret_cast<const unsigned char *>(right);
 }
 
 } // namespace __llvm_libc
index f8cf757..94960e5 100644 (file)
@@ -8,17 +8,25 @@
 
 #include "src/string/strncmp.h"
 
-#include "src/__support/CPP/functional.h"
 #include "src/__support/common.h"
-#include "src/string/memory_utils/strcmp_implementations.h"
-
 #include <stddef.h>
 
 namespace __llvm_libc {
 
+// TODO: Look at benefits for comparing words at a time.
 LLVM_LIBC_FUNCTION(int, strncmp,
                    (const char *left, const char *right, size_t n)) {
-  return strncmp_implementation(left, right, n, cpp::minus<char>{});
+
+  if (n == 0)
+    return 0;
+
+  for (; n > 1; --n, ++left, ++right) {
+    char lc = *left;
+    if (lc == '\0' || lc != *right)
+      break;
+  }
+  return *reinterpret_cast<const unsigned char *>(left) -
+         *reinterpret_cast<const unsigned char *>(right);
 }
 
 } // namespace __llvm_libc
index a43e1b7..d75e578 100644 (file)
@@ -1089,7 +1089,6 @@ libc_support_library(
         "src/string/memory_utils/memcpy_implementations.h",
         "src/string/memory_utils/memmove_implementations.h",
         "src/string/memory_utils/memset_implementations.h",
-        "src/string/memory_utils/strcmp_implementations.h",
     ],
     deps = [
         ":__support_common",
@@ -1271,8 +1270,6 @@ libc_function(
     hdrs = ["src/string/strcmp.h"],
     deps = [
         ":__support_common",
-        ":__support_cpp_functional",
-        ":string_memory_utils",
         ":string_utils",
     ],
 )