[libc-commits] [libc] 8baa87d - [libc] Enable MPFR library for math functions test
Hedin GarcĂa via libc-commits
libc-commits at lists.llvm.org
Tue Jul 27 13:40:41 PDT 2021
Author: Hedin Garca
Date: 2021-07-27T20:40:04Z
New Revision: 8baa87d91811a3da0dc69550b84a773d98902c8b
URL: https://github.com/llvm/llvm-project/commit/8baa87d91811a3da0dc69550b84a773d98902c8b
DIFF: https://github.com/llvm/llvm-project/commit/8baa87d91811a3da0dc69550b84a773d98902c8b.diff
LOG: [libc] Enable MPFR library for math functions test
Included more math functions to Windows's entrypoints
and made a cmake option (-DLLVM_LIBC_MPFR_INSTALL_PATH)
where the user can specify the install path where the MPFR
library was built so it can be linked. The try_compile was
moved to LLVMLibCCheckMPFR.cmake, so the variable that is
set after this process can retain its value in other files
of the same parent file. A direct reason for this is for
LIBC_TESTS_CAN_USE_MPFR to be true when the user specifies
MPFR's path and retain its value even after leaving the file.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D106894
Added:
libc/cmake/modules/LLVMLibCCheckMPFR.cmake
Modified:
libc/CMakeLists.txt
libc/config/windows/README.md
libc/config/windows/entrypoints.txt
libc/utils/MPFRWrapper/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 37d996fa52fc9..bfab38e5c3ff6 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -19,6 +19,7 @@ string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS)
# Defines LIBC_TARGET_ARCHITECTURE and associated macros.
include(LLVMLibCArchitectures)
+include(LLVMLibCCheckMPFR)
# 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=...)")
diff --git a/libc/cmake/modules/LLVMLibCCheckMPFR.cmake b/libc/cmake/modules/LLVMLibCCheckMPFR.cmake
new file mode 100644
index 0000000000000..46f679f1330d3
--- /dev/null
+++ b/libc/cmake/modules/LLVMLibCCheckMPFR.cmake
@@ -0,0 +1,14 @@
+set(LLVM_LIBC_MPFR_INSTALL_PATH "" CACHE PATH "Path to where MPFR is installed (e.g. C:/src/install or ~/src/install)")
+
+if(LLVM_LIBC_MPFR_INSTALL_PATH)
+ set(LIBC_TESTS_CAN_USE_MPFR TRUE)
+else()
+ try_compile(
+ LIBC_TESTS_CAN_USE_MPFR
+ ${CMAKE_CURRENT_BINARY_DIR}
+ SOURCES
+ ${LIBC_SOURCE_DIR}/utils/MPFRWrapper/check_mpfr.cpp
+ LINK_LIBRARIES
+ -lmpfr -lgmp
+ )
+endif()
diff --git a/libc/config/windows/README.md b/libc/config/windows/README.md
index 8e01a409f9247..ca3cf1a2f0c87 100644
--- a/libc/config/windows/README.md
+++ b/libc/config/windows/README.md
@@ -62,6 +62,24 @@ libc, and finally, build and test the libc.
cmake -G Ninja ../llvm-project/llvm -DCMAKE_C_COMPILER=C:/src/clang-build/bin/clang-cl.exe -DCMAKE_CXX_COMPILER=C:/src/clang-build/bin/clang-cl.exe -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_FORCE_BUILD_RUNTIME=libc -DLLVM_ENABLE_PROJECTS=libc -DLLVM_NATIVE_ARCH=x86_64 -DLLVM_HOST_TRIPLE=x86_64-window-x86-gnu
```
+ Some LLVM libc math unittests test correctness/accuracy against results from
+ the [GNU MPFR library](https://www.mpfr.org/). If you want to run math tests
+ which use MPFR, and if MPFR on your machine is not installed in the default
+ include and linker lookup directories, then you can specify the MPFR install
+ directory by passing an additional CMake option as follows:
+
+ -DLLVM_LIBC_MPFR_INSTALL_PATH=<path/mpfr/install/dir>
+
+ If the above option is specified, then `${LLVM_LIBC_MPFR_INSTALL_PATH}/include`
+ will be added to the include directories, and
+ `${LLVM_LIBC_MPFR_INSTALL_PATH}/lib` will be added to the linker lookup
+ directories.
+
+ NOTE: The GNU MPFR library depends on the
+ [GNU GMP library](https://gmplib.org/). If you specify the above option, then it
+ will be assumed that GMP is also installed in the same directory or availabe in
+ the default paths.
+
10. Build LLVM libc using:
```
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 9ef14fe77edc0..20a59a0184635 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -45,30 +45,73 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.copysign
libc.src.math.copysignf
libc.src.math.copysignl
- libc.src.math.fdimf
+ libc.src.math.ceil
+ libc.src.math.ceilf
+ libc.src.math.ceill
+ libc.src.math.fabs
+ libc.src.math.fabsf
+ libc.src.math.fabsl
libc.src.math.fdim
+ libc.src.math.fdimf
libc.src.math.fdiml
+ libc.src.math.floor
+ libc.src.math.floorf
+ libc.src.math.floorl
+ libc.src.math.fma
+ libc.src.math.fmaf
libc.src.math.fmin
libc.src.math.fminf
libc.src.math.fminl
libc.src.math.fmax
libc.src.math.fmaxf
libc.src.math.fmaxl
+ libc.src.math.frexp
+ libc.src.math.frexpf
+ libc.src.math.frexpl
+ libc.src.math.hypot
+ libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
libc.src.math.ilogbl
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
+ libc.src.math.llround
+ libc.src.math.llroundf
+ libc.src.math.llroundl
libc.src.math.logb
libc.src.math.logbf
- libc.src.math.logbl
+ libc.src.math.logbl
+ libc.src.math.lround
+ libc.src.math.lroundf
+ libc.src.math.lroundl
libc.src.math.modf
libc.src.math.modff
libc.src.math.modfl
+ libc.src.math.nearbyint
+ libc.src.math.nearbyintf
+ libc.src.math.nearbyintl
libc.src.math.nextafter
libc.src.math.nextafterf
libc.src.math.nextafterl
+ libc.src.math.remainderf
+ libc.src.math.remainder
+ libc.src.math.remainderl
+ libc.src.math.remquof
+ libc.src.math.remquo
+ libc.src.math.remquol
+ libc.src.math.rint
+ libc.src.math.rintf
+ libc.src.math.rintl
+ libc.src.math.round
+ libc.src.math.roundf
+ libc.src.math.roundl
+ libc.src.math.sqrt
+ libc.src.math.sqrtf
+ libc.src.math.sqrtl
+ libc.src.math.trunc
+ libc.src.math.truncf
+ libc.src.math.truncl
)
set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index 6f1bb76da7e83..6084653b3f29e 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -1,19 +1,14 @@
-try_compile(
- LIBC_TESTS_CAN_USE_MPFR
- ${CMAKE_CURRENT_BINARY_DIR}
- SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/check_mpfr.cpp
- LINK_LIBRARIES
- -lmpfr -lgmp
-)
-
if(LIBC_TESTS_CAN_USE_MPFR)
add_library(libcMPFRWrapper
MPFRUtils.cpp
MPFRUtils.h
)
add_dependencies(libcMPFRWrapper libc.utils.CPP.standalone_cpp libc.utils.FPUtil.fputil LibcUnitTest)
- target_link_libraries(libcMPFRWrapper -lmpfr -lgmp LibcFPTestHelpers LibcUnitTest)
+ if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
+ target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ endif()
+ target_link_libraries(libcMPFRWrapper LibcFPTestHelpers LibcUnitTest mpfr gmp)
else()
message(WARNING "Math tests using MPFR will be skipped.")
endif()
More information about the libc-commits
mailing list