[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
This commit is contained in:
Nick Desaulniers
2024-12-10 08:58:45 -08:00
committed by GitHub
parent 0fb06172f1
commit 431ea2d076
45 changed files with 365 additions and 348 deletions

View File

@@ -204,11 +204,11 @@ target_link_libraries(libc.benchmarks.memory_functions.opt_host
PRIVATE
libc-memory-benchmark
libc.src.string.memcmp_opt_host.__internal__
libc.src.string.bcmp_opt_host.__internal__
libc.src.string.memcpy_opt_host.__internal__
libc.src.string.memset_opt_host.__internal__
libc.src.string.bzero_opt_host.__internal__
libc.src.string.memmove_opt_host.__internal__
libc.src.string.memset_opt_host.__internal__
libc.src.strings.bcmp_opt_host.__internal__
libc.src.strings.bzero_opt_host.__internal__
benchmark_main
)
llvm_update_compile_flags(libc.benchmarks.memory_functions.opt_host)

View File

@@ -452,3 +452,41 @@ function(add_redirector_object target_name)
BEFORE PRIVATE -fPIC ${LIBC_COMPILE_OPTIONS_DEFAULT}
)
endfunction(add_redirector_object)
# 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()

View File

@@ -416,12 +416,12 @@ function(add_integration_test test_name)
libc.test.IntegrationTest.test
# We always add the memory functions objects. This is because the
# compiler's codegen can emit calls to the C memory functions.
libc.src.string.bcmp
libc.src.string.bzero
libc.src.string.memcmp
libc.src.string.memcpy
libc.src.string.memmove
libc.src.string.memset
libc.src.strings.bcmp
libc.src.strings.bzero
)
if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
@@ -583,13 +583,13 @@ function(add_libc_hermetic test_name)
libc.startup.${LIBC_TARGET_OS}.crt1
# We always add the memory functions objects. This is because the
# compiler's codegen can emit calls to the C memory functions.
libc.src.string.bcmp
libc.src.string.bzero
libc.src.__support.StringUtil.error_to_string
libc.src.string.memcmp
libc.src.string.memcpy
libc.src.string.memmove
libc.src.string.memset
libc.src.__support.StringUtil.error_to_string
libc.src.strings.bcmp
libc.src.strings.bzero
)
if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
@@ -766,3 +766,33 @@ function(add_libc_test test_name)
endif()
endif()
endfunction(add_libc_test)
# Tests all implementations that can run on the target CPU.
function(add_libc_multi_impl_test name suite)
get_property(fq_implementations GLOBAL PROPERTY ${name}_implementations)
foreach(fq_config_name IN LISTS fq_implementations)
get_target_property(required_cpu_features ${fq_config_name} REQUIRE_CPU_FEATURES)
cpu_supports(can_run "${required_cpu_features}")
if(can_run)
string(FIND ${fq_config_name} "." last_dot_loc REVERSE)
math(EXPR name_loc "${last_dot_loc} + 1")
string(SUBSTRING ${fq_config_name} ${name_loc} -1 target_name)
add_libc_test(
${target_name}_test
SUITE
${suite}
COMPILE_OPTIONS
${LIBC_COMPILE_OPTIONS_NATIVE}
LINK_LIBRARIES
LibcMemoryHelpers
${ARGN}
DEPENDS
${fq_config_name}
libc.src.__support.macros.sanitizer
)
get_fq_target_name(${fq_config_name}_test fq_target_name)
else()
message(STATUS "Skipping test for '${fq_config_name}' insufficient host cpu features '${required_cpu_features}'")
endif()
endforeach()
endfunction()

View File

