[libc-commits] [libc] ee81694 - [libc][math] Refactor f16fmaf to Header Only. (#178851)

via libc-commits libc-commits at lists.llvm.org
Thu Feb 5 11:56:32 PST 2026


Author: Zorojuro
Date: 2026-02-05T21:56:27+02:00
New Revision: ee816947ac4fc449b3b382b40f21f9f8c24b126b

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

LOG: [libc][math] Refactor f16fmaf to Header Only. (#178851)

closes #175319

Added: 
    libc/shared/math/f16fmaf.h
    libc/src/__support/math/f16fmaf.h

Modified: 
    libc/shared/math.h
    libc/src/__support/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/src/math/generic/f16fmaf.cpp
    libc/test/shared/CMakeLists.txt
    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 32b4bdf599f2a..110b4bfe81073 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -60,6 +60,7 @@
 #include "math/expm1f.h"
 #include "math/expm1f16.h"
 #include "math/f16fma.h"
+#include "math/f16fmaf.h"
 #include "math/f16fmaf128.h"
 #include "math/f16fmal.h"
 #include "math/f16sqrt.h"

diff  --git a/libc/shared/math/f16fmaf.h b/libc/shared/math/f16fmaf.h
new file mode 100644
index 0000000000000..bafbb4b4803b6
--- /dev/null
+++ b/libc/shared/math/f16fmaf.h
@@ -0,0 +1,31 @@
+//===-- Shared f16fmaf 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_F16FMAF_H
+#define LLVM_LIBC_SHARED_MATH_F16FMAF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "shared/libc_common.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16fmaf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace shared {
+
+using math::f16fmaf;
+
+} // namespace shared
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16FMAF_H

diff  --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index a520ede69419a..3d43eccfdbe2c 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -675,6 +675,16 @@ add_header_library(
     libc.include.llvm-libc-macros.float16_macros
 )
 
+add_header_library(
+  f16fmaf
+  HDRS
+    f16fmaf.h
+  DEPENDS
+    libc.src.__support.macros.config
+    libc.src.__support.FPUtil.fma
+    libc.include.llvm-libc-macros.float16_macros
+)
+
 add_header_library(
   f16fmaf128
   HDRS

diff  --git a/libc/src/__support/math/f16fmaf.h b/libc/src/__support/math/f16fmaf.h
new file mode 100644
index 0000000000000..92f94a9721e7d
--- /dev/null
+++ b/libc/src/__support/math/f16fmaf.h
@@ -0,0 +1,33 @@
+//===-- Implementation header for f16fmaf -----------------------*- 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_F16FMAF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16FMAF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16fmaf(float x, float y, float z) {
+  return fputil::fma<float16>(x, y, z);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16FMAF_H

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 97ab64e79055f..be3f724e10a8b 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -5038,8 +5038,7 @@ add_entrypoint_object(
   HDRS
     ../f16fmaf.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.fma
+    libc.src.__support.math.f16fmaf
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/math/generic/f16fmaf.cpp b/libc/src/math/generic/f16fmaf.cpp
index bd0b56b1ab31b..1c2c6d80934c8 100644
--- a/libc/src/math/generic/f16fmaf.cpp
+++ b/libc/src/math/generic/f16fmaf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16fmaf.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16fmaf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16fmaf, (float x, float y, float z)) {
-  return fputil::fma<float16>(x, y, z);
+  return math::f16fmaf(x, y, z);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 77bdca8ad8aec..7143ce6e84458 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -56,6 +56,7 @@ add_fp_unittest(
     libc.src.__support.math.expf
     libc.src.__support.math.expf16
     libc.src.__support.math.f16fma
+    libc.src.__support.math.f16fmaf
     libc.src.__support.math.f16fmaf128
     libc.src.__support.math.f16fmal
     libc.src.__support.math.f16sqrt

diff  --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index c00076deee8be..73d6d836227b3 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -38,6 +38,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
 
   EXPECT_FP_EQ(float16(10.0), LIBC_NAMESPACE::shared::f16fma(2.0, 3.0, 4.0));
 
+  EXPECT_FP_EQ(float16(10.0),
+               LIBC_NAMESPACE::shared::f16fmaf(2.0f, 3.0f, 4.0f));
+
 #ifdef LIBC_TYPES_HAS_FLOAT128
 
   EXPECT_FP_EQ(10.0f16, LIBC_NAMESPACE::shared::f16fmaf128(

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 14dda9fdaf704..b91a13b29d3c6 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2910,6 +2910,17 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_f16fmaf",
+    hdrs = ["src/__support/math/f16fmaf.h"],
+    deps = [
+        ":__support_common",
+        ":__support_fputil_fma",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_f16fmaf128",
     hdrs = ["src/__support/math/f16fmaf128.h"],
@@ -4452,7 +4463,7 @@ libc_math_function(
 libc_math_function(
     name = "f16fmaf",
     additional_deps = [
-        ":__support_fputil_fma",
+        ":__support_math_f16fmaf",
     ],
 )
 


        


More information about the libc-commits mailing list