[libc-commits] [libc] [llvm] [libc][math] Refactor round-roundeven-trunc family to header-only (PR #195590)
via libc-commits
libc-commits at lists.llvm.org
Sun May 3 23:23:57 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Anonmiraj (AnonMiraj)
<details>
<summary>Changes</summary>
Refactors the round-roundeven-trunc math family to be header-only.
part of: #<!-- -->147386
Target Functions:
- round
- roundbf16
- roundf
- roundf128
- roundf16
- roundl
- roundeven
- roundevenbf16
- roundevenf
- roundevenf128
- roundevenf16
- roundevenl
- trunc
- truncbf16
- truncf
- truncf128
- truncf16
- truncl
---
Patch is 81.07 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/195590.diff
61 Files Affected:
- (modified) libc/shared/math.h (+18)
- (added) libc/shared/math/round.h (+23)
- (added) libc/shared/math/roundbf16.h (+23)
- (added) libc/shared/math/roundeven.h (+23)
- (added) libc/shared/math/roundevenbf16.h (+23)
- (added) libc/shared/math/roundevenf.h (+23)
- (added) libc/shared/math/roundevenf128.h (+29)
- (added) libc/shared/math/roundevenf16.h (+29)
- (added) libc/shared/math/roundevenl.h (+23)
- (added) libc/shared/math/roundf.h (+23)
- (added) libc/shared/math/roundf128.h (+29)
- (added) libc/shared/math/roundf16.h (+29)
- (added) libc/shared/math/roundl.h (+23)
- (added) libc/shared/math/trunc.h (+23)
- (added) libc/shared/math/truncbf16.h (+23)
- (added) libc/shared/math/truncf.h (+23)
- (added) libc/shared/math/truncf128.h (+29)
- (added) libc/shared/math/truncf16.h (+29)
- (added) libc/shared/math/truncl.h (+23)
- (modified) libc/src/__support/math/CMakeLists.txt (+199)
- (added) libc/src/__support/math/round.h (+29)
- (added) libc/src/__support/math/roundbf16.h (+26)
- (added) libc/src/__support/math/roundeven.h (+30)
- (added) libc/src/__support/math/roundevenbf16.h (+26)
- (added) libc/src/__support/math/roundevenf.h (+30)
- (added) libc/src/__support/math/roundevenf128.h (+31)
- (added) libc/src/__support/math/roundevenf16.h (+39)
- (added) libc/src/__support/math/roundevenl.h (+25)
- (added) libc/src/__support/math/roundf.h (+29)
- (added) libc/src/__support/math/roundf128.h (+31)
- (added) libc/src/__support/math/roundf16.h (+39)
- (added) libc/src/__support/math/roundl.h (+25)
- (added) libc/src/__support/math/trunc.h (+30)
- (added) libc/src/__support/math/truncbf16.h (+26)
- (added) libc/src/__support/math/truncf.h (+30)
- (added) libc/src/__support/math/truncf128.h (+31)
- (added) libc/src/__support/math/truncf16.h (+39)
- (added) libc/src/__support/math/truncl.h (+25)
- (modified) libc/src/math/generic/CMakeLists.txt (+18-66)
- (modified) libc/src/math/generic/round.cpp (+2-10)
- (modified) libc/src/math/generic/roundbf16.cpp (+2-5)
- (modified) libc/src/math/generic/roundeven.cpp (+2-10)
- (modified) libc/src/math/generic/roundevenbf16.cpp (+2-5)
- (modified) libc/src/math/generic/roundevenf.cpp (+2-10)
- (modified) libc/src/math/generic/roundevenf128.cpp (+2-4)
- (modified) libc/src/math/generic/roundevenf16.cpp (+2-11)
- (modified) libc/src/math/generic/roundevenl.cpp (+2-4)
- (modified) libc/src/math/generic/roundf.cpp (+2-10)
- (modified) libc/src/math/generic/roundf128.cpp (+2-4)
- (modified) libc/src/math/generic/roundf16.cpp (+2-13)
- (modified) libc/src/math/generic/roundl.cpp (+2-4)
- (modified) libc/src/math/generic/trunc.cpp (+2-10)
- (modified) libc/src/math/generic/truncbf16.cpp (+2-5)
- (modified) libc/src/math/generic/truncf.cpp (+2-10)
- (modified) libc/src/math/generic/truncf128.cpp (+2-4)
- (modified) libc/src/math/generic/truncf16.cpp (+2-13)
- (modified) libc/src/math/generic/truncl.cpp (+2-4)
- (modified) libc/test/shared/CMakeLists.txt (+36)
- (modified) libc/test/shared/shared_math_constexpr_test.cpp (+24)
- (modified) libc/test/shared/shared_math_test.cpp (+20)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+261-15)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index bed4279f621a0..1223efa3cbc25 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -392,6 +392,18 @@
#include "math/rintf128.h"
#include "math/rintf16.h"
#include "math/rintl.h"
+#include "math/round.h"
+#include "math/roundbf16.h"
+#include "math/roundeven.h"
+#include "math/roundevenbf16.h"
+#include "math/roundevenf.h"
+#include "math/roundevenf128.h"
+#include "math/roundevenf16.h"
+#include "math/roundevenl.h"
+#include "math/roundf.h"
+#include "math/roundf128.h"
+#include "math/roundf16.h"
+#include "math/roundl.h"
#include "math/rsqrtf.h"
#include "math/rsqrtf16.h"
#include "math/scalbln.h"
@@ -452,6 +464,12 @@
#include "math/totalordermagf128.h"
#include "math/totalordermagf16.h"
#include "math/totalordermagl.h"
+#include "math/trunc.h"
+#include "math/truncbf16.h"
+#include "math/truncf.h"
+#include "math/truncf128.h"
+#include "math/truncf16.h"
+#include "math/truncl.h"
#include "math/ufromfp.h"
#include "math/ufromfpbf16.h"
#include "math/ufromfpf.h"
diff --git a/libc/shared/math/round.h b/libc/shared/math/round.h
new file mode 100644
index 0000000000000..74282f8830527
--- /dev/null
+++ b/libc/shared/math/round.h
@@ -0,0 +1,23 @@
+//===-- Shared round 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_ROUND_H
+#define LLVM_LIBC_SHARED_MATH_ROUND_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/round.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::round;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUND_H
diff --git a/libc/shared/math/roundbf16.h b/libc/shared/math/roundbf16.h
new file mode 100644
index 0000000000000..565fa6bc52df9
--- /dev/null
+++ b/libc/shared/math/roundbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared roundbf16 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_ROUNDBF16_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDBF16_H
diff --git a/libc/shared/math/roundeven.h b/libc/shared/math/roundeven.h
new file mode 100644
index 0000000000000..42a3533e80511
--- /dev/null
+++ b/libc/shared/math/roundeven.h
@@ -0,0 +1,23 @@
+//===-- Shared roundeven 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_ROUNDEVEN_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDEVEN_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundeven.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundeven;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDEVEN_H
diff --git a/libc/shared/math/roundevenbf16.h b/libc/shared/math/roundevenbf16.h
new file mode 100644
index 0000000000000..7d1d93600b437
--- /dev/null
+++ b/libc/shared/math/roundevenbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared roundevenbf16 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_ROUNDEVENBF16_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDEVENBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundevenbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundevenbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDEVENBF16_H
diff --git a/libc/shared/math/roundevenf.h b/libc/shared/math/roundevenf.h
new file mode 100644
index 0000000000000..bec33017bee5b
--- /dev/null
+++ b/libc/shared/math/roundevenf.h
@@ -0,0 +1,23 @@
+//===-- Shared roundevenf 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_ROUNDEVENF_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDEVENF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundevenf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundevenf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDEVENF_H
diff --git a/libc/shared/math/roundevenf128.h b/libc/shared/math/roundevenf128.h
new file mode 100644
index 0000000000000..5d47fd5d267f8
--- /dev/null
+++ b/libc/shared/math/roundevenf128.h
@@ -0,0 +1,29 @@
+//===-- Shared roundevenf128 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_ROUNDEVENF128_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDEVENF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundevenf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundevenf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDEVENF128_H
diff --git a/libc/shared/math/roundevenf16.h b/libc/shared/math/roundevenf16.h
new file mode 100644
index 0000000000000..fbe287471ed59
--- /dev/null
+++ b/libc/shared/math/roundevenf16.h
@@ -0,0 +1,29 @@
+//===-- Shared roundevenf16 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_ROUNDEVENF16_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDEVENF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundevenf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundevenf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDEVENF16_H
diff --git a/libc/shared/math/roundevenl.h b/libc/shared/math/roundevenl.h
new file mode 100644
index 0000000000000..b8beb858a0cc0
--- /dev/null
+++ b/libc/shared/math/roundevenl.h
@@ -0,0 +1,23 @@
+//===-- Shared roundevenl 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_ROUNDEVENL_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDEVENL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundevenl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundevenl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDEVENL_H
diff --git a/libc/shared/math/roundf.h b/libc/shared/math/roundf.h
new file mode 100644
index 0000000000000..5822fe2d37346
--- /dev/null
+++ b/libc/shared/math/roundf.h
@@ -0,0 +1,23 @@
+//===-- Shared roundf 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_ROUNDF_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDF_H
diff --git a/libc/shared/math/roundf128.h b/libc/shared/math/roundf128.h
new file mode 100644
index 0000000000000..ea0fd23fce180
--- /dev/null
+++ b/libc/shared/math/roundf128.h
@@ -0,0 +1,29 @@
+//===-- Shared roundf128 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_ROUNDF128_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDF128_H
diff --git a/libc/shared/math/roundf16.h b/libc/shared/math/roundf16.h
new file mode 100644
index 0000000000000..d097cba753f0f
--- /dev/null
+++ b/libc/shared/math/roundf16.h
@@ -0,0 +1,29 @@
+//===-- Shared roundf16 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_ROUNDF16_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDF16_H
diff --git a/libc/shared/math/roundl.h b/libc/shared/math/roundl.h
new file mode 100644
index 0000000000000..644f7f17fae5d
--- /dev/null
+++ b/libc/shared/math/roundl.h
@@ -0,0 +1,23 @@
+//===-- Shared roundl 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_ROUNDL_H
+#define LLVM_LIBC_SHARED_MATH_ROUNDL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/roundl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::roundl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ROUNDL_H
diff --git a/libc/shared/math/trunc.h b/libc/shared/math/trunc.h
new file mode 100644
index 0000000000000..06e2aefe8164d
--- /dev/null
+++ b/libc/shared/math/trunc.h
@@ -0,0 +1,23 @@
+//===-- Shared trunc 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_TRUNC_H
+#define LLVM_LIBC_SHARED_MATH_TRUNC_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/trunc.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::trunc;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TRUNC_H
diff --git a/libc/shared/math/truncbf16.h b/libc/shared/math/truncbf16.h
new file mode 100644
index 0000000000000..1e5c6e96f215a
--- /dev/null
+++ b/libc/shared/math/truncbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared truncbf16 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_TRUNCBF16_H
+#define LLVM_LIBC_SHARED_MATH_TRUNCBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/truncbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::truncbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TRUNCBF16_H
diff --git a/libc/shared/math/truncf.h b/libc/shared/math/truncf.h
new file mode 100644
index 0000000000000..63f70770aff2a
--- /dev/null
+++ b/libc/shared/math/truncf.h
@@ -0,0 +1,23 @@
+//===-- Shared truncf 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_TRUNCF_H
+#define LLVM_LIBC_SHARED_MATH_TRUNCF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/truncf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::truncf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TRUNCF_H
diff --git a/libc/shared/math/truncf128.h b/libc/shared/math/truncf128.h
new file mode 100644
index 0000000000000..7694a8e4955e8
--- /dev/null
+++ b/libc/shared/math/truncf128.h
@@ -0,0 +1,29 @@
+//===-- Shared truncf128 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_TRUNCF128_H
+#define LLVM_LIBC_SHARED_MATH_TRUNCF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/truncf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::truncf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_TRUNCF128_H
diff --git a/libc/shared/math/truncf16.h b/libc/shared/math/truncf16.h
new file mode 100644
index 0000000000000..8f5126d87e603
--- /dev/null
+++ b/libc/shared/math/truncf16.h
@@ -0,0 +1,29 @@
+//===-- Shared truncf16 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_TRUNCF16_H
+#define LLVM_LIBC_SHARED_MATH_TRUNCF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/truncf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::truncf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_TRUNCF16_H
diff --git a/libc/shared/math/truncl.h b/libc/shared/math/truncl.h
new file mode 100644
index 0000000000000..4b5760936fb96
--- /dev/null
+++ b/libc/shared/math/truncl.h
@@ -0,0 +1,23 @@
+//===-- Shared truncl 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_TRUNCL_H
+#define LLVM_LIBC_SHARED_MATH_TRUNCL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/truncl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::truncl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_TRUNCL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index a7d08c2d40cb5..7986abbe56bf9 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -2191,6 +2191,138 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ round
+ HDRS
+ round.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ roundbf16
+ HDRS
+ roundbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+add_header_library(
+ roundeven
+ HDRS
+ roundeven.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ roundevenbf16
+ HDRS
+ roundevenbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ roundevenf
+ HDRS
+ roundevenf.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ roundevenf128
+ HDRS
+ roundevenf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ roundevenf16
+ HDRS
+ roundevenf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ roundevenl
+ HDRS
+ roundevenl.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+
+add_header_library(
+ roundf
+ HDRS
+ ...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/195590
More information about the libc-commits
mailing list