[libc-commits] [libc] e6fdcf3 - [libc][math] Refactor canonicalize function family to header-only (#181467)
via libc-commits
libc-commits at lists.llvm.org
Mon Feb 16 01:28:18 PST 2026
Author: Anonmiraj
Date: 2026-02-16T11:28:14+02:00
New Revision: e6fdcf32894801af6c7cbfd0376f822635c8e6d2
URL: https://github.com/llvm/llvm-project/commit/e6fdcf32894801af6c7cbfd0376f822635c8e6d2
DIFF: https://github.com/llvm/llvm-project/commit/e6fdcf32894801af6c7cbfd0376f822635c8e6d2.diff
LOG: [libc][math] Refactor canonicalize function family to header-only (#181467)
closes: #181466
Added:
libc/shared/math/canonicalize.h
libc/shared/math/canonicalizebf16.h
libc/shared/math/canonicalizef.h
libc/shared/math/canonicalizef128.h
libc/shared/math/canonicalizef16.h
libc/shared/math/canonicalizel.h
libc/src/__support/math/canonicalize.h
libc/src/__support/math/canonicalizebf16.h
libc/src/__support/math/canonicalizef.h
libc/src/__support/math/canonicalizef128.h
libc/src/__support/math/canonicalizef16.h
libc/src/__support/math/canonicalizel.h
Modified:
libc/shared/math.h
libc/src/__support/math/CMakeLists.txt
libc/src/math/generic/CMakeLists.txt
libc/src/math/generic/canonicalize.cpp
libc/src/math/generic/canonicalizebf16.cpp
libc/src/math/generic/canonicalizef.cpp
libc/src/math/generic/canonicalizef128.cpp
libc/src/math/generic/canonicalizef16.cpp
libc/src/math/generic/canonicalizel.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 e4487d7305e4b..e185c567c45fe 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -32,6 +32,12 @@
#include "math/atanhf16.h"
#include "math/bf16add.h"
#include "math/bf16addf128.h"
+#include "math/canonicalize.h"
+#include "math/canonicalizebf16.h"
+#include "math/canonicalizef.h"
+#include "math/canonicalizef128.h"
+#include "math/canonicalizef16.h"
+#include "math/canonicalizel.h"
#include "math/cbrt.h"
#include "math/cbrtf.h"
#include "math/cos.h"
diff --git a/libc/shared/math/canonicalize.h b/libc/shared/math/canonicalize.h
new file mode 100644
index 0000000000000..5e21641de2f40
--- /dev/null
+++ b/libc/shared/math/canonicalize.h
@@ -0,0 +1,23 @@
+//===-- Shared canonicalize 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_CANONICALIZE_H
+#define LLVM_LIBC_SHARED_MATH_CANONICALIZE_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/canonicalize.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::canonicalize;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_CANONICALIZE_H
diff --git a/libc/shared/math/canonicalizebf16.h b/libc/shared/math/canonicalizebf16.h
new file mode 100644
index 0000000000000..1b92e00076362
--- /dev/null
+++ b/libc/shared/math/canonicalizebf16.h
@@ -0,0 +1,23 @@
+//===-- Shared canonicalizebf16 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_CANONICALIZEBF16_H
+#define LLVM_LIBC_SHARED_MATH_CANONICALIZEBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/canonicalizebf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::canonicalizebf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_CANONICALIZEBF16_H
diff --git a/libc/shared/math/canonicalizef.h b/libc/shared/math/canonicalizef.h
new file mode 100644
index 0000000000000..8097cdf0987fd
--- /dev/null
+++ b/libc/shared/math/canonicalizef.h
@@ -0,0 +1,23 @@
+//===-- Shared canonicalizef 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_CANONICALIZEF_H
+#define LLVM_LIBC_SHARED_MATH_CANONICALIZEF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/canonicalizef.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::canonicalizef;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_CANONICALIZEF_H
diff --git a/libc/shared/math/canonicalizef128.h b/libc/shared/math/canonicalizef128.h
new file mode 100644
index 0000000000000..dfc5f89afee50
--- /dev/null
+++ b/libc/shared/math/canonicalizef128.h
@@ -0,0 +1,29 @@
+//===-- Shared canonicalizef128 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_CANONICALIZEF128_H
+#define LLVM_LIBC_SHARED_MATH_CANONICALIZEF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/canonicalizef128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::canonicalizef128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_CANONICALIZEF128_H
diff --git a/libc/shared/math/canonicalizef16.h b/libc/shared/math/canonicalizef16.h
new file mode 100644
index 0000000000000..1925d052ac0fd
--- /dev/null
+++ b/libc/shared/math/canonicalizef16.h
@@ -0,0 +1,29 @@
+//===-- Shared canonicalizef16 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_CANONICALIZEF16_H
+#define LLVM_LIBC_SHARED_MATH_CANONICALIZEF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/canonicalizef16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::canonicalizef16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_CANONICALIZEF16_H
diff --git a/libc/shared/math/canonicalizel.h b/libc/shared/math/canonicalizel.h
new file mode 100644
index 0000000000000..66e2ed9053dc2
--- /dev/null
+++ b/libc/shared/math/canonicalizel.h
@@ -0,0 +1,23 @@
+//===-- Shared canonicalizel 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_CANONICALIZEL_H
+#define LLVM_LIBC_SHARED_MATH_CANONICALIZEL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/canonicalizel.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::canonicalizel;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_CANONICALIZEL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 8027180e2cf08..b3b66924f18d4 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -351,6 +351,63 @@ add_header_library(
libc.src.__support.FPUtil.generic.add_sub
libc.src.__support.macros.config
)
+add_header_library(
+ canonicalize
+ HDRS
+ canonicalize.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ canonicalizebf16
+ HDRS
+ canonicalizebf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ canonicalizef
+ HDRS
+ canonicalizef.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ canonicalizef128
+ HDRS
+ canonicalizef128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ canonicalizef16
+ HDRS
+ canonicalizef16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ canonicalizel
+ HDRS
+ canonicalizel.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
add_header_library(
cbrt
diff --git a/libc/src/__support/math/canonicalize.h b/libc/src/__support/math/canonicalize.h
new file mode 100644
index 0000000000000..e7c60d4026bce
--- /dev/null
+++ b/libc/src/__support/math/canonicalize.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for canonicalize ------------------*- 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_CANONICALIZE_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZE_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int canonicalize(double *cx, const double *x) {
+ return fputil::canonicalize(*cx, *x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZE_H
diff --git a/libc/src/__support/math/canonicalizebf16.h b/libc/src/__support/math/canonicalizebf16.h
new file mode 100644
index 0000000000000..cc6abd40973e7
--- /dev/null
+++ b/libc/src/__support/math/canonicalizebf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for canonicalizebf16 --------------*- 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_CANONICALIZEBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEBF16_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 int canonicalizebf16(bfloat16 *cx, const bfloat16 *x) {
+ return fputil::canonicalize(*cx, *x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEBF16_H
diff --git a/libc/src/__support/math/canonicalizef.h b/libc/src/__support/math/canonicalizef.h
new file mode 100644
index 0000000000000..da166064219d9
--- /dev/null
+++ b/libc/src/__support/math/canonicalizef.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for canonicalizef -----------------*- 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_CANONICALIZEF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEF_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int canonicalizef(float *cx, const float *x) {
+ return fputil::canonicalize(*cx, *x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEF_H
diff --git a/libc/src/__support/math/canonicalizef128.h b/libc/src/__support/math/canonicalizef128.h
new file mode 100644
index 0000000000000..8b4905353ddfa
--- /dev/null
+++ b/libc/src/__support/math/canonicalizef128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for canonicalizef128 --------------*- 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_CANONICALIZEF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEF128_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 int canonicalizef128(float128 *cx, const float128 *x) {
+ return fputil::canonicalize(*cx, *x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEF128_H
diff --git a/libc/src/__support/math/canonicalizef16.h b/libc/src/__support/math/canonicalizef16.h
new file mode 100644
index 0000000000000..b7f44caa8ce3b
--- /dev/null
+++ b/libc/src/__support/math/canonicalizef16.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for canonicalizef16 ---------------*- 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_CANONICALIZEF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEF16_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 int canonicalizef16(float16 *cx, const float16 *x) {
+ return fputil::canonicalize(*cx, *x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEF16_H
diff --git a/libc/src/__support/math/canonicalizel.h b/libc/src/__support/math/canonicalizel.h
new file mode 100644
index 0000000000000..fb69352fa1fb2
--- /dev/null
+++ b/libc/src/__support/math/canonicalizel.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for canonicalizel -----------------*- 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_CANONICALIZEL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEL_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int canonicalizel(long double *cx, const long double *x) {
+ return fputil::canonicalize(*cx, *x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index b7c1f5a911831..fefd222399ba2 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -7,7 +7,7 @@ add_entrypoint_object(
HDRS
../canonicalize.h
DEPENDS
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.canonicalize
)
add_entrypoint_object(
@@ -17,7 +17,7 @@ add_entrypoint_object(
HDRS
../canonicalizef.h
DEPENDS
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.canonicalizef
)
add_entrypoint_object(
@@ -27,8 +27,7 @@ add_entrypoint_object(
HDRS
../canonicalizef16.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.canonicalizef16
)
add_entrypoint_object(
@@ -38,8 +37,7 @@ add_entrypoint_object(
HDRS
../canonicalizef128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.canonicalizef128
)
add_entrypoint_object(
@@ -49,7 +47,7 @@ add_entrypoint_object(
HDRS
../canonicalizel.h
DEPENDS
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.canonicalizel
)
add_entrypoint_object(
@@ -59,11 +57,7 @@ add_entrypoint_object(
HDRS
../canonicalizebf16.h
DEPENDS
- libc.src.__support.common
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
- libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.math.canonicalizebf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/canonicalize.cpp b/libc/src/math/generic/canonicalize.cpp
index d93501d597376..0d2aaf7cc799d 100644
--- a/libc/src/math/generic/canonicalize.cpp
+++ b/libc/src/math/generic/canonicalize.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/canonicalize.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/canonicalize.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, canonicalize, (double *cx, const double *x)) {
- return fputil::canonicalize(*cx, *x);
+ return math::canonicalize(cx, x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/canonicalizebf16.cpp b/libc/src/math/generic/canonicalizebf16.cpp
index 9cc379060c3de..bad7cef480c38 100644
--- a/libc/src/math/generic/canonicalizebf16.cpp
+++ b/libc/src/math/generic/canonicalizebf16.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/canonicalizebf16.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/canonicalizebf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, canonicalizebf16, (bfloat16 * cx, const bfloat16 *x)) {
- return fputil::canonicalize(*cx, *x);
+ return math::canonicalizebf16(cx, x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/canonicalizef.cpp b/libc/src/math/generic/canonicalizef.cpp
index 437cf8768458a..77ffba9789c22 100644
--- a/libc/src/math/generic/canonicalizef.cpp
+++ b/libc/src/math/generic/canonicalizef.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/canonicalizef.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/canonicalizef.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, canonicalizef, (float *cx, const float *x)) {
- return fputil::canonicalize(*cx, *x);
+ return math::canonicalizef(cx, x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/canonicalizef128.cpp b/libc/src/math/generic/canonicalizef128.cpp
index 477d9c740a746..48bce08a555cf 100644
--- a/libc/src/math/generic/canonicalizef128.cpp
+++ b/libc/src/math/generic/canonicalizef128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/canonicalizef128.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/canonicalizef128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, canonicalizef128, (float128 * cx, const float128 *x)) {
- return fputil::canonicalize(*cx, *x);
+ return math::canonicalizef128(cx, x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/canonicalizef16.cpp b/libc/src/math/generic/canonicalizef16.cpp
index ff32c918793ff..f02e57b0a1070 100644
--- a/libc/src/math/generic/canonicalizef16.cpp
+++ b/libc/src/math/generic/canonicalizef16.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/canonicalizef16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/canonicalizef16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, canonicalizef16, (float16 * cx, const float16 *x)) {
- return fputil::canonicalize(*cx, *x);
+ return math::canonicalizef16(cx, x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/canonicalizel.cpp b/libc/src/math/generic/canonicalizel.cpp
index fa2b846216d7b..75b0ba8931bd6 100644
--- a/libc/src/math/generic/canonicalizel.cpp
+++ b/libc/src/math/generic/canonicalizel.cpp
@@ -7,15 +7,13 @@
//===----------------------------------------------------------------------===//
#include "src/math/canonicalizel.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/canonicalizel.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, canonicalizel,
(long double *cx, const long double *x)) {
- return fputil::canonicalize(*cx, *x);
+ return math::canonicalizel(cx, x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 1a0559af51acd..3b77d8bf183e9 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -28,6 +28,12 @@ add_fp_unittest(
libc.src.__support.math.atanhf16
libc.src.__support.math.bf16add
libc.src.__support.math.bf16addf128
+ libc.src.__support.math.canonicalize
+ libc.src.__support.math.canonicalizebf16
+ libc.src.__support.math.canonicalizef
+ libc.src.__support.math.canonicalizef128
+ libc.src.__support.math.canonicalizef16
+ libc.src.__support.math.canonicalizel
libc.src.__support.math.cbrt
libc.src.__support.math.cbrtf
libc.src.__support.math.cos
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index fc6e6c74b3720..12557ac5e671c 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -74,6 +74,12 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_FP_EQ(0x1p+0f16, LIBC_NAMESPACE::shared::f16sqrtl(1.0L));
EXPECT_FP_EQ(0.0f16, LIBC_NAMESPACE::shared::sinf16(0.0f16));
EXPECT_FP_EQ(0.0f16, LIBC_NAMESPACE::shared::tanhf16(0.0f16));
+
+ float16 canonicalizef16_cx = 0.0f16;
+ float16 canonicalizef16_x = 0.0f16;
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef16(&canonicalizef16_cx,
+ &canonicalizef16_x));
+ EXPECT_FP_EQ(0x0p+0f16, canonicalizef16_cx);
}
#endif // LIBC_TYPES_HAS_FLOAT16
@@ -129,6 +135,12 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::shared::sqrtf(0.0f));
EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::shared::tanf(0.0f));
EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::shared::tanhf(0.0f));
+
+ float canonicalizef_cx = 0.0f;
+ float canonicalizef_x = 0.0f;
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef(&canonicalizef_cx,
+ &canonicalizef_x));
+ EXPECT_FP_EQ(0x0p+0f, canonicalizef_cx);
}
TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -136,7 +148,6 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::asin(0.0));
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::atan(0.0));
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::atan2(0.0, 0.0));
- EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16add(2.0, 3.0));
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::cbrt(0.0));
EXPECT_FP_EQ(0x1p+0, LIBC_NAMESPACE::shared::cos(0.0));
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::dsqrtl(0.0));
@@ -156,6 +167,12 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::tan(0.0));
EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogb(1.0));
EXPECT_EQ(0L, LIBC_NAMESPACE::shared::llogb(1.0));
+
+ double canonicalize_cx = 0.0;
+ double canonicalize_x = 0.0;
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalize(&canonicalize_cx,
+ &canonicalize_x));
+ EXPECT_FP_EQ(0.0, canonicalize_cx);
}
TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -165,6 +182,12 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::ilogbl(0x1.p+0L));
EXPECT_EQ(0L, LIBC_NAMESPACE::shared::llogbl(1.0L));
EXPECT_FP_EQ(10.0f, LIBC_NAMESPACE::shared::ffmal(2.0L, 3.0, 4.0L));
+
+ long double canonicalizel_cx = 0.0L;
+ long double canonicalizel_x = 0.0L;
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizel(&canonicalizel_cx,
+ &canonicalizel_x));
+ EXPECT_FP_EQ(0x0p+0L, canonicalizel_cx);
}
#ifdef LIBC_TYPES_HAS_FLOAT128
@@ -194,6 +217,22 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16addf128(
float128(2.0), float128(3.0)));
+
+ float128 canonicalizef128_cx = float128(0.0);
+ float128 canonicalizef128_x = float128(0.0);
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef128(&canonicalizef128_cx,
+ &canonicalizef128_x));
+ EXPECT_FP_EQ(float128(0.0), canonicalizef128_cx);
}
#endif // LIBC_TYPES_HAS_FLOAT128
+
+TEST(LlvmLibcSharedMathTest, AllBFloat16) {
+ EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16add(2.0, 3.0));
+
+ bfloat16 canonicalizebf16_cx = bfloat16(0.0);
+ bfloat16 canonicalizebf16_x = bfloat16(0.0);
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizebf16(&canonicalizebf16_cx,
+ &canonicalizebf16_x));
+ EXPECT_FP_EQ(bfloat16(0.0), canonicalizebf16_cx);
+}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 0eaff89f04215..72106798ec279 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2655,6 +2655,63 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_canonicalize",
+ hdrs = ["src/__support/math/canonicalize.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_canonicalizebf16",
+ hdrs = ["src/__support/math/canonicalizebf16.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_fputil_bfloat16",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_canonicalizef",
+ hdrs = ["src/__support/math/canonicalizef.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_canonicalizef128",
+ hdrs = ["src/__support/math/canonicalizef128.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_canonicalizef16",
+ hdrs = ["src/__support/math/canonicalizef16.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_canonicalizel",
+ hdrs = ["src/__support/math/canonicalizel.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_cbrt",
hdrs = ["src/__support/math/cbrt.h"],
@@ -4341,15 +4398,40 @@ libc_math_function(
additional_deps = [":__support_math_bf16addf128"],
)
-libc_math_function(name = "canonicalize")
+libc_math_function(
+ name = "canonicalize",
+ additional_deps = [
+ ":__support_math_canonicalize",
+ ],
+)
-libc_math_function(name = "canonicalizef")
+libc_math_function(
+ name = "canonicalizef",
+ additional_deps = [
+ ":__support_math_canonicalizef",
+ ],
+)
-libc_math_function(name = "canonicalizel")
+libc_math_function(
+ name = "canonicalizel",
+ additional_deps = [
+ ":__support_math_canonicalizel",
+ ],
+)
-libc_math_function(name = "canonicalizef128")
+libc_math_function(
+ name = "canonicalizef128",
+ additional_deps = [
+ ":__support_math_canonicalizef128",
+ ],
+)
-libc_math_function(name = "canonicalizef16")
+libc_math_function(
+ name = "canonicalizef16",
+ additional_deps = [
+ ":__support_math_canonicalizef16",
+ ],
+)
libc_math_function(name = "iscanonical")
More information about the libc-commits
mailing list