@@ -31,10 +31,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.setjmp.setjmp
# string.h entrypoints
libc.src.string.bcmp
libc.src.string.bcopy
libc.src.string.bzero
libc.src.string.index
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
@@ -45,10 +41,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.memrchr
libc.src.string.memset
libc.src.string.memset_explicit
libc.src.string.rindex
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
@@ -62,7 +56,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
libc.src.string.strncasecmp
libc.src.string.strncat
libc.src.string.strncmp
libc.src.string.strncpy
@@ -76,6 +69,15 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strtok_r
libc.src.string.strxfrm
# strings.h entrypoints
libc.src.strings.bcmp
libc.src.strings.bcopy
libc.src.strings.bzero
libc.src.strings.index
libc.src.strings.rindex
libc.src.strings.strcasecmp
libc.src.strings.strncasecmp
# inttypes.h entrypoints
libc.src.inttypes.imaxabs
libc.src.inttypes.imaxdiv

View File

@@ -27,10 +27,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.errno.errno
# string.h entrypoints
libc.src.string.bcmp
libc.src.string.bcopy
libc.src.string.bzero
libc.src.string.index
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
@@ -41,10 +37,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.memrchr
libc.src.string.memset
libc.src.string.memset_explicit
libc.src.string.rindex
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
@@ -58,7 +52,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
libc.src.string.strncasecmp
libc.src.string.strncat
libc.src.string.strncmp
libc.src.string.strncpy
@@ -72,6 +65,15 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strtok_r
libc.src.string.strxfrm
# strings.h entrypoints
libc.src.strings.bcmp
libc.src.strings.bcopy
libc.src.strings.bzero
libc.src.strings.index
libc.src.strings.rindex
libc.src.strings.strcasecmp
libc.src.strings.strncasecmp
# inttypes.h entrypoints
libc.src.inttypes.imaxabs
libc.src.inttypes.imaxdiv

View File

@@ -21,9 +21,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.errno.errno
# string.h entrypoints
libc.src.string.bcmp
libc.src.string.bcopy
libc.src.string.bzero
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
@@ -35,7 +32,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.memset
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
@@ -46,7 +42,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
libc.src.string.strncasecmp
libc.src.string.strncat
libc.src.string.strncmp
libc.src.string.strncpy
@@ -62,6 +57,13 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strdup
libc.src.string.strndup
# strings.h entrypoints
libc.src.strings.bcmp
libc.src.strings.bcopy
libc.src.strings.bzero
libc.src.strings.strcasecmp
libc.src.strings.strncasecmp
# inttypes.h entrypoints
libc.src.inttypes.imaxabs
libc.src.inttypes.imaxdiv

View File

@@ -18,11 +18,9 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.ctype.toupper
# search.h entrypoints
libc.src.search.lfind
libc.src.search.lfind
# string.h entrypoints
libc.src.string.bcmp
libc.src.string.bzero
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
@@ -58,6 +56,10 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strdup
libc.src.string.strndup
# strings.h entrypoints
libc.src.strings.bcmp
libc.src.strings.bzero
# inttypes.h entrypoints
libc.src.inttypes.imaxabs
libc.src.inttypes.imaxdiv

View File

@@ -35,10 +35,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.ctype.toupper_l
# string.h entrypoints
libc.src.string.bcmp
libc.src.string.bcopy
libc.src.string.bzero
libc.src.string.index
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
@@ -48,10 +44,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.mempcpy
libc.src.string.memrchr
libc.src.string.memset
libc.src.string.rindex
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
@@ -66,7 +60,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
libc.src.string.strncasecmp
libc.src.string.strncat
libc.src.string.strncmp
libc.src.string.strncpy
@@ -82,6 +75,15 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strxfrm
libc.src.string.strxfrm_l
# strings.h entrypoints
libc.src.strings.bcmp
libc.src.strings.bcopy
libc.src.strings.bzero
libc.src.strings.index
libc.src.strings.rindex
libc.src.strings.strcasecmp
libc.src.strings.strncasecmp
# stdbit.h entrypoints
libc.src.stdbit.stdc_bit_ceil_uc
libc.src.stdbit.stdc_bit_ceil_ui

View File

