Skip to content

Commit

Permalink
[libc] Remove common_libc_tuners.cmake and move options into config.j…
Browse files Browse the repository at this point in the history
…son.

The name has been changed to adhere to the config option naming format.
The necessary build changes to use the new option have also been made.
  • Loading branch information
Siva Chandra Reddy committed Sep 13, 2023
1 parent e504194 commit 8a681ba
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
2 changes: 0 additions & 2 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ add_compile_definitions(LIBC_NAMESPACE=${LIBC_NAMESPACE})
# Flags to pass down to the compiler while building the libc functions.
set(LIBC_COMPILE_OPTIONS_DEFAULT "" CACHE STRING "Architecture to tell clang to optimize for (e.g. -march=... or -mcpu=...)")

include(common_libc_tuners.cmake)

list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT ${LIBC_COMMON_TUNE_OPTIONS})

# Check --print-resource-dir to find the compiler resource dir if this flag
Expand Down
2 changes: 2 additions & 0 deletions libc/cmake/modules/LLVMLibCObjectRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ function(create_entrypoint_object fq_target_name)
target_compile_options(${internal_target_name} BEFORE PRIVATE ${common_compile_options})
target_include_directories(${internal_target_name} PRIVATE ${include_dirs})
add_dependencies(${internal_target_name} ${full_deps_list})
target_link_libraries(${internal_target_name} ${full_deps_list})

add_library(
${fq_target_name}
Expand All @@ -685,6 +686,7 @@ function(create_entrypoint_object fq_target_name)
target_compile_options(${fq_target_name} BEFORE PRIVATE ${common_compile_options} -DLIBC_COPT_PUBLIC_PACKAGING)
target_include_directories(${fq_target_name} PRIVATE ${include_dirs})
add_dependencies(${fq_target_name} ${full_deps_list})
target_link_libraries(${fq_target_name} ${full_deps_list})
endif()

set_target_properties(
Expand Down
14 changes: 0 additions & 14 deletions libc/common_libc_tuners.cmake

This file was deleted.

6 changes: 6 additions & 0 deletions libc/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@
"value": true,
"doc": "Use large table for better printf long double performance."
}
},
"string": {
"LIBC_CONF_STRING_UNSAFE_WIDE_READ": {
"value": false,
"doc": "Read more than a byte at a time to perform byte-string operations like strlen."
}
}
}
2 changes: 2 additions & 0 deletions libc/docs/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ to learn about the defaults for your platform and target.
- ``LIBC_CONF_PRINTF_DISABLE_INDEX_MODE``: Disable index mode in the printf format string.
- ``LIBC_CONF_PRINTF_DISABLE_WRITE_INT``: Disable handling of %n in printf format string.
- ``LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE``: Use large table for better printf long double performance.
* **"string" options**
- ``LIBC_CONF_STRING_UNSAFE_WIDE_READ``: Read more than a byte at a time to perform byte-string operations like strlen.
8 changes: 8 additions & 0 deletions libc/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
add_subdirectory(memory_utils)

if(LIBC_CONF_STRING_UNSAFE_WIDE_READ)
list(APPEND string_config_options "-DLIBC_COPT_STRING_UNSAFE_WIDE_READ")
endif()
if(string_config_options)
list(PREPEND string_config_options "COMPILE_OPTIONS")
endif()

add_header_library(
string_utils
HDRS
Expand All @@ -10,6 +17,7 @@ add_header_library(
libc.include.stdlib
libc.src.__support.common
libc.src.__support.CPP.bitset
${string_config_options}
)

add_header_library(
Expand Down
4 changes: 2 additions & 2 deletions libc/src/string/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ LIBC_INLINE size_t string_length_byte_read(const char *src) {
// Returns the length of a string, denoted by the first occurrence
// of a null terminator.
LIBC_INLINE size_t string_length(const char *src) {
#ifdef LIBC_COPT_UNSAFE_STRING_WIDE_READ
#ifdef LIBC_COPT_STRING_UNSAFE_WIDE_READ
// Unsigned int is the default size for most processors, and on x86-64 it
// performs better than larger sizes when the src pointer can't be assumed to
// be aligned to a word boundary, so it's the size we use for reading the
Expand Down Expand Up @@ -143,7 +143,7 @@ LIBC_INLINE void *find_first_character_byte_read(const unsigned char *src,
// 'src'. If 'ch' is not found, returns nullptr.
LIBC_INLINE void *find_first_character(const unsigned char *src,
unsigned char ch, size_t max_strlen) {
#ifdef LIBC_COPT_UNSAFE_STRING_WIDE_READ
#ifdef LIBC_COPT_STRING_UNSAFE_WIDE_READ
// If the maximum size of the string is small, the overhead of aligning to a
// word boundary and generating a bitmask of the appropriate size may be
// greater than the gains from reading larger chunks. Based on some testing,
Expand Down

0 comments on commit 8a681ba

Please sign in to comment.