[libc-commits] [libc] [llvm] [libc][math] Refactor fmin to header only (PR #182290)
Xinlong Chen via libc-commits
libc-commits at lists.llvm.org
Mon Feb 23 07:17:05 PST 2026
https://github.com/Xinlong-Chen updated https://github.com/llvm/llvm-project/pull/182290
>From 35af6af6bbfbaed526e71c3f08867de61f6f8c1f Mon Sep 17 00:00:00 2001
From: xinlongchen <xinlongchen at tencent.com>
Date: Thu, 19 Feb 2026 22:10:20 +0800
Subject: [PATCH 1/2] [libc][math] Refactor fmin implementation to header-only
in src/__support/math folder.
---
libc/shared/math.h | 5 ++
libc/shared/math/fmin.h | 23 ++++++
libc/shared/math/fminbf16.h | 23 ++++++
libc/shared/math/fminf.h | 23 ++++++
libc/shared/math/fminf128.h | 23 ++++++
libc/shared/math/fminf16.h | 23 ++++++
libc/src/__support/math/CMakeLists.txt | 61 +++++++++++++++
libc/src/__support/math/fmin.h | 25 ++++++
libc/src/__support/math/fminbf16.h | 28 +++++++
libc/src/__support/math/fminf.h | 25 ++++++
libc/src/__support/math/fminf128.h | 33 ++++++++
libc/src/__support/math/fminf16.h | 31 ++++++++
libc/src/math/generic/CMakeLists.txt | 22 ++----
libc/src/math/generic/fmin.cpp | 6 +-
libc/src/math/generic/fminbf16.cpp | 7 +-
libc/src/math/generic/fminf.cpp | 6 +-
libc/src/math/generic/fminf128.cpp | 6 +-
libc/src/math/generic/fminf16.cpp | 6 +-
libc/test/shared/CMakeLists.txt | 5 ++
libc/test/shared/shared_math_test.cpp | 11 +++
.../llvm-project-overlay/libc/BUILD.bazel | 76 ++++++++++++++++++-
.../libc/test/src/math/smoke/BUILD.bazel | 8 ++
22 files changed, 434 insertions(+), 42 deletions(-)
create mode 100644 libc/shared/math/fmin.h
create mode 100644 libc/shared/math/fminbf16.h
create mode 100644 libc/shared/math/fminf.h
create mode 100644 libc/shared/math/fminf128.h
create mode 100644 libc/shared/math/fminf16.h
create mode 100644 libc/src/__support/math/fmin.h
create mode 100644 libc/src/__support/math/fminbf16.h
create mode 100644 libc/src/__support/math/fminf.h
create mode 100644 libc/src/__support/math/fminf128.h
create mode 100644 libc/src/__support/math/fminf16.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 8a5aca82c6ec3..1d62233b10c8b 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -85,6 +85,11 @@
#include "math/f16sqrtl.h"
#include "math/ffma.h"
#include "math/ffmal.h"
+#include "math/fmin.h"
+#include "math/fminbf16.h"
+#include "math/fminf.h"
+#include "math/fminf128.h"
+#include "math/fminf16.h"
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
diff --git a/libc/shared/math/fmin.h b/libc/shared/math/fmin.h
new file mode 100644
index 0000000000000..3266b6650f653
--- /dev/null
+++ b/libc/shared/math/fmin.h
@@ -0,0 +1,23 @@
+//===-- Shared fmin function ------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_FMIN_H
+#define LLVM_LIBC_SHARED_MATH_FMIN_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmin.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmin;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMIN_H
diff --git a/libc/shared/math/fminbf16.h b/libc/shared/math/fminbf16.h
new file mode 100644
index 0000000000000..b8660cb72d39c
--- /dev/null
+++ b/libc/shared/math/fminbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared fminbf16 function --------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_FMINBF16_H
+#define LLVM_LIBC_SHARED_MATH_FMINBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fminbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fminbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMINBF16_H
diff --git a/libc/shared/math/fminf.h b/libc/shared/math/fminf.h
new file mode 100644
index 0000000000000..aa6c04fb8c154
--- /dev/null
+++ b/libc/shared/math/fminf.h
@@ -0,0 +1,23 @@
+//===-- Shared fminf function -----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_FMINF_H
+#define LLVM_LIBC_SHARED_MATH_FMINF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fminf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fminf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMINF_H
diff --git a/libc/shared/math/fminf128.h b/libc/shared/math/fminf128.h
new file mode 100644
index 0000000000000..44d7c883784e6
--- /dev/null
+++ b/libc/shared/math/fminf128.h
@@ -0,0 +1,23 @@
+//===-- Shared fminf128 function --------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_FMINF128_H
+#define LLVM_LIBC_SHARED_MATH_FMINF128_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fminf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fminf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMINF128_H
diff --git a/libc/shared/math/fminf16.h b/libc/shared/math/fminf16.h
new file mode 100644
index 0000000000000..469e69fc48c06
--- /dev/null
+++ b/libc/shared/math/fminf16.h
@@ -0,0 +1,23 @@
+//===-- Shared fminf16 function ---------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_FMINF16_H
+#define LLVM_LIBC_SHARED_MATH_FMINF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fminf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fminf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMINF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e21fe8ef0ab93..41b36ebf3f460 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -762,6 +762,67 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ fmin
+ HDRS
+ fmin.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.common
+ libc.src.__support.macros.config
+ FLAGS
+ MISC_MATH_BASIC_OPS_OPT
+)
+
+add_header_library(
+ fminf
+ HDRS
+ fminf.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.common
+ libc.src.__support.macros.config
+ FLAGS
+ MISC_MATH_BASIC_OPS_OPT
+)
+
+add_header_library(
+ fminf128
+ HDRS
+ fminf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fminf16
+ HDRS
+ fminf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.common
+ libc.src.__support.macros.config
+ FLAGS
+ MISC_MATH_BASIC_OPS_OPT
+)
+
+add_header_library(
+ fminbf16
+ HDRS
+ fminbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.common
+ libc.src.__support.macros.config
+ FLAGS
+ MISC_MATH_BASIC_OPS_OPT
+)
+
add_header_library(
f16sqrt
HDRS
diff --git a/libc/src/__support/math/fmin.h b/libc/src/__support/math/fmin.h
new file mode 100644
index 0000000000000..21b9eebbb6257
--- /dev/null
+++ b/libc/src/__support/math/fmin.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmin --------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMIN_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMIN_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE double fmin(double x, double y) { return fputil::fmin(x, y); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMIN_H
diff --git a/libc/src/__support/math/fminbf16.h b/libc/src/__support/math/fminbf16.h
new file mode 100644
index 0000000000000..30a26c1c48e47
--- /dev/null
+++ b/libc/src/__support/math/fminbf16.h
@@ -0,0 +1,28 @@
+//===-- Implementation header for fminbf16 ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMINBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMINBF16_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE bfloat16 fminbf16(bfloat16 x, bfloat16 y) {
+ return fputil::fmin(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMINBF16_H
diff --git a/libc/src/__support/math/fminf.h b/libc/src/__support/math/fminf.h
new file mode 100644
index 0000000000000..308e51494806b
--- /dev/null
+++ b/libc/src/__support/math/fminf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fminf -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMINF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMINF_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float fminf(float x, float y) { return fputil::fmin(x, y); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMINF_H
diff --git a/libc/src/__support/math/fminf128.h b/libc/src/__support/math/fminf128.h
new file mode 100644
index 0000000000000..5aabc9d7872fd
--- /dev/null
+++ b/libc/src/__support/math/fminf128.h
@@ -0,0 +1,33 @@
+//===-- Implementation header for fminf128 ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMINF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMINF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float128 fminf128(float128 x, float128 y) {
+ return fputil::fmin(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMINF128_H
diff --git a/libc/src/__support/math/fminf16.h b/libc/src/__support/math/fminf16.h
new file mode 100644
index 0000000000000..c6c0f5e6565cb
--- /dev/null
+++ b/libc/src/__support/math/fminf16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for fminf16 -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMINF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMINF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 fminf16(float16 x, float16 y) { return fputil::fmin(x, y); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMINF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 57a29665318a3..e423c4f096aee 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2111,9 +2111,7 @@ add_entrypoint_object(
HDRS
../fmin.h
DEPENDS
- libc.src.__support.FPUtil.basic_operations
- FLAGS
- MISC_MATH_BASIC_OPS_OPT
+ libc.src.__support.math.fmin
)
add_entrypoint_object(
@@ -2123,9 +2121,7 @@ add_entrypoint_object(
HDRS
../fminf.h
DEPENDS
- libc.src.__support.FPUtil.basic_operations
- FLAGS
- MISC_MATH_BASIC_OPS_OPT
+ libc.src.__support.math.fminf
)
add_entrypoint_object(
@@ -2145,8 +2141,7 @@ add_entrypoint_object(
HDRS
../fminf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.fminf128
)
add_entrypoint_object(
@@ -2156,10 +2151,7 @@ add_entrypoint_object(
HDRS
../fminf16.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
- FLAGS
- MISC_MATH_BASIC_OPS_OPT
+ libc.src.__support.math.fminf16
)
add_entrypoint_object(
@@ -2169,11 +2161,7 @@ add_entrypoint_object(
HDRS
../fminbf16.h
DEPENDS
- libc.src.__support.common
- libc.src.__support.FPUtil.basic_operations
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.fminbf16
FLAGS
MISC_MATH_BASIC_OPS_OPT
)
diff --git a/libc/src/math/generic/fmin.cpp b/libc/src/math/generic/fmin.cpp
index 2351874029c72..b3bb623dc414b 100644
--- a/libc/src/math/generic/fmin.cpp
+++ b/libc/src/math/generic/fmin.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fmin.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmin.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(double, fmin, (double x, double y)) {
- return fputil::fmin(x, y);
+ return math::fmin(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fminbf16.cpp b/libc/src/math/generic/fminbf16.cpp
index c3e29ee10c8b6..514f38f55cacd 100644
--- a/libc/src/math/generic/fminbf16.cpp
+++ b/libc/src/math/generic/fminbf16.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fminbf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fminbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, fminbf16, (bfloat16 x, bfloat16 y)) {
- return fputil::fmin(x, y);
+ return math::fminbf16(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fminf.cpp b/libc/src/math/generic/fminf.cpp
index 83dd0aa66b54a..495f2d1f9cfba 100644
--- a/libc/src/math/generic/fminf.cpp
+++ b/libc/src/math/generic/fminf.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fminf.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fminf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, fminf, (float x, float y)) {
- return fputil::fmin(x, y);
+ return math::fminf(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fminf128.cpp b/libc/src/math/generic/fminf128.cpp
index 184b7e3c21532..fa5591ad5941e 100644
--- a/libc/src/math/generic/fminf128.cpp
+++ b/libc/src/math/generic/fminf128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fminf128.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fminf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float128, fminf128, (float128 x, float128 y)) {
- return fputil::fmin(x, y);
+ return math::fminf128(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fminf16.cpp b/libc/src/math/generic/fminf16.cpp
index 8b69273a906ec..00ff5dd6138fb 100644
--- a/libc/src/math/generic/fminf16.cpp
+++ b/libc/src/math/generic/fminf16.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fminf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fminf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, fminf16, (float16 x, float16 y)) {
- return fputil::fmin(x, y);
+ return math::fminf16(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 53ad309af4f30..cba6cb8c2bbef 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -81,6 +81,11 @@ add_fp_unittest(
libc.src.__support.math.f16sqrtl
libc.src.__support.math.ffma
libc.src.__support.math.ffmal
+ libc.src.__support.math.fmin
+ libc.src.__support.math.fminbf16
+ libc.src.__support.math.fminf
+ libc.src.__support.math.fminf128
+ libc.src.__support.math.fminf16
libc.src.__support.math.frexpf
libc.src.__support.math.frexpf128
libc.src.__support.math.frexpf16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 7f2f39ac7a285..f002aa54b8105 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -42,6 +42,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_FP_EQ(float16(10.0),
LIBC_NAMESPACE::shared::f16fmaf(2.0f, 3.0f, 4.0f));
+ EXPECT_FP_EQ(1.0f16,
+ LIBC_NAMESPACE::shared::fminf16(float16(1.0), float16(2.0)));
+
#ifdef LIBC_TYPES_HAS_FLOAT128
EXPECT_FP_EQ(10.0f16, LIBC_NAMESPACE::shared::f16fmaf128(
@@ -122,6 +125,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
LIBC_NAMESPACE::shared::frexpf(24.0f, &exponent));
EXPECT_EQ(exponent, 5);
+ EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::fminf(1.0f, 2.0f));
+
EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbf(1.0f));
ASSERT_FP_EQ(float(8 << 5), LIBC_NAMESPACE::shared::ldexpf(8.0f, 5));
@@ -167,6 +172,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_FP_EQ(0x1p+0, LIBC_NAMESPACE::shared::exp10(0.0));
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::expm1(0.0));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::ffma(0.0, 0.0, 0.0));
+ EXPECT_FP_EQ(1.0, LIBC_NAMESPACE::shared::fmin(1.0, 2.0));
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::fsqrt(0.0));
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::log(1.0));
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::log10(1.0));
@@ -217,6 +223,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
float128(24), &exponent));
EXPECT_EQ(exponent, 5);
+ EXPECT_FP_EQ(float128(1.0),
+ LIBC_NAMESPACE::shared::fminf128(float128(1.0), float128(2.0)));
+
EXPECT_EQ(3, LIBC_NAMESPACE::shared::ilogbf128(float128(8.0)));
ASSERT_FP_EQ(float128(8 << 5),
LIBC_NAMESPACE::shared::ldexpf128(float128(8), 5));
@@ -257,4 +266,6 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16addf(2.0f, 3.0f));
EXPECT_FP_EQ(bfloat16(10.0),
LIBC_NAMESPACE::shared::bf16fmaf(2.0f, 3.0f, 4.0f));
+ EXPECT_FP_EQ(bfloat16(1.0),
+ LIBC_NAMESPACE::shared::fminbf16(bfloat16(1.0), bfloat16(2.0)));
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index b90688af7a1d2..55dafacf7fbe0 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3116,6 +3116,57 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_fmin",
+ hdrs = ["src/__support/math/fmin.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_fminf",
+ hdrs = ["src/__support/math/fminf.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_fminf128",
+ hdrs = ["src/__support/math/fminf128.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_fminf16",
+ hdrs = ["src/__support/math/fminf16.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_fminbf16",
+ hdrs = ["src/__support/math/fminbf16.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_basic_operations",
+ ":__support_fputil_bfloat16",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_frexpf128",
hdrs = ["src/__support/math/frexpf128.h"],
@@ -5083,15 +5134,32 @@ libc_math_function(name = "fmaximum_numf128")
libc_math_function(name = "fmaximum_numf16")
-libc_math_function(name = "fmin")
+libc_math_function(
+ name = "fmin",
+ additional_deps = [":__support_math_fmin"],
+)
-libc_math_function(name = "fminf")
+libc_math_function(
+ name = "fminf",
+ additional_deps = [":__support_math_fminf"],
+)
libc_math_function(name = "fminl")
-libc_math_function(name = "fminf128")
+libc_math_function(
+ name = "fminf128",
+ additional_deps = [":__support_math_fminf128"],
+)
+
+libc_math_function(
+ name = "fminf16",
+ additional_deps = [":__support_math_fminf16"],
+)
-libc_math_function(name = "fminf16")
+libc_math_function(
+ name = "fminbf16",
+ additional_deps = [":__support_math_fminbf16"],
+)
libc_math_function(name = "fminimum")
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index 5b093dbdca7cb..0ac2ed1b38fd4 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -639,6 +639,14 @@ math_test(
hdrs = ["FMinTest.h"],
)
+math_test(
+ name = "fminbf16",
+ hdrs = ["FMinTest.h"],
+ deps = [
+ "//libc:__support_fputil_bfloat16",
+ ],
+)
+
math_test(
name = "fminimum",
hdrs = ["FMinimumTest.h"],
>From a190999427b6b1a4a2caf3822db1276816deb3f5 Mon Sep 17 00:00:00 2001
From: xinlongchen <xinlongchen at tencent.com>
Date: Thu, 19 Feb 2026 23:11:39 +0800
Subject: [PATCH 2/2] add type guard in libc/shared/math/fminf16|f128, fix
build error in windows
---
libc/shared/math/fminf128.h | 6 ++++++
libc/shared/math/fminf16.h | 6 ++++++
2 files changed, 12 insertions(+)
diff --git a/libc/shared/math/fminf128.h b/libc/shared/math/fminf128.h
index 44d7c883784e6..2970bc3fd1c4c 100644
--- a/libc/shared/math/fminf128.h
+++ b/libc/shared/math/fminf128.h
@@ -9,6 +9,10 @@
#ifndef LLVM_LIBC_SHARED_MATH_FMINF128_H
#define LLVM_LIBC_SHARED_MATH_FMINF128_H
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
#include "shared/libc_common.h"
#include "src/__support/math/fminf128.h"
@@ -20,4 +24,6 @@ using math::fminf128;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
+#endif // LIBC_TYPES_HAS_FLOAT128
+
#endif // LLVM_LIBC_SHARED_MATH_FMINF128_H
diff --git a/libc/shared/math/fminf16.h b/libc/shared/math/fminf16.h
index 469e69fc48c06..c9be529060c0d 100644
--- a/libc/shared/math/fminf16.h
+++ b/libc/shared/math/fminf16.h
@@ -9,6 +9,10 @@
#ifndef LLVM_LIBC_SHARED_MATH_FMINF16_H
#define LLVM_LIBC_SHARED_MATH_FMINF16_H
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
#include "shared/libc_common.h"
#include "src/__support/math/fminf16.h"
@@ -20,4 +24,6 @@ using math::fminf16;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
+#endif // LIBC_TYPES_HAS_FLOAT16
+
#endif // LLVM_LIBC_SHARED_MATH_FMINF16_H
More information about the libc-commits
mailing list