@@ -45,10 +45,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sched.sched_yield
# string.h entrypoints
libc.src.string.bcmp
libc.src.string.bcopy
libc.src.string.bzero
libc.src.string.index
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
@@ -59,10 +55,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.memrchr
libc.src.string.memset
libc.src.string.memset_explicit
libc.src.string.rindex
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
@@ -77,7 +71,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
libc.src.string.strncasecmp
libc.src.string.strncat
libc.src.string.strncmp
libc.src.string.strncpy
@@ -93,6 +86,15 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strtok_r
libc.src.string.strxfrm
# strings.h entrypoints
libc.src.strings.bcmp
libc.src.strings.bcopy
libc.src.strings.bzero
libc.src.strings.index
libc.src.strings.rindex
libc.src.strings.strcasecmp
libc.src.strings.strncasecmp
# inttypes.h entrypoints
libc.src.inttypes.imaxabs
libc.src.inttypes.imaxdiv

View File

@@ -21,10 +21,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.errno.errno
# string.h entrypoints
libc.src.string.bcmp
libc.src.string.bcopy
libc.src.string.bzero
libc.src.string.index
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
@@ -34,10 +30,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.mempcpy
libc.src.string.memrchr
libc.src.string.memset
libc.src.string.rindex
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
@@ -48,7 +42,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
libc.src.string.strncasecmp
libc.src.string.strncat
libc.src.string.strncmp
libc.src.string.strncpy
@@ -61,6 +54,15 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strtok
libc.src.string.strtok_r
# strings.h entrypoints
libc.src.strings.bcmp
libc.src.strings.bcopy
libc.src.strings.bzero
libc.src.strings.index
libc.src.strings.rindex
libc.src.strings.strcasecmp
libc.src.strings.strncasecmp
# inttypes.h entrypoints
libc.src.inttypes.imaxabs
libc.src.inttypes.imaxdiv

View File

@@ -45,10 +45,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sched.sched_yield
# string.h entrypoints
libc.src.string.bcmp
libc.src.string.bcopy
libc.src.string.bzero
libc.src.string.index
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
@@ -59,10 +55,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.memrchr
libc.src.string.memset
libc.src.string.memset_explicit
libc.src.string.rindex
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
@@ -77,7 +71,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
libc.src.string.strncasecmp
libc.src.string.strncat
libc.src.string.strncmp
libc.src.string.strncpy
@@ -93,6 +86,14 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strtok_r
libc.src.string.strxfrm
# strings.h entrypoints
libc.src.string.index
libc.src.string.rindex
libc.src.strings.bcmp
libc.src.strings.bcopy
libc.src.strings.bzero
libc.src.strings.strcasecmp
# inttypes.h entrypoints
libc.src.inttypes.imaxabs
libc.src.inttypes.imaxdiv

View File

@@ -45,10 +45,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sched.sched_yield
# string.h entrypoints
libc.src.string.bcmp
libc.src.string.bcopy
libc.src.string.bzero
libc.src.string.index
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
@@ -59,10 +55,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.memrchr
libc.src.string.memset
libc.src.string.memset_explicit
libc.src.string.rindex
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
@@ -77,7 +71,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
libc.src.string.strncasecmp
libc.src.string.strncat
libc.src.string.strncmp
libc.src.string.strncpy
@@ -93,6 +86,15 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strtok_r
libc.src.string.strxfrm
# strings.h entrypoints
libc.src.strings.bcmp
libc.src.strings.bcopy
libc.src.strings.bzero
libc.src.strings.index
libc.src.strings.rindex
libc.src.strings.strcasecmp
libc.src.strings.strncasecmp
# inttypes.h entrypoints
libc.src.inttypes.imaxabs
libc.src.inttypes.imaxdiv

View File

@@ -18,9 +18,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.ctype.toupper
# string.h entrypoints
libc.src.string.bcmp
libc.src.string.bcopy
libc.src.string.bzero
libc.src.string.memccpy
libc.src.string.memchr
libc.src.string.memcmp
@@ -32,7 +29,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.memset
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
@@ -43,7 +39,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
libc.src.string.strncasecmp
libc.src.string.strncat
libc.src.string.strncmp
libc.src.string.strncpy
@@ -59,6 +54,13 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strdup
libc.src.string.strndup
# strings.h entrypoints
libc.src.strings.bcmp
libc.src.strings.bcopy
libc.src.strings.bzero
libc.src.strings.strcasecmp
libc.src.strings.strncasecmp
# inttypes.h entrypoints
libc.src.inttypes.imaxabs
libc.src.inttypes.imaxdiv

