diff options
| author | Nick Desaulniers <nickdesaulniers@users.noreply.github.com> | 2024-12-10 08:58:45 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-10 08:58:45 -0800 |
| commit | 431ea2d076f8a5ca35b2c293dd5d62f5ce083f45 (patch) | |
| tree | 82645c03681dabcbe4ee0c4423266607aa61c672 /libc/src/string | |
| parent | 0fb06172f14110daa45bed8ae4c153967c9365dc (diff) | |
[libc] move bcmp, bzero, bcopy, index, rindex, strcasecmp, strncasecmp to strings.h (#118899)
docgen relies on the convention that we have a file foo.cpp in
libc/src/\<header\>/. Because the above functions weren't in libc/src/strings/
but rather libc/src/string/, docgen could not find that we had implemented
these.
Rather than add special carve outs to docgen, let's fix up our sources for
these 7 functions to stick with the existing conventions the rest of the
codebase follows.
Link: #118860
Fixes: #118875
Diffstat (limited to 'libc/src/string')
| -rw-r--r-- | libc/src/string/CMakeLists.txt | 146 | ||||
| -rw-r--r-- | libc/src/string/bcmp.cpp | 21 | ||||
| -rw-r--r-- | libc/src/string/bcmp.h | 21 | ||||
| -rw-r--r-- | libc/src/string/bcopy.cpp | 20 | ||||
| -rw-r--r-- | libc/src/string/bcopy.h | 21 | ||||
| -rw-r--r-- | libc/src/string/bzero.cpp | 20 | ||||
| -rw-r--r-- | libc/src/string/bzero.h | 21 | ||||
| -rw-r--r-- | libc/src/string/index.cpp | 21 | ||||
| -rw-r--r-- | libc/src/string/index.h | 20 | ||||
| -rw-r--r-- | libc/src/string/rindex.cpp | 21 | ||||
| -rw-r--r-- | libc/src/string/rindex.h | 20 | ||||
| -rw-r--r-- | libc/src/string/strcasecmp.cpp | 26 | ||||
| -rw-r--r-- | libc/src/string/strcasecmp.h | 20 | ||||
| -rw-r--r-- | libc/src/string/strncasecmp.cpp | 27 | ||||
| -rw-r--r-- | libc/src/string/strncasecmp.h | 21 |
15 files changed, 0 insertions, 446 deletions
diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt index 8fe1226dd6a7..e3faa543e630 100644 --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -35,24 +35,6 @@ add_header_library( ) add_entrypoint_object( - bcopy - SRCS - bcopy.cpp - HDRS - bcopy.h -) - -add_entrypoint_object( - index - SRCS - index.cpp - HDRS - index.h - DEPENDS - .string_utils -) - -add_entrypoint_object( memccpy SRCS memccpy.cpp @@ -99,16 +81,6 @@ add_entrypoint_object( ) add_entrypoint_object( - rindex - SRCS - rindex.cpp - HDRS - rindex.h - DEPENDS - .string_utils -) - -add_entrypoint_object( stpcpy SRCS stpcpy.cpp @@ -172,17 +144,6 @@ add_entrypoint_object( ) add_entrypoint_object( - strcasecmp - SRCS - strcasecmp.cpp - HDRS - strcasecmp.h - DEPENDS - .memory_utils.inline_strcmp - libc.src.__support.ctype_utils -) - -add_entrypoint_object( strcasestr SRCS strcasestr.cpp @@ -320,17 +281,6 @@ add_entrypoint_object( ) add_entrypoint_object( - strncasecmp - SRCS - strncasecmp.cpp - HDRS - strncasecmp.h - DEPENDS - .memory_utils.inline_strcmp - libc.src.__support.ctype_utils -) - -add_entrypoint_object( strncpy SRCS strncpy.cpp @@ -475,102 +425,6 @@ add_entrypoint_object( .memory_utils.inline_memset ) -# Helper to define a function with multiple implementations -# - Computes flags to satisfy required/rejected features and arch, -# - Declares an entry point, -# - Attach the REQUIRE_CPU_FEATURES property to the target, -# - Add the fully qualified target to `${name}_implementations` global property for tests. -function(add_implementation name impl_name) - cmake_parse_arguments( - "ADD_IMPL" - "" # Optional arguments - "" # Single value arguments - "REQUIRE;SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;MLLVM_COMPILE_OPTIONS" # Multi value arguments - ${ARGN}) - - if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - # Note that '-mllvm' needs to be prefixed with 'SHELL:' to prevent CMake flag deduplication. - foreach(opt IN LISTS ADD_IMPL_MLLVM_COMPILE_OPTIONS) - list(APPEND ADD_IMPL_COMPILE_OPTIONS "SHELL:-mllvm ${opt}") - endforeach() - endif() - - if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") - # Prevent warning when passing x86 SIMD types as template arguments. - # e.g. "warning: ignoring attributes on template argument ā__m128iā [-Wignored-attributes]" - list(APPEND ADD_IMPL_COMPILE_OPTIONS "-Wno-ignored-attributes") - endif() - - add_entrypoint_object(${impl_name} - NAME ${name} - SRCS ${ADD_IMPL_SRCS} - HDRS ${ADD_IMPL_HDRS} - DEPENDS ${ADD_IMPL_DEPENDS} - COMPILE_OPTIONS ${libc_opt_high_flag} ${ADD_IMPL_COMPILE_OPTIONS} - ) - get_fq_target_name(${impl_name} fq_target_name) - set_target_properties(${fq_target_name} PROPERTIES REQUIRE_CPU_FEATURES "${ADD_IMPL_REQUIRE}") - set_property(GLOBAL APPEND PROPERTY "${name}_implementations" "${fq_target_name}") -endfunction() - -# ------------------------------------------------------------------------------ -# bcmp -# ------------------------------------------------------------------------------ - -function(add_bcmp bcmp_name) - add_implementation(bcmp ${bcmp_name} - SRCS ${LIBC_SOURCE_DIR}/src/string/bcmp.cpp - HDRS ${LIBC_SOURCE_DIR}/src/string/bcmp.h - DEPENDS - .memory_utils.memory_utils - libc.include.string - ${ARGN} - ) -endfunction() - -if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) - add_bcmp(bcmp_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2) - add_bcmp(bcmp_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2) - add_bcmp(bcmp_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2) - add_bcmp(bcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512BW) - add_bcmp(bcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}) - add_bcmp(bcmp) -elseif(LIBC_TARGET_OS_IS_GPU) - add_bcmp(bcmp) -else() - add_bcmp(bcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}) - add_bcmp(bcmp) -endif() - -# ------------------------------------------------------------------------------ -# bzero -# ------------------------------------------------------------------------------ - -function(add_bzero bzero_name) - add_implementation(bzero ${bzero_name} - SRCS ${LIBC_SOURCE_DIR}/src/string/bzero.cpp - HDRS ${LIBC_SOURCE_DIR}/src/string/bzero.h - DEPENDS - .memory_utils.inline_memset - libc.include.string - ${ARGN} - ) -endfunction() - -if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) - add_bzero(bzero_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2) - add_bzero(bzero_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2) - add_bzero(bzero_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2) - add_bzero(bzero_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F) - add_bzero(bzero_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}) - add_bzero(bzero) -elseif(LIBC_TARGET_OS_IS_GPU) - add_bzero(bzero) -else() - add_bzero(bzero_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}) - add_bzero(bzero) -endif() - # ------------------------------------------------------------------------------ # memcmp # ------------------------------------------------------------------------------ diff --git a/libc/src/string/bcmp.cpp b/libc/src/string/bcmp.cpp deleted file mode 100644 index 6e9c9ae3b7a3..000000000000 --- a/libc/src/string/bcmp.cpp +++ /dev/null @@ -1,21 +0,0 @@ -//===-- Implementation of bcmp --------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include "src/string/bcmp.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" -#include "src/string/memory_utils/inline_bcmp.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(int, bcmp, - (const void *lhs, const void *rhs, size_t count)) { - return inline_bcmp(lhs, rhs, count); -} - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/string/bcmp.h b/libc/src/string/bcmp.h deleted file mode 100644 index a82b529164d9..000000000000 --- a/libc/src/string/bcmp.h +++ /dev/null @@ -1,21 +0,0 @@ -//===-- Implementation header for bzero -------------------------*- 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_BCMP_H -#define LLVM_LIBC_SRC_STRING_BCMP_H - -#include "src/__support/macros/config.h" -#include <stddef.h> // size_t - -namespace LIBC_NAMESPACE_DECL { - -int bcmp(const void *lhs, const void *rhs, size_t count); - -} // namespace LIBC_NAMESPACE_DECL - -#endif // LLVM_LIBC_SRC_STRING_BCMP_H diff --git a/libc/src/string/bcopy.cpp b/libc/src/string/bcopy.cpp deleted file mode 100644 index 89aad71e354c..000000000000 --- a/libc/src/string/bcopy.cpp +++ /dev/null @@ -1,20 +0,0 @@ -//===-- Implementation of bcopy -------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include "src/string/bcopy.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" -#include "src/string/memory_utils/inline_memmove.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(void, bcopy, (const void *src, void *dst, size_t count)) { - return inline_memmove(dst, src, count); -} - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/string/bcopy.h b/libc/src/string/bcopy.h deleted file mode 100644 index 4cf0263a7d63..000000000000 --- a/libc/src/string/bcopy.h +++ /dev/null @@ -1,21 +0,0 @@ -//===-- Implementation header for bcopy -------------------------*- 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_BCOPY_H -#define LLVM_LIBC_SRC_STRING_BCOPY_H - -#include "src/__support/macros/config.h" -#include <stddef.h> // size_t - -namespace LIBC_NAMESPACE_DECL { - -void bcopy(const void *src, void *dest, size_t count); - -} // namespace LIBC_NAMESPACE_DECL - -#endif // LLVM_LIBC_SRC_STRING_BCOPY_H diff --git a/libc/src/string/bzero.cpp b/libc/src/string/bzero.cpp deleted file mode 100644 index 7bcbee3547b9..000000000000 --- a/libc/src/string/bzero.cpp +++ /dev/null @@ -1,20 +0,0 @@ -//===-- Implementation of bzero -------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include "src/string/bzero.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" -#include "src/string/memory_utils/inline_bzero.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(void, bzero, (void *ptr, size_t count)) { - inline_bzero(reinterpret_cast<char *>(ptr), count); -} - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/string/bzero.h b/libc/src/string/bzero.h deleted file mode 100644 index d9722197e8e8..000000000000 --- a/libc/src/string/bzero.h +++ /dev/null @@ -1,21 +0,0 @@ -//===-- Implementation header for bzero -------------------------*- 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_BZERO_H -#define LLVM_LIBC_SRC_STRING_BZERO_H - -#include "src/__support/macros/config.h" -#include <stddef.h> // size_t - -namespace LIBC_NAMESPACE_DECL { - -void bzero(void *ptr, size_t count); - -} // namespace LIBC_NAMESPACE_DECL - -#endif // LLVM_LIBC_SRC_STRING_BZERO_H diff --git a/libc/src/string/index.cpp b/libc/src/string/index.cpp deleted file mode 100644 index 46cf54825f6c..000000000000 --- a/libc/src/string/index.cpp +++ /dev/null @@ -1,21 +0,0 @@ -//===-- Implementation of index -------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include "src/string/index.h" - -#include "src/__support/common.h" -#include "src/__support/macros/config.h" -#include "src/string/string_utils.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(char *, index, (const char *src, int c)) { - return internal::strchr_implementation(src, c); -} - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/string/index.h b/libc/src/string/index.h deleted file mode 100644 index 9843bcdf9a57..000000000000 --- a/libc/src/string/index.h +++ /dev/null @@ -1,20 +0,0 @@ -//===-- Implementation header for index -------------------------*- 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_INDEX_H -#define LLVM_LIBC_SRC_STRING_INDEX_H - -#include "src/__support/macros/config.h" - -namespace LIBC_NAMESPACE_DECL { - -char *index(const char *src, int c); - -} // namespace LIBC_NAMESPACE_DECL - -#endif // LLVM_LIBC_SRC_STRING_INDEX_H diff --git a/libc/src/string/rindex.cpp b/libc/src/string/rindex.cpp deleted file mode 100644 index 25879ddb07f6..000000000000 --- a/libc/src/string/rindex.cpp +++ /dev/null @@ -1,21 +0,0 @@ -//===-- Implementation of rindex ------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include "src/string/rindex.h" - -#include "src/__support/common.h" -#include "src/__support/macros/config.h" -#include "src/string/string_utils.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(char *, rindex, (const char *src, int c)) { - return internal::strrchr_implementation(src, c); -} - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/string/rindex.h b/libc/src/string/rindex.h deleted file mode 100644 index cfc35daa1f4d..000000000000 --- a/libc/src/string/rindex.h +++ /dev/null @@ -1,20 +0,0 @@ -//===-- Implementation header for rindex ------------------------*- 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_RINDEX_H -#define LLVM_LIBC_SRC_STRING_RINDEX_H - -#include "src/__support/macros/config.h" - -namespace LIBC_NAMESPACE_DECL { - -char *rindex(const char *src, int c); - -} // namespace LIBC_NAMESPACE_DECL - -#endif // LLVM_LIBC_SRC_STRING_RINDEX_H diff --git a/libc/src/string/strcasecmp.cpp b/libc/src/string/strcasecmp.cpp deleted file mode 100644 index 1274c047fc28..000000000000 --- a/libc/src/string/strcasecmp.cpp +++ /dev/null @@ -1,26 +0,0 @@ -//===-- Implementation of strcasecmp --------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include "src/string/strcasecmp.h" - -#include "src/__support/common.h" -#include "src/__support/ctype_utils.h" -#include "src/__support/macros/config.h" -#include "src/string/memory_utils/inline_strcmp.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(int, strcasecmp, (const char *left, const char *right)) { - auto case_cmp = [](char a, char b) { - return LIBC_NAMESPACE::internal::tolower(a) - - LIBC_NAMESPACE::internal::tolower(b); - }; - return inline_strcmp(left, right, case_cmp); -} - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/string/strcasecmp.h b/libc/src/string/strcasecmp.h deleted file mode 100644 index 2916b8d41707..000000000000 --- a/libc/src/string/strcasecmp.h +++ /dev/null @@ -1,20 +0,0 @@ -//===-- Implementation header for strcasecmp --------------------*- 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_STRCASECMP_H -#define LLVM_LIBC_SRC_STRING_STRCASECMP_H - -#include "src/__support/macros/config.h" - -namespace LIBC_NAMESPACE_DECL { - -int strcasecmp(const char *left, const char *right); - -} // namespace LIBC_NAMESPACE_DECL - -#endif // LLVM_LIBC_SRC_STRING_STRCASECMP_H diff --git a/libc/src/string/strncasecmp.cpp b/libc/src/string/strncasecmp.cpp deleted file mode 100644 index 45f82c98069b..000000000000 --- a/libc/src/string/strncasecmp.cpp +++ /dev/null @@ -1,27 +0,0 @@ -//===-- Implementation of strncasecmp -------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#include "src/string/strncasecmp.h" - -#include "src/__support/common.h" -#include "src/__support/ctype_utils.h" -#include "src/__support/macros/config.h" -#include "src/string/memory_utils/inline_strcmp.h" - -namespace LIBC_NAMESPACE_DECL { - -LLVM_LIBC_FUNCTION(int, strncasecmp, - (const char *left, const char *right, size_t n)) { - auto case_cmp = [](char a, char b) { - return LIBC_NAMESPACE::internal::tolower(a) - - LIBC_NAMESPACE::internal::tolower(b); - }; - return inline_strncmp(left, right, n, case_cmp); -} - -} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/string/strncasecmp.h b/libc/src/string/strncasecmp.h deleted file mode 100644 index 15f74994ca56..000000000000 --- a/libc/src/string/strncasecmp.h +++ /dev/null @@ -1,21 +0,0 @@ -//===-- Implementation header for strcasecmp --------------------*- 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_STRNCASECMP_H -#define LLVM_LIBC_SRC_STRING_STRNCASECMP_H - -#include "src/__support/macros/config.h" -#include <stddef.h> - -namespace LIBC_NAMESPACE_DECL { - -int strncasecmp(const char *left, const char *right, size_t n); - -} // namespace LIBC_NAMESPACE_DECL - -#endif // LLVM_LIBC_SRC_STRING_STRNCASECMP_H |
