Implement double precision log1p function correctly rounded to all rounding modes. **Performance** - For `0.5 <= x <= 2`, the fast pass hitting rate is about 99.93%. - Benchmarks with `./perf.sh` tool from the CORE-MATH project, unit is (CPU clocks / call). - Reciprocal throughput from CORE-MATH's perf tool on Ryzen 5900X: ``` $ ./perf.sh log1p GNU libc version: 2.35 GNU libc release: stable -- CORE-MATH reciprocal throughput -- with FMA [####################] 100 % Ntrial = 20 ; Min = 39.792 + 1.011 clc/call; Median-Min = 0.940 clc/call; Max = 41.373 clc/call; -- CORE-MATH reciprocal throughput -- without FMA (-march=x86-64-v2) [####################] 100 % Ntrial = 20 ; Min = 87.285 + 1.135 clc/call; Median-Min = 1.299 clc/call; Max = 89.715 clc/call; -- System LIBC reciprocal throughput -- [####################] 100 % Ntrial = 20 ; Min = 20.666 + 0.123 clc/call; Median-Min = 0.125 clc/call; Max = 20.828 clc/call; -- LIBC reciprocal throughput -- with FMA [####################] 100 % Ntrial = 20 ; Min = 20.928 + 0.771 clc/call; Median-Min = 0.725 clc/call; Max = 22.767 clc/call; -- LIBC reciprocal throughput -- without FMA [####################] 100 % Ntrial = 20 ; Min = 31.461 + 0.528 clc/call; Median-Min = 0.602 clc/call; Max = 36.809 clc/call; ``` - Latency from CORE-MATH's perf tool on Ryzen 5900X: ``` $ ./perf.sh log1p --latency GNU libc version: 2.35 GNU libc release: stable -- CORE-MATH latency -- with FMA [####################] 100 % Ntrial = 20 ; Min = 77.875 + 0.062 clc/call; Median-Min = 0.051 clc/call; Max = 78.003 clc/call; -- CORE-MATH latency -- without FMA (-march=x86-64-v2) [####################] 100 % Ntrial = 20 ; Min = 101.958 + 1.202 clc/call; Median-Min = 1.325 clc/call; Max = 104.452 clc/call; -- System LIBC latency -- [####################] 100 % Ntrial = 20 ; Min = 60.581 + 1.443 clc/call; Median-Min = 1.611 clc/call; Max = 62.285 clc/call; -- LIBC latency -- with FMA [####################] 100 % Ntrial = 20 ; Min = 48.817 + 1.108 clc/call; Median-Min = 1.300 clc/call; Max = 50.282 clc/call; -- LIBC latency -- without FMA [####################] 100 % Ntrial = 20 ; Min = 61.121 + 0.599 clc/call; Median-Min = 0.761 clc/call; Max = 62.020 clc/call; ``` - Accurate pass latency: ``` $ ./perf.sh log1p --latency --simple_stat GNU libc version: 2.35 GNU libc release: stable -- CORE-MATH latency -- with FMA 760.444 -- CORE-MATH latency -- without FMA (-march=x86-64-v2) 827.880 -- LIBC latency -- with FMA 711.837 -- LIBC latency -- without FMA 764.317 ``` Reviewed By: zimmermann6 Differential Revision: https://reviews.llvm.org/D151049
Building and Testing LLVM libc on Windows
Setting Up Environment
To build LLVM libc on Windows, first build Clang using the following steps.
-
Open Command Prompt in Windows
-
Set TEMP and TMP to a directory. Creating this path is necessary for a successful clang build.
-
Create tmp under your preferred directory or under
C:\src:cd C:\src mkdir tmp -
In the start menu, search for "environment variables for your account". Set TEMP and TMP to
C:\src\tmpor the corresponding path elsewhere.
-
-
Download Visual Studio Community.
-
Install CMake and Ninja. (Optional, included in Visual Studio).
-
Load the Visual Studio environment variables using this command. This is crucial as it allows you to use build tools like CMake and Ninja:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64Note: Rerun this command every time you open a new Command Prompt window.
-
If you have not used Git before, install Git for Windows. Check out the LLVM source tree from Github using:
git clone https://github.com/llvm/llvm-project.git -
Ensure you have access to Clang, either by downloading from LLVM Download or building it yourself.
Building LLVM libc
In this section, Clang will be used to compile LLVM libc, and finally, build and test the libc.
-
Create a empty build directory in
C:\srcor your preferred directory and cd to it using:mkdir libc-build cd libc-build -
Run the following CMake command to generate build files. LLVM libc must be built by Clang, so ensure Clang is specified as the C and C++ compiler.
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-gnuSome LLVM libc math unittests test correctness/accuracy against results from the GNU MPFR library. 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}/includewill be added to the include directories, and${LLVM_LIBC_MPFR_INSTALL_PATH}/libwill be added to the linker lookup directories.NOTE: The GNU MPFR library depends on the GNU GMP library. 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.
-
Build LLVM libc using:
ninja libc -
Run tests using:
ninja checklibc