View File

@@ -38,5 +38,5 @@ add_libc_fuzzer(
SRCS
bcmp_fuzz.cpp
DEPENDS
libc.src.string.bcmp
libc.src.strings.bcmp
)

View File

@@ -9,7 +9,7 @@
/// Fuzzing test for llvm-libc bcmp implementation.
///
//===----------------------------------------------------------------------===//
#include "src/string/bcmp.h"
#include "src/strings/bcmp.h"
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>

View File

@@ -10,7 +10,8 @@
#define LLVM_LIBC_HDR_FUNC_FREE_H
#ifdef LIBC_FULL_BUILD
extern "C" void free(void *);
extern "C" void free(void *) noexcept;
#else // Overlay mode

View File

@@ -10,8 +10,10 @@
#define LLVM_LIBC_HDR_FUNC_MALLOC_H
#ifdef LIBC_FULL_BUILD
#include "hdr/types/size_t.h"
extern "C" void *malloc(size_t);
extern "C" void *malloc(size_t) noexcept;
#else // Overlay mode

View File

@@ -10,8 +10,10 @@
#define LLVM_LIBC_HDR_FUNC_REALLOC_H
#ifdef LIBC_FULL_BUILD
#include "hdr/types/size_t.h"
extern "C" void *realloc(void *ptr, size_t new_size);
extern "C" void *realloc(void *ptr, size_t new_size) noexcept;
#else // Overlay mode

View File

@@ -12,6 +12,7 @@ add_subdirectory(stdfix)
add_subdirectory(stdio)
add_subdirectory(stdlib)
add_subdirectory(string)
add_subdirectory(strings)
add_subdirectory(wchar)
add_subdirectory(time)

View File

