[libc-commits] [libc] [llvm] [libc][math] Refactor fmax family to header-only (PR #182165)

Mohamed Emad via libc-commits libc-commits at lists.llvm.org
Thu Feb 19 14:04:55 PST 2026


https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/182165

>From acee84ab6695b0fa9955f69b1f0c5cf9967b4f29 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 19 Feb 2026 00:36:12 +0200
Subject: [PATCH] [libc][math] Refactor fmax family to header-only

Refactored functions:
  - fmax
  - fmaxbf16
  - fmaxf
  - fmaxf128
  - fmaxf16
  - fmaxl
---
 libc/shared/math.h                            |  6 ++
 libc/shared/math/fmax.h                       | 22 +++++
 libc/shared/math/fmaxbf16.h                   | 22 +++++
 libc/shared/math/fmaxf.h                      | 22 +++++
 libc/shared/math/fmaxf128.h                   | 28 ++++++
 libc/shared/math/fmaxf16.h                    | 28 ++++++
 libc/shared/math/fmaxl.h                      | 22 +++++
 libc/src/__support/math/CMakeLists.txt        | 65 ++++++++++++
 libc/src/__support/math/fmax.h                | 23 +++++
 libc/src/__support/math/fmaxbf16.h            | 26 +++++
 libc/src/__support/math/fmaxf.h               | 23 +++++
 libc/src/__support/math/fmaxf128.h            | 31 ++++++
 libc/src/__support/math/fmaxf16.h             | 29 ++++++
 libc/src/__support/math/fmaxl.h               | 25 +++++
 libc/src/math/generic/CMakeLists.txt          | 26 ++---
 libc/src/math/generic/fmax.cpp                |  6 +-
 libc/src/math/generic/fmaxbf16.cpp            |  7 +-
 libc/src/math/generic/fmaxf.cpp               |  6 +-
 libc/src/math/generic/fmaxf128.cpp            |  6 +-
 libc/src/math/generic/fmaxf16.cpp             |  6 +-
 libc/src/math/generic/fmaxl.cpp               |  6 +-
 libc/test/shared/CMakeLists.txt               |  6 ++
 libc/test/shared/shared_math_test.cpp         | 14 +++
 .../llvm-project-overlay/libc/BUILD.bazel     | 99 +++++++++++++++++--
 24 files changed, 502 insertions(+), 52 deletions(-)
 create mode 100644 libc/shared/math/fmax.h
 create mode 100644 libc/shared/math/fmaxbf16.h
 create mode 100644 libc/shared/math/fmaxf.h
 create mode 100644 libc/shared/math/fmaxf128.h
 create mode 100644 libc/shared/math/fmaxf16.h
 create mode 100644 libc/shared/math/fmaxl.h
 create mode 100644 libc/src/__support/math/fmax.h
 create mode 100644 libc/src/__support/math/fmaxbf16.h
 create mode 100644 libc/src/__support/math/fmaxf.h
 create mode 100644 libc/src/__support/math/fmaxf128.h
 create mode 100644 libc/src/__support/math/fmaxf16.h
 create mode 100644 libc/src/__support/math/fmaxl.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 8a5aca82c6ec3..c4e034483b8a0 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -85,6 +85,12 @@
 #include "math/f16sqrtl.h"
 #include "math/ffma.h"
 #include "math/ffmal.h"
+#include "math/fmax.h"
+#include "math/fmaxbf16.h"
+#include "math/fmaxf.h"
+#include "math/fmaxf128.h"
+#include "math/fmaxf16.h"
+#include "math/fmaxl.h"
 #include "math/frexpf.h"
 #include "math/frexpf128.h"
 #include "math/frexpf16.h"
diff --git a/libc/shared/math/fmax.h b/libc/shared/math/fmax.h
new file mode 100644
index 0000000000000..ac04ff3b51ac0
--- /dev/null
+++ b/libc/shared/math/fmax.h
@@ -0,0 +1,22 @@
+//===-- Shared fmax 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_FMAX_H
+#define LLVM_LIBC_SHARED_MATH_FMAX_H
+
+#include "src/__support/math/fmax.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmax;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMAX_H
diff --git a/libc/shared/math/fmaxbf16.h b/libc/shared/math/fmaxbf16.h
new file mode 100644
index 0000000000000..27c5bc78c47e6
--- /dev/null
+++ b/libc/shared/math/fmaxbf16.h
@@ -0,0 +1,22 @@
+//===-- Shared fmaxbf16 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_FMAXBF16_H
+#define LLVM_LIBC_SHARED_MATH_FMAXBF16_H
+
+#include "src/__support/math/fmaxbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmaxbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMAXBF16_H
diff --git a/libc/shared/math/fmaxf.h b/libc/shared/math/fmaxf.h
new file mode 100644
index 0000000000000..eb65fe33508f0
--- /dev/null
+++ b/libc/shared/math/fmaxf.h
@@ -0,0 +1,22 @@
+//===-- Shared fmaxf 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_FMAXF_H
+#define LLVM_LIBC_SHARED_MATH_FMAXF_H
+
+#include "src/__support/math/fmaxf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmaxf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMAXF_H
diff --git a/libc/shared/math/fmaxf128.h b/libc/shared/math/fmaxf128.h
new file mode 100644
index 0000000000000..6b4cb53f5af3c
--- /dev/null
+++ b/libc/shared/math/fmaxf128.h
@@ -0,0 +1,28 @@
+//===-- Shared fmaxf128 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_FMAXF128_H
+#define LLVM_LIBC_SHARED_MATH_FMAXF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/fmaxf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmaxf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FMAXF128_H
diff --git a/libc/shared/math/fmaxf16.h b/libc/shared/math/fmaxf16.h
new file mode 100644
index 0000000000000..386779bacad68
--- /dev/null
+++ b/libc/shared/math/fmaxf16.h
@@ -0,0 +1,28 @@
+//===-- Shared fmaxf16 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_FMAXF16_H
+#define LLVM_LIBC_SHARED_MATH_FMAXF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/fmaxf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmaxf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_FMAXF16_H
diff --git a/libc/shared/math/fmaxl.h b/libc/shared/math/fmaxl.h
new file mode 100644
index 0000000000000..48704161d765c
--- /dev/null
+++ b/libc/shared/math/fmaxl.h
@@ -0,0 +1,22 @@
+//===-- Shared fmaxl 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_FMAXL_H
+#define LLVM_LIBC_SHARED_MATH_FMAXL_H
+
+#include "src/__support/math/fmaxl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmaxl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMAXL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e21fe8ef0ab93..bf2a569cbbd02 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -801,6 +801,71 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  fmax
+  HDRS
+    fmax.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+  FLAGS
+    MISC_MATH_BASIC_OPS_OPT
+)
+
+add_header_library(
+  fmaxbf16
+  HDRS
+    fmaxbf16.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(
+  fmaxf
+  HDRS
+    fmaxf.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+  FLAGS
+    MISC_MATH_BASIC_OPS_OPT
+)
+
+add_header_library(
+  fmaxf128
+  HDRS
+    fmaxf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  fmaxf16
+  HDRS
+    fmaxf16.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+  FLAGS
+    MISC_MATH_BASIC_OPS_OPT
+)
+
+add_header_library(
+  fmaxl
+  HDRS
+    fmaxl.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   frexpf128
   HDRS
diff --git a/libc/src/__support/math/fmax.h b/libc/src/__support/math/fmax.h
new file mode 100644
index 0000000000000..c7b0b86b3dbc3
--- /dev/null
+++ b/libc/src/__support/math/fmax.h
@@ -0,0 +1,23 @@
+//===-- Implementation header for fmax --------------------------*- 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_FMAX_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAX_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE double fmax(double x, double y) { return fputil::fmax(x, y); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAX_H
diff --git a/libc/src/__support/math/fmaxbf16.h b/libc/src/__support/math/fmaxbf16.h
new file mode 100644
index 0000000000000..4dd41c59a1b7e
--- /dev/null
+++ b/libc/src/__support/math/fmaxbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for fmaxbf16 ----------------------*- 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_FMAXBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAXBF16_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 bfloat16 fmaxbf16(bfloat16 x, bfloat16 y) {
+  return fputil::fmax(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAXBF16_H
diff --git a/libc/src/__support/math/fmaxf.h b/libc/src/__support/math/fmaxf.h
new file mode 100644
index 0000000000000..7137b89e392d5
--- /dev/null
+++ b/libc/src/__support/math/fmaxf.h
@@ -0,0 +1,23 @@
+//===-- Implementation header for fmaxf -------------------------*- 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_FMAXF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAXF_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE float fmaxf(float x, float y) { return fputil::fmax(x, y); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAXF_H
diff --git a/libc/src/__support/math/fmaxf128.h b/libc/src/__support/math/fmaxf128.h
new file mode 100644
index 0000000000000..ab57a0780bb65
--- /dev/null
+++ b/libc/src/__support/math/fmaxf128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for fmaxf128 ----------------------*- 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_FMAXF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAXF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE float128 fmaxf128(float128 x, float128 y) {
+  return fputil::fmax(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAXF128_H
diff --git a/libc/src/__support/math/fmaxf16.h b/libc/src/__support/math/fmaxf16.h
new file mode 100644
index 0000000000000..0a2e2ff066347
--- /dev/null
+++ b/libc/src/__support/math/fmaxf16.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for fmaxf16 -----------------------*- 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_FMAXF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAXF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE float16 fmaxf16(float16 x, float16 y) { return fputil::fmax(x, y); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAXF16_H
diff --git a/libc/src/__support/math/fmaxl.h b/libc/src/__support/math/fmaxl.h
new file mode 100644
index 0000000000000..307f5c59b25d7
--- /dev/null
+++ b/libc/src/__support/math/fmaxl.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmaxl -------------------------*- 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_FMAXL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAXL_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE long double fmaxl(long double x, long double y) {
+  return fputil::fmax(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAXL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 57a29665318a3..20ececb14c889 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2185,9 +2185,7 @@ add_entrypoint_object(
   HDRS
     ../fmax.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
-  FLAGS
-    MISC_MATH_BASIC_OPS_OPT
+    libc.src.__support.math.fmax
 )
 
 add_entrypoint_object(
@@ -2197,9 +2195,7 @@ add_entrypoint_object(
   HDRS
     ../fmaxf.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
-  FLAGS
-    MISC_MATH_BASIC_OPS_OPT
+    libc.src.__support.math.fmaxf
 )
 
 add_entrypoint_object(
@@ -2209,7 +2205,7 @@ add_entrypoint_object(
   HDRS
     ../fmaxl.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.fmaxl
 )
 
 add_entrypoint_object(
@@ -2219,8 +2215,7 @@ add_entrypoint_object(
   HDRS
     ../fmaxf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.fmaxf128
 )
 
 add_entrypoint_object(
@@ -2230,10 +2225,7 @@ add_entrypoint_object(
   HDRS
     ../fmaxf16.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.basic_operations
-  FLAGS
-    MISC_MATH_BASIC_OPS_OPT
+    libc.src.__support.math.fmaxf16
 )
 
 add_entrypoint_object(
@@ -2243,13 +2235,7 @@ add_entrypoint_object(
   HDRS
     ../fmaxbf16.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
-  FLAGS
-    MISC_MATH_BASIC_OPS_OPT
+    libc.src.__support.math.fmaxbf16
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/fmax.cpp b/libc/src/math/generic/fmax.cpp
index b9ac4a0d8efaf..8ae7f24448365 100644
--- a/libc/src/math/generic/fmax.cpp
+++ b/libc/src/math/generic/fmax.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmax.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmax.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(double, fmax, (double x, double y)) {
-  return fputil::fmax(x, y);
+  return math::fmax(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmaxbf16.cpp b/libc/src/math/generic/fmaxbf16.cpp
index 01d395bc04fa6..f152010ef4d61 100644
--- a/libc/src/math/generic/fmaxbf16.cpp
+++ b/libc/src/math/generic/fmaxbf16.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmaxbf16.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/fmaxbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(bfloat16, fmaxbf16, (bfloat16 x, bfloat16 y)) {
-  return fputil::fmax(x, y);
+  return math::fmaxbf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmaxf.cpp b/libc/src/math/generic/fmaxf.cpp
index 1c422de371f23..7c2816819ffcf 100644
--- a/libc/src/math/generic/fmaxf.cpp
+++ b/libc/src/math/generic/fmaxf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmaxf.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmaxf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float, fmaxf, (float x, float y)) {
-  return fputil::fmax(x, y);
+  return math::fmaxf(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmaxf128.cpp b/libc/src/math/generic/fmaxf128.cpp
index 08a9c8fe88aef..c724a8815d8ce 100644
--- a/libc/src/math/generic/fmaxf128.cpp
+++ b/libc/src/math/generic/fmaxf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmaxf128.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmaxf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, fmaxf128, (float128 x, float128 y)) {
-  return fputil::fmax(x, y);
+  return math::fmaxf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmaxf16.cpp b/libc/src/math/generic/fmaxf16.cpp
index 02c2bd80149fd..c0a95d54ed824 100644
--- a/libc/src/math/generic/fmaxf16.cpp
+++ b/libc/src/math/generic/fmaxf16.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmaxf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmaxf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, fmaxf16, (float16 x, float16 y)) {
-  return fputil::fmax(x, y);
+  return math::fmaxf16(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmaxl.cpp b/libc/src/math/generic/fmaxl.cpp
index a5460f559eeba..46335f9c0dbcd 100644
--- a/libc/src/math/generic/fmaxl.cpp
+++ b/libc/src/math/generic/fmaxl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/fmaxl.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmaxl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(long double, fmaxl, (long double x, long double y)) {
-  return fputil::fmax(x, y);
+  return math::fmaxl(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 53ad309af4f30..48ee92100a0ee 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -81,6 +81,12 @@ add_fp_unittest(
     libc.src.__support.math.f16sqrtl
     libc.src.__support.math.ffma
     libc.src.__support.math.ffmal
+    libc.src.__support.math.fmax
+    libc.src.__support.math.fmaxbf16
+    libc.src.__support.math.fmaxf
+    libc.src.__support.math.fmaxf128
+    libc.src.__support.math.fmaxf16
+    libc.src.__support.math.fmaxl
     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..7ff87fea60b04 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -88,6 +88,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef16(&canonicalizef16_cx,
                                                        &canonicalizef16_x));
   EXPECT_FP_EQ(0x0p+0f16, canonicalizef16_cx);
+
+  EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::fmaxf16(0.0f16, 0.0f16));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
@@ -150,6 +152,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef(&canonicalizef_cx,
                                                      &canonicalizef_x));
   EXPECT_FP_EQ(0x0p+0f, canonicalizef_cx);
+
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fmaxf(0.0f, 0.0f));
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -187,6 +191,8 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalize(&canonicalize_cx,
                                                     &canonicalize_x));
   EXPECT_FP_EQ(0.0, canonicalize_cx);
+
+  EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmax(0.0, 0.0));
 }
 
 TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -203,6 +209,8 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizel(&canonicalizel_cx,
                                                      &canonicalizel_x));
   EXPECT_FP_EQ(0x0p+0L, canonicalizel_cx);
+
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fmaxl(0.0L, 0.0L));
 }
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
@@ -238,6 +246,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef128(&canonicalizef128_cx,
                                                         &canonicalizef128_x));
   EXPECT_FP_EQ(float128(0.0), canonicalizef128_cx);
+
+  EXPECT_FP_EQ(float128(0.0),
+               LIBC_NAMESPACE::shared::fmaxf128(float128(0.0), float128(0.0)));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
@@ -257,4 +268,7 @@ 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(0.0),
+               LIBC_NAMESPACE::shared::fmaxbf16(bfloat16(0.0), bfloat16(0.0)));
 }
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index b90688af7a1d2..ec39261ccd988 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3106,12 +3106,65 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_fmax",
+    hdrs = ["src/__support/math/fmax.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmaxbf16",
+    hdrs = ["src/__support/math/fmaxbf16.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmaxf",
+    hdrs = ["src/__support/math/fmaxf.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmaxf128",
+    hdrs = ["src/__support/math/fmaxf128.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmaxf16",
+    hdrs = ["src/__support/math/fmaxf16.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_fmaxl",
+    hdrs = ["src/__support/math/fmaxl.h"],
+    deps = [
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_ffmal",
     hdrs = ["src/__support/math/ffmal.h"],
     deps = [
-        ":__support_common",
-        ":__support_fputil_fma",
         ":__support_macros_config",
     ],
 )
@@ -5033,15 +5086,47 @@ libc_math_function(
     additional_deps = [":__support_fputil_fma"],
 )
 
-libc_math_function(name = "fmax")
+libc_math_function(
+    name = "fmax",
+    additional_deps = [
+        ":__support_math_fmax",
+    ],
+)
 
-libc_math_function(name = "fmaxf")
+libc_math_function(
+    name = "fmaxf",
+    additional_deps = [
+        ":__support_math_fmaxf",
+    ],
+)
 
-libc_math_function(name = "fmaxl")
+libc_math_function(
+    name = "fmaxbf16",
+    additional_deps = [
+        ":__support_math_fmaxbf16",
+    ],
+)
 
-libc_math_function(name = "fmaxf128")
+libc_math_function(
+    name = "fmaxf128",
+    additional_deps = [
+        ":__support_math_fmaxf128",
+    ],
+)
 
-libc_math_function(name = "fmaxf16")
+libc_math_function(
+    name = "fmaxf16",
+    additional_deps = [
+        ":__support_math_fmaxf16",
+    ],
+)
+
+libc_math_function(
+    name = "fmaxl",
+    additional_deps = [
+        ":__support_math_fmaxl",
+    ],
+)
 
 libc_math_function(name = "fmaximum")
 



More information about the libc-commits mailing list