[libc][math] Refactor fmaximum_mag_num family to header-only#182169
[libc][math] Refactor fmaximum_mag_num family to header-only#182169
Conversation
|
@llvm/pr-subscribers-libc Author: Mohamed Emad (hulxv) ChangesRefactors the fmaximum_mag_num math family to be header-only. Closes #182168 Target Functions:
Full diff: https://github.com/llvm/llvm-project/pull/182169.diff 15 Files Affected:
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 8a5aca82c6ec3..c731ad456f4e2 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -85,6 +85,9 @@
#include "math/f16sqrtl.h"
#include "math/ffma.h"
#include "math/ffmal.h"
+#include "math/fmaximum_mag_num.h"
+#include "math/fmaximum_mag_numbf16.h"
+#include "math/fmaximum_mag_numf.h"
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.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..f356682277b73
--- /dev/null
+++ b/libc/shared/math/fmaximum_mag_num.h
@@ -0,0 +1,22 @@
+//===-- 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 "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..c650bd2902ac6
--- /dev/null
+++ b/libc/shared/math/fmaximum_mag_numbf16.h
@@ -0,0 +1,22 @@
+//===-- 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 "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..862136f7db490
--- /dev/null
+++ b/libc/shared/math/fmaximum_mag_numf.h
@@ -0,0 +1,22 @@
+//===-- 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 "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/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e21fe8ef0ab93..7149e2e85c8c6 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -800,6 +800,31 @@ add_header_library(
libc.src.__support.FPUtil.fma
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
+)
+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(
frexpf128
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..b69effd9dfbd7
--- /dev/null
+++ b/libc/src/__support/math/fmaximum_mag_num.h
@@ -0,0 +1,26 @@
+//===-- 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 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..aa87054f44c90
--- /dev/null
+++ b/libc/src/__support/math/fmaximum_mag_numbf16.h
@@ -0,0 +1,27 @@
+//===-- 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 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..155b220049fd3
--- /dev/null
+++ b/libc/src/__support/math/fmaximum_mag_numf.h
@@ -0,0 +1,26 @@
+//===-- 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 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 57a29665318a3..3b3146506657a 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2472,7 +2472,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(
@@ -2482,7 +2482,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(
@@ -2524,12 +2524,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 53ad309af4f30..fa132d6f42faf 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -81,6 +81,9 @@ add_fp_unittest(
libc.src.__support.math.f16sqrtl
libc.src.__support.math.ffma
libc.src.__support.math.ffmal
+ 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.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..689d38e1386c4 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -150,6 +150,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::fmaximum_mag_numf(0.0f, 0.0f));
}
TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -187,6 +189,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::fmaximum_mag_num(0.0, 0.0));
}
TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -257,4 +261,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(0.0f, LIBC_NAMESPACE::shared::fmaximum_mag_numbf16(
+ 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..e4977c43c7fab 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3106,6 +3106,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"],
@@ -5063,9 +5091,19 @@ libc_math_function(name = "fmaximum_magf128")
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_numf",
+ additional_deps = [
+ ":__support_math_fmaximum_mag_numf",
+ ],
+)
libc_math_function(name = "fmaximum_mag_numl")
|
8ef1cd0 to
490f832
Compare
Refactored functions: - fmaximum_mag_num - fmaximum_mag_numbf16 - fmaximum_mag_numf
490f832 to
53d35b6
Compare
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions cpp,h -- 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 libc/shared/math.h 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/shared_math_test.cpp --diff_from_common_commit
View the diff from clang-format here.diff --git a/libc/shared/math.h b/libc/shared/math.h
index 551bd2a8c..8b003c01d 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -131,14 +131,14 @@
#include "math/floorf128.h"
#include "math/floorf16.h"
#include "math/floorl.h"
-#include "math/fmaximum_mag_num.h"
-#include "math/fmaximum_mag_numbf16.h"
-#include "math/fmaximum_mag_numf.h"
#include "math/fmax.h"
#include "math/fmaxbf16.h"
#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"
|
73081e9 to
9316481
Compare
| FLAGS | ||
| MISC_MATH_BASIC_OPS_OPT |
There was a problem hiding this comment.
move the flag to __support as well
There was a problem hiding this comment.
The flag exists on one target only, not all of them.
| FLAGS | ||
| MISC_MATH_BASIC_OPS_OPT |
There was a problem hiding this comment.
The flag exists on one target only, not all of them.
Refactors the fmaximum_mag_num math family to be header-only.
Closes #182168
Target Functions: