[libc-commits] [libc] 1b1e14f - [libc][math] Qualify f16add functions to constexpr (#195429)
via libc-commits
libc-commits at lists.llvm.org
Sat May 2 03:17:41 PDT 2026
Author: Kiriti Ponduri
Date: 2026-05-02T13:17:35+03:00
New Revision: 1b1e14f1ea43a6d5e583a3e58062f3730fd42387
URL: https://github.com/llvm/llvm-project/commit/1b1e14f1ea43a6d5e583a3e58062f3730fd42387
DIFF: https://github.com/llvm/llvm-project/commit/1b1e14f1ea43a6d5e583a3e58062f3730fd42387.diff
LOG: [libc][math] Qualify f16add functions to constexpr (#195429)
Signed-off-by: udaykiriti <udaykiriti624 at gmail.com>
Added:
Modified:
libc/src/__support/math/f16add.h
libc/src/__support/math/f16addf.h
libc/src/__support/math/f16addf128.h
libc/src/__support/math/f16addl.h
libc/test/shared/CMakeLists.txt
libc/test/shared/shared_math_constexpr_test.cpp
Removed:
################################################################################
diff --git a/libc/src/__support/math/f16add.h b/libc/src/__support/math/f16add.h
index 7e046c3f115dc..a75d2189b6fd7 100644
--- a/libc/src/__support/math/f16add.h
+++ b/libc/src/__support/math/f16add.h
@@ -19,7 +19,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float16 f16add(double x, double y) {
+LIBC_INLINE constexpr float16 f16add(double x, double y) {
return fputil::generic::add<float16>(x, y);
}
diff --git a/libc/src/__support/math/f16addf.h b/libc/src/__support/math/f16addf.h
index 5e140bc6e5373..2c91a2ad86051 100644
--- a/libc/src/__support/math/f16addf.h
+++ b/libc/src/__support/math/f16addf.h
@@ -19,7 +19,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float16 f16addf(float x, float y) {
+LIBC_INLINE constexpr float16 f16addf(float x, float y) {
return fputil::generic::add<float16>(x, y);
}
diff --git a/libc/src/__support/math/f16addf128.h b/libc/src/__support/math/f16addf128.h
index 8d259a273a8d1..d4316ce24b188 100644
--- a/libc/src/__support/math/f16addf128.h
+++ b/libc/src/__support/math/f16addf128.h
@@ -21,7 +21,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float16 f16addf128(float128 x, float128 y) {
+LIBC_INLINE constexpr float16 f16addf128(float128 x, float128 y) {
return fputil::generic::add<float16>(x, y);
}
diff --git a/libc/src/__support/math/f16addl.h b/libc/src/__support/math/f16addl.h
index 88f16857be48e..265ad52eedb9e 100644
--- a/libc/src/__support/math/f16addl.h
+++ b/libc/src/__support/math/f16addl.h
@@ -19,7 +19,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE float16 f16addl(long double x, long double y) {
+LIBC_INLINE constexpr float16 f16addl(long double x, long double y) {
return fputil::generic::add<float16>(x, y);
}
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 27701bf1bbeee..c5781cca1d16e 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -454,6 +454,10 @@ add_fp_unittest(
libc.src.__support.math.dmulf128
libc.src.__support.math.dmull
libc.src.__support.math.dsqrtf128
+ libc.src.__support.math.f16add
+ libc.src.__support.math.f16addf
+ libc.src.__support.math.f16addf128
+ libc.src.__support.math.f16addl
libc.src.__support.math.fadd
libc.src.__support.math.faddf128
libc.src.__support.math.faddl
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 4158338078718..7422017f5d3ee 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -118,6 +118,17 @@ static_assert(0.0f == LIBC_NAMESPACE::shared::fsub(0.0, 0.0));
static_assert(0.0f16 == LIBC_NAMESPACE::shared::ceilf16(0.0f16));
static_assert(0.0f16 == LIBC_NAMESPACE::shared::copysignf16(0.0f16, 0.0f16));
+static_assert(3.0f16 == LIBC_NAMESPACE::shared::f16add(1.0, 2.0));
+static_assert(3.0f16 == LIBC_NAMESPACE::shared::f16addf(1.0f, 2.0f));
+
+// TODO: make available after long double problem is fixed
+#if 0
+static_assert(3.0f16 == LIBC_NAMESPACE::shared::f16addl(1.0L, 2.0L));
+#endif
+#ifdef LIBC_TYPES_HAS_FLOAT128
+static_assert(3.0f16 ==
+ LIBC_NAMESPACE::shared::f16addf128(float128(1.0), float128(2.0)));
+#endif
static_assert(1.0f16 == LIBC_NAMESPACE::shared::fabsf16(-1.0f16));
static_assert(1.0f16 == LIBC_NAMESPACE::shared::fdimf16(1.0f16, 0.0f16));
static_assert(3.0f16 == LIBC_NAMESPACE::shared::floorf16(3.7f16));
More information about the libc-commits
mailing list