[libc-commits] [libc] [llvm] [libc][math] Refactor canonicalize family to header-only (PR #181467)
via libc-commits
libc-commits at lists.llvm.org
Sun Feb 15 08:29:08 PST 2026
https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/181467
>From 1da1762be6e855d76a787c6a3e0af185e39e113e Mon Sep 17 00:00:00 2001
From: Ezzeldin Ibrahim <ezzibrahimx at gmail.com>
Date: Sat, 14 Feb 2026 10:19:43 +0200
Subject: [PATCH 1/2] [libc][math] Refactor canonicalize family to header-only
---
libc/shared/math.h | 6 ++
libc/shared/math/canonicalize.h | 23 +++++
libc/shared/math/canonicalizebf16.h | 23 +++++
libc/shared/math/canonicalizef.h | 23 +++++
libc/shared/math/canonicalizef128.h | 29 ++++++
libc/shared/math/canonicalizef16.h | 29 ++++++
libc/shared/math/canonicalizel.h | 23 +++++
libc/src/__support/math/CMakeLists.txt | 54 +++++++++++
libc/src/__support/math/canonicalize.h | 27 ++++++
libc/src/__support/math/canonicalizebf16.h | 28 ++++++
libc/src/__support/math/canonicalizef.h | 27 ++++++
libc/src/__support/math/canonicalizef128.h | 33 +++++++
libc/src/__support/math/canonicalizef16.h | 33 +++++++
libc/src/__support/math/canonicalizel.h | 27 ++++++
libc/src/math/generic/CMakeLists.txt | 18 ++--
libc/src/math/generic/canonicalize.cpp | 6 +-
libc/src/math/generic/canonicalizebf16.cpp | 7 +-
libc/src/math/generic/canonicalizef.cpp | 6 +-
libc/src/math/generic/canonicalizef128.cpp | 6 +-
libc/src/math/generic/canonicalizef16.cpp | 6 +-
libc/src/math/generic/canonicalizel.cpp | 6 +-
libc/test/shared/CMakeLists.txt | 6 ++
libc/test/shared/shared_math_test.cpp | 41 ++++++++-
.../llvm-project-overlay/libc/BUILD.bazel | 89 +++++++++++++++++--
24 files changed, 533 insertions(+), 43 deletions(-)
create mode 100644 libc/shared/math/canonicalize.h
create mode 100644 libc/shared/math/canonicalizebf16.h
create mode 100644 libc/shared/math/canonicalizef.h
create mode 100644 libc/shared/math/canonicalizef128.h
create mode 100644 libc/shared/math/canonicalizef16.h
create mode 100644 libc/shared/math/canonicalizel.h
create mode 100644 libc/src/__support/math/canonicalize.h
create mode 100644 libc/src/__support/math/canonicalizebf16.h
create mode 100644 libc/src/__support/math/canonicalizef.h
create mode 100644 libc/src/__support/math/canonicalizef128.h
create mode 100644 libc/src/__support/math/canonicalizef16.h
create mode 100644 libc/src/__support/math/canonicalizel.h
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..662398848c898 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -351,6 +351,60 @@ 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
+)
+
+add_header_library(
+ canonicalizebf16
+ HDRS
+ canonicalizebf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.common
+ libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
+)
+
+add_header_library(
+ canonicalizef
+ HDRS
+ canonicalizef.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+)
+
+add_header_library(
+ canonicalizef128
+ HDRS
+ canonicalizef128.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.properties.types
+)
+
+add_header_library(
+ canonicalizef16
+ HDRS
+ canonicalizef16.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.properties.types
+)
+
+add_header_library(
+ canonicalizel
+ HDRS
+ canonicalizel.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+)
+
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..eb208b2de744e
--- /dev/null
+++ b/libc/src/__support/math/canonicalize.h
@@ -0,0 +1,27 @@
+//===-- 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/common.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..9a2fe3b6561cf
--- /dev/null
+++ b/libc/src/__support/math/canonicalizebf16.h
@@ -0,0 +1,28 @@
+//===-- 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/common.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..39e20b9253e53
--- /dev/null
+++ b/libc/src/__support/math/canonicalizef.h
@@ -0,0 +1,27 @@
+//===-- 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/common.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..de357c75c655f
--- /dev/null
+++ b/libc/src/__support/math/canonicalizef128.h
@@ -0,0 +1,33 @@
+//===-- 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/common.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..6feea9aa271d1
--- /dev/null
+++ b/libc/src/__support/math/canonicalizef16.h
@@ -0,0 +1,33 @@
+//===-- 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/common.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..63b4af24718ad
--- /dev/null
+++ b/libc/src/__support/math/canonicalizel.h
@@ -0,0 +1,27 @@
+//===-- 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/common.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..be3ecd46dcfd6 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2655,6 +2655,60 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_canonicalize",
+ hdrs = ["src/__support/math/canonicalize.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_canonicalizebf16",
+ hdrs = ["src/__support/math/canonicalizebf16.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_basic_operations",
+ ":__support_fputil_bfloat16",
+ ":__support_macros_config",
+ ":__support_macros_properties_types",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_canonicalizef",
+ hdrs = ["src/__support/math/canonicalizef.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_canonicalizef128",
+ hdrs = ["src/__support/math/canonicalizef128.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_properties_types",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_canonicalizef16",
+ hdrs = ["src/__support/math/canonicalizef16.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_properties_types",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_canonicalizel",
+ hdrs = ["src/__support/math/canonicalizel.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ],
+)
+
libc_support_library(
name = "__support_math_cbrt",
hdrs = ["src/__support/math/cbrt.h"],
@@ -4341,15 +4395,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")
>From c2fdb2bc272452eb24874496d8be3c2dab26cd54 Mon Sep 17 00:00:00 2001
From: Ezzeldin Ibrahim <ezzibrahimx at gmail.com>
Date: Sun, 15 Feb 2026 18:27:54 +0200
Subject: [PATCH 2/2] make deps Consistent
---
libc/src/__support/math/CMakeLists.txt | 11 +++++++----
libc/src/__support/math/canonicalize.h | 1 -
libc/src/__support/math/canonicalizebf16.h | 1 -
libc/src/__support/math/canonicalizef.h | 1 -
libc/src/__support/math/canonicalizef128.h | 1 -
libc/src/__support/math/canonicalizef16.h | 1 -
libc/src/__support/math/canonicalizel.h | 1 -
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 11 +++++++----
8 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 662398848c898..b3b66924f18d4 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -357,6 +357,7 @@ add_header_library(
canonicalize.h
DEPENDS
libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
)
add_header_library(
@@ -366,9 +367,7 @@ add_header_library(
DEPENDS
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.bfloat16
- libc.src.__support.common
libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
)
add_header_library(
@@ -377,6 +376,7 @@ add_header_library(
canonicalizef.h
DEPENDS
libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
)
add_header_library(
@@ -384,8 +384,9 @@ add_header_library(
HDRS
canonicalizef128.h
DEPENDS
+ libc.include.llvm-libc-types.float128
libc.src.__support.FPUtil.basic_operations
- libc.src.__support.macros.properties.types
+ libc.src.__support.macros.config
)
add_header_library(
@@ -393,8 +394,9 @@ add_header_library(
HDRS
canonicalizef16.h
DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
libc.src.__support.FPUtil.basic_operations
- libc.src.__support.macros.properties.types
+ libc.src.__support.macros.config
)
add_header_library(
@@ -403,6 +405,7 @@ add_header_library(
canonicalizel.h
DEPENDS
libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
)
diff --git a/libc/src/__support/math/canonicalize.h b/libc/src/__support/math/canonicalize.h
index eb208b2de744e..e7c60d4026bce 100644
--- a/libc/src/__support/math/canonicalize.h
+++ b/libc/src/__support/math/canonicalize.h
@@ -10,7 +10,6 @@
#define LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZE_H
#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/__support/math/canonicalizebf16.h b/libc/src/__support/math/canonicalizebf16.h
index 9a2fe3b6561cf..cc6abd40973e7 100644
--- a/libc/src/__support/math/canonicalizebf16.h
+++ b/libc/src/__support/math/canonicalizebf16.h
@@ -11,7 +11,6 @@
#include "src/__support/FPUtil/BasicOperations.h"
#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/__support/math/canonicalizef.h b/libc/src/__support/math/canonicalizef.h
index 39e20b9253e53..da166064219d9 100644
--- a/libc/src/__support/math/canonicalizef.h
+++ b/libc/src/__support/math/canonicalizef.h
@@ -10,7 +10,6 @@
#define LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEF_H
#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/__support/math/canonicalizef128.h b/libc/src/__support/math/canonicalizef128.h
index de357c75c655f..8b4905353ddfa 100644
--- a/libc/src/__support/math/canonicalizef128.h
+++ b/libc/src/__support/math/canonicalizef128.h
@@ -14,7 +14,6 @@
#ifdef LIBC_TYPES_HAS_FLOAT128
#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/__support/math/canonicalizef16.h b/libc/src/__support/math/canonicalizef16.h
index 6feea9aa271d1..b7f44caa8ce3b 100644
--- a/libc/src/__support/math/canonicalizef16.h
+++ b/libc/src/__support/math/canonicalizef16.h
@@ -14,7 +14,6 @@
#ifdef LIBC_TYPES_HAS_FLOAT16
#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/__support/math/canonicalizel.h b/libc/src/__support/math/canonicalizel.h
index 63b4af24718ad..fb69352fa1fb2 100644
--- a/libc/src/__support/math/canonicalizel.h
+++ b/libc/src/__support/math/canonicalizel.h
@@ -10,7 +10,6 @@
#define LLVM_LIBC_SRC___SUPPORT_MATH_CANONICALIZEL_H
#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index be3ecd46dcfd6..72106798ec279 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2660,6 +2660,7 @@ libc_support_library(
hdrs = ["src/__support/math/canonicalize.h"],
deps = [
":__support_fputil_basic_operations",
+ ":__support_macros_config",
],
)
@@ -2667,11 +2668,9 @@ libc_support_library(
name = "__support_math_canonicalizebf16",
hdrs = ["src/__support/math/canonicalizebf16.h"],
deps = [
- ":__support_common",
":__support_fputil_basic_operations",
":__support_fputil_bfloat16",
":__support_macros_config",
- ":__support_macros_properties_types",
],
)
@@ -2680,6 +2679,7 @@ libc_support_library(
hdrs = ["src/__support/math/canonicalizef.h"],
deps = [
":__support_fputil_basic_operations",
+ ":__support_macros_config",
],
)
@@ -2688,7 +2688,8 @@ libc_support_library(
hdrs = ["src/__support/math/canonicalizef128.h"],
deps = [
":__support_fputil_basic_operations",
- ":__support_macros_properties_types",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
],
)
@@ -2697,7 +2698,8 @@ libc_support_library(
hdrs = ["src/__support/math/canonicalizef16.h"],
deps = [
":__support_fputil_basic_operations",
- ":__support_macros_properties_types",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
],
)
@@ -2706,6 +2708,7 @@ libc_support_library(
hdrs = ["src/__support/math/canonicalizel.h"],
deps = [
":__support_fputil_basic_operations",
+ ":__support_macros_config",
],
)
More information about the libc-commits
mailing list