Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 431ea2d

Browse files
authoredDec 10, 2024
[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
1 parent 0fb0617 commit 431ea2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+365
-348
lines changed
 

‎libc/benchmarks/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ target_link_libraries(libc.benchmarks.memory_functions.opt_host
204204
PRIVATE
205205
libc-memory-benchmark
206206
libc.src.string.memcmp_opt_host.__internal__
207-
libc.src.string.bcmp_opt_host.__internal__
208207
libc.src.string.memcpy_opt_host.__internal__
209-
libc.src.string.memset_opt_host.__internal__
210-
libc.src.string.bzero_opt_host.__internal__
211208
libc.src.string.memmove_opt_host.__internal__
209+
libc.src.string.memset_opt_host.__internal__
210+
libc.src.strings.bcmp_opt_host.__internal__
211+
libc.src.strings.bzero_opt_host.__internal__
212212
benchmark_main
213213
)
214214
llvm_update_compile_flags(libc.benchmarks.memory_functions.opt_host)

‎libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,41 @@ function(add_redirector_object target_name)
452452
BEFORE PRIVATE -fPIC ${LIBC_COMPILE_OPTIONS_DEFAULT}
453453
)
454454
endfunction(add_redirector_object)
455+
456+
# Helper to define a function with multiple implementations
457+
# - Computes flags to satisfy required/rejected features and arch,
458+
# - Declares an entry point,
459+
# - Attach the REQUIRE_CPU_FEATURES property to the target,
460+
# - Add the fully qualified target to `${name}_implementations` global property for tests.
461+
function(add_implementation name impl_name)
462+
cmake_parse_arguments(
463+
"ADD_IMPL"
464+
"" # Optional arguments
465+
"" # Single value arguments
466+
"REQUIRE;SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;MLLVM_COMPILE_OPTIONS" # Multi value arguments
467+
${ARGN})
468+
469+
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
470+
# Note that '-mllvm' needs to be prefixed with 'SHELL:' to prevent CMake flag deduplication.
471+
foreach(opt IN LISTS ADD_IMPL_MLLVM_COMPILE_OPTIONS)
472+
list(APPEND ADD_IMPL_COMPILE_OPTIONS "SHELL:-mllvm ${opt}")
473+
endforeach()
474+
endif()
475+
476+
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
477+
# Prevent warning when passing x86 SIMD types as template arguments.
478+
# e.g. "warning: ignoring attributes on template argument ‘__m128i’ [-Wignored-attributes]"
479+
list(APPEND ADD_IMPL_COMPILE_OPTIONS "-Wno-ignored-attributes")
480+
endif()
481+
482+
add_entrypoint_object(${impl_name}
483+
NAME ${name}
484+
SRCS ${ADD_IMPL_SRCS}
485+
HDRS ${ADD_IMPL_HDRS}
486+
DEPENDS ${ADD_IMPL_DEPENDS}
487+
COMPILE_OPTIONS ${libc_opt_high_flag} ${ADD_IMPL_COMPILE_OPTIONS}
488+
)
489+
get_fq_target_name(${impl_name} fq_target_name)
490+
set_target_properties(${fq_target_name} PROPERTIES REQUIRE_CPU_FEATURES "${ADD_IMPL_REQUIRE}")
491+
set_property(GLOBAL APPEND PROPERTY "${name}_implementations" "${fq_target_name}")
492+
endfunction()

0 commit comments

Comments
 (0)
Please sign in to comment.