[libc-commits] [libc] [libc][math] Optimize nearest integer functions using builtins when available (PR #98376)
via libc-commits
libc-commits at lists.llvm.org
Fri Jul 12 11:11:25 PDT 2024
================
@@ -39,11 +47,19 @@ endfunction()
set(AVAILABLE_COMPILER_FEATURES "")
# Try compile a C file to check if flag is supported.
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
foreach(feature IN LISTS ALL_COMPILER_FEATURES)
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(compile_options ${LIBC_COMPILE_OPTIONS_NATIVE})
if(${feature} STREQUAL "fixed_point")
list(APPEND compile_options "-ffixed-point")
+ elseif(${feature} MATCHES "^builtin_")
+ set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT})
+ # The compiler might handle calls to rounding builtins by generating calls
+ # to the respective libc math functions, in which case we cannot use these
+ # builtins in our implementations of these functions. We check that this is
+ # not the case by trying to link an executable, since linking would fail due
+ # to unresolved references if calls to libc functions were generated.
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
----------------
overmighty wrote:
This actually doesn't work. Here, `compile_options` doesn't have `-ffreestanding` or anything like it, and the executable just gets linked with the system libc, so linking would only fail if the compiler generated a call to a function that's not implemented by the system libc. Also, I think this CMake script runs too early on to link the feature check executables with our own startup code and use `-ffreestanding`, so I'm not sure what to do.
https://github.com/llvm/llvm-project/pull/98376
More information about the libc-commits
mailing list