[libc-commits] [libc] [libc] Add config option for fast math optimizations (PR #98029)
via libc-commits
libc-commits at lists.llvm.org
Mon Jul 8 07:38:34 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Joseph Huber (jhuber6)
<details>
<summary>Changes</summary>
Summary:
This patch adds `LIBC_COPT_MATH` that allows users to configure the
different math optimizations.
---
Full diff: https://github.com/llvm/llvm-project/pull/98029.diff
6 Files Affected:
- (modified) libc/cmake/modules/LLVMLibCCompileOptionRules.cmake (+3)
- (modified) libc/config/config.json (+6)
- (modified) libc/config/gpu/config.json (+5)
- (modified) libc/docs/configure.rst (+2)
- (modified) libc/src/math/amdgpu/CMakeLists.txt (-10)
- (modified) libc/src/math/generic/tan.cpp (+3-2)
``````````diff
diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 6d38bb491044e..11ed05d088216 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -104,6 +104,9 @@ function(_get_common_compile_options output_var flags)
list(APPEND compile_options "-Wthread-safety")
list(APPEND compile_options "-Wglobal-constructors")
endif()
+ if(LIBC_CONF_MATH)
+ list(APPEND compile_options "-DLIBC_MATH=${LIBC_CONF_MATH}")
+ endif()
elseif(MSVC)
list(APPEND compile_options "/EHs-c-")
list(APPEND compile_options "/GR-")
diff --git a/libc/config/config.json b/libc/config/config.json
index 11433c15d762e..d4499e70ed3cf 100644
--- a/libc/config/config.json
+++ b/libc/config/config.json
@@ -60,5 +60,11 @@
"value": 1073741824,
"doc": "Default size for the constinit freelist buffer used for the freelist malloc implementation (default 1o 1GB)."
}
+ },
+ "math": {
+ "LIBC_CONF_MATH": {
+ "value": 0,
+ "doc": "Configures optimizations for math functions. Values accepted are LIBC_MATH_SKIP_ACCURATE_PASS, LIBC_MATH_SMALL_TABLES, LIBC_MATH_NO_ERRNO, LIBC_MATH_NO_EXCEPT, and LIBC_MATH_FAST."
+ }
}
}
diff --git a/libc/config/gpu/config.json b/libc/config/gpu/config.json
index 53f232e31cc8a..a4139e5fe999e 100644
--- a/libc/config/gpu/config.json
+++ b/libc/config/gpu/config.json
@@ -12,5 +12,10 @@
"LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE": {
"value": false
}
+ },
+ "math": {
+ "LIBC_CONF_MATH": {
+ "value": "LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT"
+ }
}
}
diff --git a/libc/docs/configure.rst b/libc/docs/configure.rst
index 016e2e5aa5876..1b1c505279988 100644
--- a/libc/docs/configure.rst
+++ b/libc/docs/configure.rst
@@ -30,6 +30,8 @@ to learn about the defaults for your platform and target.
- ``LIBC_CONF_KEEP_FRAME_POINTER``: Keep frame pointer in functions for better debugging experience.
* **"malloc" options**
- ``LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE``: Default size for the constinit freelist buffer used for the freelist malloc implementation (default 1o 1GB).
+* **"math" options**
+ - ``LIBC_CONF_MATH``: Configures optimizations for math functions. Values accepted are LIBC_MATH_SKIP_ACCURATE_PASS, LIBC_MATH_SMALL_TABLES, LIBC_MATH_NO_ERRNO, LIBC_MATH_NO_EXCEPT, and LIBC_MATH_FAST.
* **"printf" options**
- ``LIBC_CONF_PRINTF_DISABLE_FIXED_POINT``: Disable printing fixed point values in printf and friends.
- ``LIBC_CONF_PRINTF_DISABLE_FLOAT``: Disable printing floating point values in printf and friends.
diff --git a/libc/src/math/amdgpu/CMakeLists.txt b/libc/src/math/amdgpu/CMakeLists.txt
index bc81f7b20a71d..5581700bed028 100644
--- a/libc/src/math/amdgpu/CMakeLists.txt
+++ b/libc/src/math/amdgpu/CMakeLists.txt
@@ -216,16 +216,6 @@ add_entrypoint_object(
-O2
)
-add_entrypoint_object(
- rint
- SRCS
- rint.cpp
- HDRS
- ../rint.h
- COMPILE_OPTIONS
- -O2
-)
-
add_entrypoint_object(
rintf
SRCS
diff --git a/libc/src/math/generic/tan.cpp b/libc/src/math/generic/tan.cpp
index 7f1385c4717dd..d153cc53acc80 100644
--- a/libc/src/math/generic/tan.cpp
+++ b/libc/src/math/generic/tan.cpp
@@ -127,7 +127,8 @@ LIBC_INLINE DoubleDouble tan_eval(const DoubleDouble &u) {
// Calculation a / b = a * (1/b) for Float128.
// Using the initial approximation of q ~ (1/b), then apply 2 Newton-Raphson
// iterations, before multiplying by a.
-[[maybe_unused]] Float128 newton_raphson_div(const Float128 &a, Float128 b, double q) {
+[[maybe_unused]] Float128 newton_raphson_div(const Float128 &a, Float128 b,
+ double q) {
Float128 q0(q);
constexpr Float128 TWO(2.0);
b.sign = (b.sign == Sign::POS) ? Sign::NEG : Sign::POS;
@@ -158,7 +159,7 @@ LLVM_LIBC_FUNCTION(double, tan, (double x)) {
if (LIBC_UNLIKELY(x == 0.0))
return x;
- // For |x| < 2^-27, |tan(x) - x| < ulp(x)/2.
+ // For |x| < 2^-27, |tan(x) - x| < ulp(x)/2.
#ifdef LIBC_TARGET_CPU_HAS_FMA
return fputil::multiply_add(x, 0x1.0p-54, x);
#else
``````````
</details>
https://github.com/llvm/llvm-project/pull/98029
More information about the libc-commits
mailing list