[libc-commits] [libc] 4c7dc9c - Reland "[libc][math] Refactor fmaximum_mag_num family to header-only" (#194194)

via libc-commits libc-commits at lists.llvm.org
Sat Apr 25 16:48:21 PDT 2026


Author: hulxv
Date: 2026-04-26T02:48:16+03:00
New Revision: 4c7dc9c1783fa10e5e99e28ed25103a046c02c7d

URL: https://github.com/llvm/llvm-project/commit/4c7dc9c1783fa10e5e99e28ed25103a046c02c7d
DIFF: https://github.com/llvm/llvm-project/commit/4c7dc9c1783fa10e5e99e28ed25103a046c02c7d.diff

LOG: Reland "[libc][math] Refactor fmaximum_mag_num family to header-only" (#194194)

Reland #182169

---------

Co-authored-by: Muhammad Bassiouni <60100307+bassiounix at users.noreply.github.com>

Added: 
    libc/shared/math/fmaximum_mag_num.h
    libc/shared/math/fmaximum_mag_numbf16.h
    libc/shared/math/fmaximum_mag_numf.h
    libc/src/__support/math/fmaximum_mag_num.h
    libc/src/__support/math/fmaximum_mag_numbf16.h
    libc/src/__support/math/fmaximum_mag_numf.h

Modified: 
    libc/shared/math.h
    libc/src/__support/FPUtil/BasicOperations.h
    libc/src/__support/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/src/math/generic/fmaximum_mag_num.cpp
    libc/src/math/generic/fmaximum_mag_numbf16.cpp
    libc/src/math/generic/fmaximum_mag_numf.cpp
    libc/test/shared/CMakeLists.txt
    libc/test/shared/shared_math_constexpr_test.cpp
    libc/test/shared/shared_math_test.cpp
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    


################################################################################
diff  --git a/libc/shared/math.h b/libc/shared/math.h
index 66b7af9b95ebc..80078afea59ba 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -175,6 +175,9 @@
 #include "math/fmaxf.h"
 #include "math/fmaxf128.h"
 #include "math/fmaxf16.h"
+#include "math/fmaximum_mag_num.h"
+#include "math/fmaximum_mag_numbf16.h"
+#include "math/fmaximum_mag_numf.h"
 #include "math/fmaxl.h"
 #include "math/frexpf.h"
 #include "math/frexpf128.h"

diff  --git a/libc/shared/math/fmaximum_mag_num.h b/libc/shared/math/fmaximum_mag_num.h
new file mode 100644
index 0000000000000..a644072cd4406
--- /dev/null
+++ b/libc/shared/math/fmaximum_mag_num.h
@@ -0,0 +1,23 @@
+//===-- Shared fmaximum_mag_num 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_FMAXIMUM_MAG_NUM_H
+#define LLVM_LIBC_SHARED_MATH_FMAXIMUM_MAG_NUM_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmaximum_mag_num.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmaximum_mag_num;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMAXIMUM_MAG_NUM_H

diff  --git a/libc/shared/math/fmaximum_mag_numbf16.h b/libc/shared/math/fmaximum_mag_numbf16.h
new file mode 100644
index 0000000000000..d6b4067e59451
--- /dev/null
+++ b/libc/shared/math/fmaximum_mag_numbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared fmaximum_mag_numbf16 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_FMAXIMUM_MAG_NUMBF16_H
+#define LLVM_LIBC_SHARED_MATH_FMAXIMUM_MAG_NUMBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmaximum_mag_numbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmaximum_mag_numbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMAXIMUM_MAG_NUMBF16_H

diff  --git a/libc/shared/math/fmaximum_mag_numf.h b/libc/shared/math/fmaximum_mag_numf.h
new file mode 100644
index 0000000000000..57236f4dcf1d9
--- /dev/null
+++ b/libc/shared/math/fmaximum_mag_numf.h
@@ -0,0 +1,23 @@
+//===-- Shared fmaximum_mag_numf 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_FMAXIMUM_MAG_NUMF_H
+#define LLVM_LIBC_SHARED_MATH_FMAXIMUM_MAG_NUMF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmaximum_mag_numf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmaximum_mag_numf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMAXIMUM_MAG_NUMF_H

diff  --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index 1253359c53bbb..3216740aa74f9 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -33,7 +33,8 @@ LIBC_INLINE constexpr T abs(T x) {
 namespace internal {
 
 template <typename T>
-LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, T> max(T x, T y) {
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T>
+constexpr_max(T x, T y) {
   FPBits<T> x_bits(x);
   FPBits<T> y_bits(y);
 
@@ -45,13 +46,21 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, T> max(T x, T y) {
   return x > y ? x : y;
 }
 
+template <typename T>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T>
+max(T x, T y) {
+  return constexpr_max(x, y);
+}
+
 #ifdef LIBC_TYPES_HAS_FLOAT16
 #if defined(__LIBC_USE_BUILTIN_FMAXF16_FMINF16)
-template <> LIBC_INLINE float16 max(float16 x, float16 y) {
+template <> LIBC_INLINE constexpr float16 max(float16 x, float16 y) {
+  if (cpp::is_constant_evaluated())
+    return constexpr_max(x, y);
   return __builtin_fmaxf16(x, y);
 }
 #elif !defined(LIBC_TARGET_ARCH_IS_AARCH64)
-template <> LIBC_INLINE float16 max(float16 x, float16 y) {
+template <> LIBC_INLINE constexpr float16 max(float16 x, float16 y) {
   FPBits<float16> x_bits(x);
   FPBits<float16> y_bits(y);
 
@@ -63,11 +72,15 @@ template <> LIBC_INLINE float16 max(float16 x, float16 y) {
 #endif // LIBC_TYPES_HAS_FLOAT16
 
 #if defined(__LIBC_USE_BUILTIN_FMAX_FMIN) && !defined(LIBC_TARGET_ARCH_IS_X86)
-template <> LIBC_INLINE float max(float x, float y) {
+template <> LIBC_INLINE constexpr float max(float x, float y) {
+  if (cpp::is_constant_evaluated())
+    return constexpr_max(x, y);
   return __builtin_fmaxf(x, y);
 }
 
-template <> LIBC_INLINE double max(double x, double y) {
+template <> LIBC_INLINE constexpr double max(double x, double y) {
+  if (cpp::is_constant_evaluated())
+    return constexpr_max(x, y);
   return __builtin_fmax(x, y);
 }
 #endif
@@ -159,7 +172,7 @@ LIBC_INLINE T fminimum(T x, T y) {
 }
 
 template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
-LIBC_INLINE T fmaximum_num(T x, T y) {
+LIBC_INLINE constexpr T fmaximum_num(T x, T y) {
   FPBits<T> bitx(x), bity(y);
   if (bitx.is_signaling_nan() || bity.is_signaling_nan()) {
     fputil::raise_except_if_required(FE_INVALID);
@@ -211,7 +224,7 @@ LIBC_INLINE T fminimum_mag(T x, T y) {
 }
 
 template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
-LIBC_INLINE T fmaximum_mag_num(T x, T y) {
+LIBC_INLINE constexpr T fmaximum_mag_num(T x, T y) {
   FPBits<T> bitx(x), bity(y);
 
   if (abs(x) > abs(y))

diff  --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index f72dd6772c8ca..67c3b28109987 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1674,6 +1674,36 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  fmaximum_mag_num
+  HDRS
+    fmaximum_mag_num.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fmaximum_mag_numbf16
+  HDRS
+    fmaximum_mag_numbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.macros.config
+  FLAGS
+    MISC_MATH_BASIC_OPS_OPT
+)
+
+add_header_library(
+  fmaximum_mag_numf
+  HDRS
+    fmaximum_mag_numf.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   fmabf16
   HDRS

diff  --git a/libc/src/__support/math/fmaximum_mag_num.h b/libc/src/__support/math/fmaximum_mag_num.h
new file mode 100644
index 0000000000000..bb54f5c8919d1
--- /dev/null
+++ b/libc/src/__support/math/fmaximum_mag_num.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmaximum_mag_num --------------*- 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_FMAXIMUM_MAG_NUM_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAXIMUM_MAG_NUM_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double fmaximum_mag_num(double x, double y) {
+  return fputil::fmaximum_mag_num(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAXIMUM_MAG_NUM_H

diff  --git a/libc/src/__support/math/fmaximum_mag_numbf16.h b/libc/src/__support/math/fmaximum_mag_numbf16.h
new file mode 100644
index 0000000000000..7010371015589
--- /dev/null
+++ b/libc/src/__support/math/fmaximum_mag_numbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for fmaximum_mag_numbf16 ----------*- 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_FMAXIMUM_MAG_NUMBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAXIMUM_MAG_NUMBF16_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 fmaximum_mag_numbf16(bfloat16 x, bfloat16 y) {
+  return fputil::fmaximum_mag_num(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAXIMUM_MAG_NUMBF16_H

diff  --git a/libc/src/__support/math/fmaximum_mag_numf.h b/libc/src/__support/math/fmaximum_mag_numf.h
new file mode 100644
index 0000000000000..c2298b85b4c77
--- /dev/null
+++ b/libc/src/__support/math/fmaximum_mag_numf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmaximum_mag_numf -------------*- 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_FMAXIMUM_MAG_NUMF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAXIMUM_MAG_NUMF_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float fmaximum_mag_numf(float x, float y) {
+  return fputil::fmaximum_mag_num(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAXIMUM_MAG_NUMF_H

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index eed816057b934..0b91d1d4404ab 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2423,7 +2423,7 @@ add_entrypoint_object(
   HDRS
     ../fmaximum_mag_num.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.fmaximum_mag_num
 )
 
 add_entrypoint_object(
@@ -2433,7 +2433,7 @@ add_entrypoint_object(
   HDRS
     ../fmaximum_mag_numf.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.fmaximum_mag_numf
 )
 
 add_entrypoint_object(
@@ -2475,12 +2475,7 @@ add_entrypoint_object(
   HDRS
     ../fmaximum_mag_numbf16.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
-    libc.src.__support.FPUtil.bfloat16
-    libc.src.__support.macros.config
-    libc.src.__support.macros.properties.types
-  FLAGS
-    MISC_MATH_BASIC_OPS_OPT
+    libc.src.__support.math.fmaximum_mag_numbf16
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/math/generic/fmaximum_mag_num.cpp b/libc/src/math/generic/fmaximum_mag_num.cpp
index de250bbd32b7b..40c8f6e3755d0 100644
--- a/libc/src/math/generic/fmaximum_mag_num.cpp
+++ b/libc/src/math/generic/fmaximum_mag_num.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmaximum_mag_num.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmaximum_mag_num.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, fmaximum_mag_num, (double x, double y)) {
-  return fputil::fmaximum_mag_num(x, y);
+  return math::fmaximum_mag_num(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/fmaximum_mag_numbf16.cpp b/libc/src/math/generic/fmaximum_mag_numbf16.cpp
index 485e32959b53a..a54725b7f1eee 100644
--- a/libc/src/math/generic/fmaximum_mag_numbf16.cpp
+++ b/libc/src/math/generic/fmaximum_mag_numbf16.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmaximum_mag_numbf16.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/fmaximum_mag_numbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(bfloat16, fmaximum_mag_numbf16, (bfloat16 x, bfloat16 y)) {
-  return fputil::fmaximum_mag_num(x, y);
+  return math::fmaximum_mag_numbf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/fmaximum_mag_numf.cpp b/libc/src/math/generic/fmaximum_mag_numf.cpp
index e372f1bd1f9d3..97039ef845aec 100644
--- a/libc/src/math/generic/fmaximum_mag_numf.cpp
+++ b/libc/src/math/generic/fmaximum_mag_numf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmaximum_mag_numf.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmaximum_mag_numf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, fmaximum_mag_numf, (float x, float y)) {
-  return fputil::fmaximum_mag_num(x, y);
+  return math::fmaximum_mag_numf(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 8948186ec1775..8f324ae814f71 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -172,6 +172,9 @@ add_fp_unittest(
     libc.src.__support.math.fmaxf
     libc.src.__support.math.fmaxf128
     libc.src.__support.math.fmaxf16
+    libc.src.__support.math.fmaximum_mag_num
+    libc.src.__support.math.fmaximum_mag_numbf16
+    libc.src.__support.math.fmaximum_mag_numf
     libc.src.__support.math.fmaxl
     libc.src.__support.math.frexpf
     libc.src.__support.math.frexpf128
@@ -330,6 +333,9 @@ add_fp_unittest(
     libc.src.__support.math.fabsf128
     libc.src.__support.math.fabsf16
     libc.src.__support.math.fabsl
+    libc.src.__support.math.fmaximum_mag_num
+    libc.src.__support.math.fmaximum_mag_numbf16
+    libc.src.__support.math.fmaximum_mag_numf
     libc.src.__support.math.log
     libc.src.__support.math.logbbf16
 )

diff  --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index e3bfc65bd5211..2e995474e19be 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -21,6 +21,7 @@ static_assert(1.0 == LIBC_NAMESPACE::shared::fabs(-1.0));
 static_assert(1.0 == LIBC_NAMESPACE::shared::fdim(1.0, 0.0));
 static_assert(0.0f == LIBC_NAMESPACE::shared::fdiv(0.0, 1.0));
 static_assert(1.0 == LIBC_NAMESPACE::shared::floor(1.2));
+static_assert(2.0 == LIBC_NAMESPACE::shared::fmaximum_mag_num(1.0, 2.0));
 static_assert(0.0 == LIBC_NAMESPACE::shared::log(1.0));
 
 //===----------------------------------------------------------------------===//
@@ -31,6 +32,7 @@ static_assert(0.0f == LIBC_NAMESPACE::shared::ceilf(0.0f));
 static_assert(0.0f == LIBC_NAMESPACE::shared::copysignf(0.0f, 0.0f));
 static_assert(1.0f == LIBC_NAMESPACE::shared::fabsf(-1.0f));
 static_assert(1.0f == LIBC_NAMESPACE::shared::fdimf(1.0f, 0.0f));
+static_assert(2.0f == LIBC_NAMESPACE::shared::fmaximum_mag_numf(1.0f, 2.0f));
 static_assert(0.0f == LIBC_NAMESPACE::shared::floorf(0.0f));
 
 //===----------------------------------------------------------------------===//
@@ -98,6 +100,9 @@ static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::asinbf16(bfloat16(0.0)));
 static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::ceilbf16(bfloat16(0.0)));
 static_assert(bfloat16(1.0) ==
               LIBC_NAMESPACE::shared::fabsbf16(bfloat16(-1.0)));
+static_assert(bfloat16(2.0) ==
+              LIBC_NAMESPACE::shared::fmaximum_mag_numbf16(bfloat16(1.0),
+                                                           bfloat16(2.0)));
 static_assert(bfloat16(0.0) ==
               LIBC_NAMESPACE::shared::copysignbf16(bfloat16(0.0),
                                                    bfloat16(0.0)));

diff  --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index d31436267f75b..d9d5c2c621d4a 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -182,6 +182,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::shared::fdimf(0.0f, 0.0f));
   EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::shared::floorf(0.0f));
   EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::shared::fmaxf(0.0f, 0.0f));
+  EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::shared::fmaximum_mag_numf(0.0f, 0.0f));
+
   float getpayloadf_x = 0.0f;
   EXPECT_FP_EQ(-1.0f, LIBC_NAMESPACE::shared::getpayloadf(&getpayloadf_x));
 
@@ -267,6 +269,8 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
   EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::shared::fdiv(1.0, 1.0));
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::floor(0.0));
   EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmax(0.0, 0.0));
+  EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmaximum_mag_num(0.0, 0.0));
+
   double getpayload_x = 0.0;
   EXPECT_FP_EQ(-1.0, LIBC_NAMESPACE::shared::getpayload(&getpayload_x));
 
@@ -496,6 +500,9 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
   EXPECT_FP_EQ(bfloat16(0.0),
                LIBC_NAMESPACE::shared::fmaxbf16(bfloat16(0.0), bfloat16(0.0)));
 
+  EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::shared::fmaximum_mag_numbf16(
+                         bfloat16(0.0), bfloat16(0.0)));
+
   bfloat16 getpayloadbf16_x = bfloat16(0.0);
   EXPECT_FP_EQ(bfloat16(-1.0),
                LIBC_NAMESPACE::shared::getpayloadbf16(&getpayloadbf16_x));

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index b2355202d19ce..1be54084b85bc 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4822,6 +4822,34 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_fmaximum_mag_num",
+    hdrs = ["src/__support/math/fmaximum_mag_num.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmaximum_mag_numbf16",
+    hdrs = ["src/__support/math/fmaximum_mag_numbf16.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_fputil_bfloat16",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmaximum_mag_numf",
+    hdrs = ["src/__support/math/fmaximum_mag_numf.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_ffmal",
     hdrs = ["src/__support/math/ffmal.h"],
@@ -7925,9 +7953,26 @@ libc_math_function(
     name = "fmaximum_magf16",
 )
 
-libc_math_function(name = "fmaximum_mag_num")
+libc_math_function(
+    name = "fmaximum_mag_num",
+    additional_deps = [
+        ":__support_math_fmaximum_mag_num",
+    ],
+)
 
-libc_math_function(name = "fmaximum_mag_numf")
+libc_math_function(
+    name = "fmaximum_mag_numbf16",
+    additional_deps = [
+        ":__support_math_fmaximum_mag_numbf16",
+    ],
+)
+
+libc_math_function(
+    name = "fmaximum_mag_numf",
+    additional_deps = [
+        ":__support_math_fmaximum_mag_numf",
+    ],
+)
 
 libc_math_function(name = "fmaximum_mag_numl")
 


        


More information about the libc-commits mailing list