@@ -34,24 +34,6 @@ add_header_library(
libc.src.__support.macros.config
)
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
@@ -98,16 +80,6 @@ add_entrypoint_object(
memrchr.h
)
add_entrypoint_object(
rindex
SRCS
rindex.cpp
HDRS
rindex.h
DEPENDS
.string_utils
)
add_entrypoint_object(
stpcpy
SRCS
@@ -171,17 +143,6 @@ add_entrypoint_object(
.memory_utils.inline_strcmp
)
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
@@ -319,17 +280,6 @@ add_entrypoint_object(
.memory_utils.inline_strcmp
)
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
@@ -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
# ------------------------------------------------------------------------------

View File

@@ -0,0 +1,97 @@
function(add_bcmp bcmp_name)
add_implementation(bcmp ${bcmp_name}
SRCS ${LIBC_SOURCE_DIR}/src/strings/bcmp.cpp
HDRS ${LIBC_SOURCE_DIR}/src/strings/bcmp.h
DEPENDS
libc.src.string.memory_utils.memory_utils
${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()
function(add_bzero bzero_name)
add_implementation(bzero ${bzero_name}
SRCS ${LIBC_SOURCE_DIR}/src/strings/bzero.cpp
HDRS ${LIBC_SOURCE_DIR}/src/strings/bzero.h
DEPENDS
libc.src.string.memory_utils.inline_memset
${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()
add_entrypoint_object(
bcopy
SRCS
bcopy.cpp
HDRS
bcopy.h
)
add_entrypoint_object(
index
SRCS
index.cpp
HDRS
index.h
DEPENDS
libc.src.string.string_utils
)
add_entrypoint_object(
rindex
SRCS
rindex.cpp
HDRS
rindex.h
DEPENDS
libc.src.string.string_utils
)
add_entrypoint_object(
strcasecmp
SRCS
strcasecmp.cpp
HDRS
strcasecmp.h
DEPENDS
libc.src.__support.ctype_utils
libc.src.string.memory_utils.inline_strcmp
)
add_entrypoint_object(
strncasecmp
SRCS
strncasecmp.cpp
HDRS
strncasecmp.h
DEPENDS
libc.src.__support.ctype_utils
libc.src.string.memory_utils.inline_strcmp
)

View File

@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/string/bcmp.h"
#include "src/strings/bcmp.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/string/memory_utils/inline_bcmp.h"

View File

@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_STRING_BCMP_H
#define LLVM_LIBC_SRC_STRING_BCMP_H
#ifndef LLVM_LIBC_SRC_STRINGS_BCMP_H
#define LLVM_LIBC_SRC_STRINGS_BCMP_H
#include "src/__support/macros/config.h"
#include <stddef.h> // size_t
@@ -18,4 +18,4 @@ int bcmp(const void *lhs, const void *rhs, size_t count);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_STRING_BCMP_H
#endif // LLVM_LIBC_SRC_STRINGS_BCMP_H

View File

@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/string/bcopy.h"
#include "src/strings/bcopy.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/string/memory_utils/inline_memmove.h"

View File

@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_STRING_BCOPY_H
#define LLVM_LIBC_SRC_STRING_BCOPY_H
#ifndef LLVM_LIBC_SRC_STRINGS_BCOPY_H
#define LLVM_LIBC_SRC_STRINGS_BCOPY_H
#include "src/__support/macros/config.h"
#include <stddef.h> // size_t
@@ -18,4 +18,4 @@ void bcopy(const void *src, void *dest, size_t count);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_STRING_BCOPY_H
#endif // LLVM_LIBC_SRC_STRINGS_BCOPY_H

View File

@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/string/bzero.h"
#include "src/strings/bzero.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/string/memory_utils/inline_bzero.h"

View File

@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_STRING_BZERO_H
#define LLVM_LIBC_SRC_STRING_BZERO_H
#ifndef LLVM_LIBC_SRC_STRINGS_BZERO_H
#define LLVM_LIBC_SRC_STRINGS_BZERO_H
#include "src/__support/macros/config.h"
#include <stddef.h> // size_t
@@ -18,4 +18,4 @@ void bzero(void *ptr, size_t count);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_STRING_BZERO_H
#endif // LLVM_LIBC_SRC_STRINGS_BZERO_H

View File

@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/string/index.h"
#include "src/strings/index.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

View File

@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_STRING_INDEX_H
#define LLVM_LIBC_SRC_STRING_INDEX_H
#ifndef LLVM_LIBC_SRC_STRINGS_INDEX_H
#define LLVM_LIBC_SRC_STRINGS_INDEX_H
#include "src/__support/macros/config.h"
@@ -17,4 +17,4 @@ char *index(const char *src, int c);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_STRING_INDEX_H
#endif // LLVM_LIBC_SRC_STRINGS_INDEX_H

View File

@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/string/rindex.h"
#include "src/strings/rindex.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

View File

@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_STRING_RINDEX_H
#define LLVM_LIBC_SRC_STRING_RINDEX_H
#ifndef LLVM_LIBC_SRC_STRINGS_RINDEX_H
#define LLVM_LIBC_SRC_STRINGS_RINDEX_H
#include "src/__support/macros/config.h"
@@ -17,4 +17,4 @@ char *rindex(const char *src, int c);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_STRING_RINDEX_H
#endif // LLVM_LIBC_SRC_STRINGS_RINDEX_H

View File

@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/string/strcasecmp.h"
#include "src/strings/strcasecmp.h"
#include "src/__support/common.h"
#include "src/__support/ctype_utils.h"

View File

@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_STRING_STRCASECMP_H
#define LLVM_LIBC_SRC_STRING_STRCASECMP_H
#ifndef LLVM_LIBC_SRC_STRINGS_STRCASECMP_H
#define LLVM_LIBC_SRC_STRINGS_STRCASECMP_H
#include "src/__support/macros/config.h"
@@ -17,4 +17,4 @@ int strcasecmp(const char *left, const char *right);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_STRING_STRCASECMP_H
#endif // LLVM_LIBC_SRC_STRINGS_STRCASECMP_H

View File

@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/string/strncasecmp.h"
#include "src/strings/strncasecmp.h"
#include "src/__support/common.h"
#include "src/__support/ctype_utils.h"

View File

@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_STRING_STRNCASECMP_H
#define LLVM_LIBC_SRC_STRING_STRNCASECMP_H
#ifndef LLVM_LIBC_SRC_STRINGS_STRNCASECMP_H
#define LLVM_LIBC_SRC_STRINGS_STRNCASECMP_H
#include "src/__support/macros/config.h"
#include <stddef.h>
@@ -18,4 +18,4 @@ int strncasecmp(const char *left, const char *right, size_t n);
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_STRING_STRNCASECMP_H
#endif // LLVM_LIBC_SRC_STRINGS_STRNCASECMP_H

View File

@@ -58,6 +58,7 @@ add_subdirectory(stdfix)
add_subdirectory(stdio)
add_subdirectory(stdlib)
add_subdirectory(string)
add_subdirectory(strings)
add_subdirectory(wchar)
add_subdirectory(time)

View File

@@ -2,35 +2,12 @@ add_custom_target(libc-string-tests)
add_subdirectory(memory_utils)
add_libc_test(
bcopy_test
SUITE
libc-string-tests
SRCS
bcopy_test.cpp
DEPENDS
libc.src.string.bcopy
LINK_LIBRARIES
LibcMemoryHelpers
)
add_header_library(
strchr_test_support
HDRS
StrchrTest.h
)
add_libc_test(
index_test
SUITE
libc-string-tests
SRCS
index_test.cpp
DEPENDS
libc.src.string.index
.strchr_test_support
)
add_libc_test(
memccpy_test
SUITE
@@ -81,17 +58,6 @@ add_libc_test(
libc.src.string.memrchr
)
add_libc_test(
rindex_test
SUITE
libc-string-tests
SRCS
rindex_test.cpp
DEPENDS
libc.src.string.rindex
.strchr_test_support
)
add_libc_test(
stpcpy_test
SUITE
@@ -153,16 +119,6 @@ add_libc_test(
libc.src.string.strcmp
)
add_libc_test(
strcasecmp_test
SUITE
libc-string-tests
SRCS
strcasecmp_test.cpp
DEPENDS
libc.src.string.strcasecmp
)
add_libc_test(
strcasestr_test
SUITE
@@ -287,16 +243,6 @@ add_libc_test(
libc.src.string.strncmp
)
add_libc_test(
strncasecmp_test
SUITE
libc-string-tests
SRCS
strncasecmp_test.cpp
DEPENDS
libc.src.string.strncasecmp
)
add_libc_test(
strncpy_test
SUITE
@@ -428,39 +374,7 @@ add_libc_test(
libc.src.string.memset_explicit
)
# Tests all implementations that can run on the target CPU.
function(add_libc_multi_impl_test name)
get_property(fq_implementations GLOBAL PROPERTY ${name}_implementations)
foreach(fq_config_name IN LISTS fq_implementations)
get_target_property(required_cpu_features ${fq_config_name} REQUIRE_CPU_FEATURES)
cpu_supports(can_run "${required_cpu_features}")
if(can_run)
string(FIND ${fq_config_name} "." last_dot_loc REVERSE)
math(EXPR name_loc "${last_dot_loc} + 1")
string(SUBSTRING ${fq_config_name} ${name_loc} -1 target_name)
add_libc_test(
${target_name}_test
SUITE
libc-string-tests
COMPILE_OPTIONS
${LIBC_COMPILE_OPTIONS_NATIVE}
LINK_LIBRARIES
LibcMemoryHelpers
${ARGN}
DEPENDS
${fq_config_name}
libc.src.__support.macros.sanitizer
)
get_fq_target_name(${fq_config_name}_test fq_target_name)
else()
message(STATUS "Skipping test for '${fq_config_name}' insufficient host cpu features '${required_cpu_features}'")
endif()
endforeach()
endfunction()
add_libc_multi_impl_test(bcmp SRCS bcmp_test.cpp)
add_libc_multi_impl_test(bzero SRCS bzero_test.cpp)
add_libc_multi_impl_test(memcmp SRCS memcmp_test.cpp)
add_libc_multi_impl_test(memcpy SRCS memcpy_test.cpp)
add_libc_multi_impl_test(memmove SRCS memmove_test.cpp)
add_libc_multi_impl_test(memset SRCS memset_test.cpp)
add_libc_multi_impl_test(memcmp libc-string-tests SRCS memcmp_test.cpp)
add_libc_multi_impl_test(memcpy libc-string-tests SRCS memcpy_test.cpp)
add_libc_multi_impl_test(memmove libc-string-tests SRCS memmove_test.cpp)
add_libc_multi_impl_test(memset libc-string-tests SRCS memset_test.cpp)

View File

@@ -0,0 +1,58 @@
add_custom_target(libc-strings-tests)
add_libc_test(
bcopy_test
SUITE
libc-strings-tests
SRCS
bcopy_test.cpp
DEPENDS
libc.src.strings.bcopy
LINK_LIBRARIES
LibcMemoryHelpers
)
add_libc_test(
index_test
SUITE
libc-strings-tests
SRCS
index_test.cpp
DEPENDS
libc.src.strings.index
libc.test.src.strchr_test_support
)
add_libc_test(
rindex_test
SUITE
libc-strings-tests
SRCS
rindex_test.cpp
DEPENDS
libc.src.strings.rindex
libc.test.src.strchr_test_support
)
add_libc_test(
strcasecmp_test
SUITE
libc-strings-tests
SRCS
strcasecmp_test.cpp
DEPENDS
libc.src.strings.strcasecmp
)
add_libc_test(
strncasecmp_test
SUITE
libc-strings-tests
SRCS
strncasecmp_test.cpp
DEPENDS
libc.src.strings.strncasecmp
)
add_libc_multi_impl_test(bcmp libc-strings-tests SRCS bcmp_test.cpp)
add_libc_multi_impl_test(bzero libc-strings-tests SRCS bzero_test.cpp)

View File

@@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//
#include "memory_utils/memory_check_utils.h"
#include "src/__support/macros/config.h"
#include "src/string/bcmp.h"
#include "src/strings/bcmp.h"
#include "test/UnitTest/Test.h"
#include "test/UnitTest/TestLogger.h"
#include "test/src/string/memory_utils/memory_check_utils.h"
namespace LIBC_NAMESPACE_DECL {

View File

@@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//
#include "src/__support/macros/config.h"
#include "src/string/bcopy.h"
#include "src/strings/bcopy.h"
#include "memory_utils/memory_check_utils.h"
#include "src/__support/CPP/span.h"
#include "src/__support/macros/config.h"
#include "test/UnitTest/MemoryMatcher.h"
#include "test/UnitTest/Test.h"
#include "test/src/string/memory_utils/memory_check_utils.h"
using LIBC_NAMESPACE::cpp::array;
using LIBC_NAMESPACE::cpp::span;

View File

@@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//
#include "memory_utils/memory_check_utils.h"
#include "src/__support/macros/config.h"
#include "src/string/bzero.h"
#include "src/strings/bzero.h"
#include "test/UnitTest/Test.h"
#include "test/src/string/memory_utils/memory_check_utils.h"
namespace LIBC_NAMESPACE_DECL {

View File

@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/string/strcasecmp.h"
#include "src/strings/strcasecmp.h"
#include "test/UnitTest/Test.h"
TEST(LlvmLibcStrCaseCmpTest, EmptyStringsShouldReturnZero) {

View File

@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/string/strncasecmp.h"
#include "src/strings/strncasecmp.h"
#include "test/UnitTest/Test.h"
TEST(LlvmLibcStrNCaseCmpTest,