[libc-commits] [libc] [llvm] [libc][math] Refactor fromfp family to header-only (PR #195413)
via libc-commits
libc-commits at lists.llvm.org
Fri May 1 22:22:05 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Anonmiraj (AnonMiraj)
<details>
<summary>Changes</summary>
Refactors the fromfp math family to be header-only.
part of: #<!-- -->147386
Target Functions:
- fromfp
- fromfpbf16
- fromfpf
- fromfpf128
- fromfpf16
- fromfpl
- fromfpx
- fromfpxbf16
- fromfpxf
- fromfpxf128
- fromfpxf16
- fromfpxl
---
Patch is 55.67 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/195413.diff
43 Files Affected:
- (modified) libc/shared/math.h (+12)
- (added) libc/shared/math/fromfp.h (+23)
- (added) libc/shared/math/fromfpbf16.h (+23)
- (added) libc/shared/math/fromfpf.h (+23)
- (added) libc/shared/math/fromfpf128.h (+29)
- (added) libc/shared/math/fromfpf16.h (+29)
- (added) libc/shared/math/fromfpl.h (+23)
- (added) libc/shared/math/fromfpx.h (+23)
- (added) libc/shared/math/fromfpxbf16.h (+23)
- (added) libc/shared/math/fromfpxf.h (+23)
- (added) libc/shared/math/fromfpxf128.h (+29)
- (added) libc/shared/math/fromfpxf16.h (+29)
- (added) libc/shared/math/fromfpxl.h (+23)
- (modified) libc/src/__support/math/CMakeLists.txt (+114)
- (added) libc/src/__support/math/fromfp.h (+25)
- (added) libc/src/__support/math/fromfpbf16.h (+27)
- (added) libc/src/__support/math/fromfpf.h (+25)
- (added) libc/src/__support/math/fromfpf128.h (+32)
- (added) libc/src/__support/math/fromfpf16.h (+32)
- (added) libc/src/__support/math/fromfpl.h (+26)
- (added) libc/src/__support/math/fromfpx.h (+25)
- (added) libc/src/__support/math/fromfpxbf16.h (+27)
- (added) libc/src/__support/math/fromfpxf.h (+25)
- (added) libc/src/__support/math/fromfpxf128.h (+32)
- (added) libc/src/__support/math/fromfpxf16.h (+32)
- (added) libc/src/__support/math/fromfpxl.h (+26)
- (modified) libc/src/math/generic/CMakeLists.txt (+12-24)
- (modified) libc/src/math/generic/fromfp.cpp (+2-4)
- (modified) libc/src/math/generic/fromfpbf16.cpp (+2-5)
- (modified) libc/src/math/generic/fromfpf.cpp (+2-4)
- (modified) libc/src/math/generic/fromfpf128.cpp (+2-4)
- (modified) libc/src/math/generic/fromfpf16.cpp (+2-4)
- (modified) libc/src/math/generic/fromfpl.cpp (+2-4)
- (modified) libc/src/math/generic/fromfpx.cpp (+2-4)
- (modified) libc/src/math/generic/fromfpxbf16.cpp (+2-5)
- (modified) libc/src/math/generic/fromfpxf.cpp (+2-4)
- (modified) libc/src/math/generic/fromfpxf128.cpp (+2-4)
- (modified) libc/src/math/generic/fromfpxf16.cpp (+2-4)
- (modified) libc/src/math/generic/fromfpxl.cpp (+2-4)
- (modified) libc/test/shared/CMakeLists.txt (+24)
- (modified) libc/test/shared/shared_math_constexpr_test.cpp (+17)
- (modified) libc/test/shared/shared_math_test.cpp (+16)
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+176-6)
``````````diff
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 42826eaa98067..b5fd88dd026f5 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -232,6 +232,18 @@
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
+#include "math/fromfp.h"
+#include "math/fromfpbf16.h"
+#include "math/fromfpf.h"
+#include "math/fromfpf128.h"
+#include "math/fromfpf16.h"
+#include "math/fromfpl.h"
+#include "math/fromfpx.h"
+#include "math/fromfpxbf16.h"
+#include "math/fromfpxf.h"
+#include "math/fromfpxf128.h"
+#include "math/fromfpxf16.h"
+#include "math/fromfpxl.h"
#include "math/fsqrt.h"
#include "math/fsqrtf128.h"
#include "math/fsqrtl.h"
diff --git a/libc/shared/math/fromfp.h b/libc/shared/math/fromfp.h
new file mode 100644
index 0000000000000..6ffa1fa0f2f4e
--- /dev/null
+++ b/libc/shared/math/fromfp.h
@@ -0,0 +1,23 @@
+//===-- Shared fromfp 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_FROMFP_H
+#define LLVM_LIBC_SHARED_MATH_FROMFP_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfp.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfp;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFP_H
diff --git a/libc/shared/math/fromfpbf16.h b/libc/shared/math/fromfpbf16.h
new file mode 100644
index 0000000000000..5d4e110bad86a
--- /dev/null
+++ b/libc/shared/math/fromfpbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared fromfpbf16 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_FROMFPBF16_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPBF16_H
diff --git a/libc/shared/math/fromfpf.h b/libc/shared/math/fromfpf.h
new file mode 100644
index 0000000000000..bd6b00809649d
--- /dev/null
+++ b/libc/shared/math/fromfpf.h
@@ -0,0 +1,23 @@
+//===-- Shared fromfpf 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_FROMFPF_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPF_H
diff --git a/libc/shared/math/fromfpf128.h b/libc/shared/math/fromfpf128.h
new file mode 100644
index 0000000000000..4e4c55b6efcfd
--- /dev/null
+++ b/libc/shared/math/fromfpf128.h
@@ -0,0 +1,29 @@
+//===-- Shared fromfpf128 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_FROMFPF128_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPF128_H
diff --git a/libc/shared/math/fromfpf16.h b/libc/shared/math/fromfpf16.h
new file mode 100644
index 0000000000000..d26baac4b3fec
--- /dev/null
+++ b/libc/shared/math/fromfpf16.h
@@ -0,0 +1,29 @@
+//===-- Shared fromfpf16 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_FROMFPF16_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPF16_H
diff --git a/libc/shared/math/fromfpl.h b/libc/shared/math/fromfpl.h
new file mode 100644
index 0000000000000..055ca2743f7dd
--- /dev/null
+++ b/libc/shared/math/fromfpl.h
@@ -0,0 +1,23 @@
+//===-- Shared fromfpl 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_FROMFPL_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPL_H
diff --git a/libc/shared/math/fromfpx.h b/libc/shared/math/fromfpx.h
new file mode 100644
index 0000000000000..2784d8f88b430
--- /dev/null
+++ b/libc/shared/math/fromfpx.h
@@ -0,0 +1,23 @@
+//===-- Shared fromfpx 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_FROMFPX_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPX_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpx.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpx;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPX_H
diff --git a/libc/shared/math/fromfpxbf16.h b/libc/shared/math/fromfpxbf16.h
new file mode 100644
index 0000000000000..f19c2feca75d3
--- /dev/null
+++ b/libc/shared/math/fromfpxbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared fromfpxbf16 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_FROMFPXBF16_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPXBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpxbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpxbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPXBF16_H
diff --git a/libc/shared/math/fromfpxf.h b/libc/shared/math/fromfpxf.h
new file mode 100644
index 0000000000000..8a40dcb5d0ed2
--- /dev/null
+++ b/libc/shared/math/fromfpxf.h
@@ -0,0 +1,23 @@
+//===-- Shared fromfpxf 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_FROMFPXF_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPXF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpxf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpxf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPXF_H
diff --git a/libc/shared/math/fromfpxf128.h b/libc/shared/math/fromfpxf128.h
new file mode 100644
index 0000000000000..dbdb89cc2d8e7
--- /dev/null
+++ b/libc/shared/math/fromfpxf128.h
@@ -0,0 +1,29 @@
+//===-- Shared fromfpxf128 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_FROMFPXF128_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPXF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpxf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpxf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPXF128_H
diff --git a/libc/shared/math/fromfpxf16.h b/libc/shared/math/fromfpxf16.h
new file mode 100644
index 0000000000000..16696178b0de1
--- /dev/null
+++ b/libc/shared/math/fromfpxf16.h
@@ -0,0 +1,29 @@
+//===-- Shared fromfpxf16 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_FROMFPXF16_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPXF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpxf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpxf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPXF16_H
diff --git a/libc/shared/math/fromfpxl.h b/libc/shared/math/fromfpxl.h
new file mode 100644
index 0000000000000..2f6044cd182b4
--- /dev/null
+++ b/libc/shared/math/fromfpxl.h
@@ -0,0 +1,23 @@
+//===-- Shared fromfpxl 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_FROMFPXL_H
+#define LLVM_LIBC_SHARED_MATH_FROMFPXL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fromfpxl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fromfpxl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FROMFPXL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 762c1478f8dbd..eb36df1e823c9 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1332,6 +1332,120 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ fromfp
+ HDRS
+ fromfp.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpbf16
+ HDRS
+ fromfpbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpf
+ HDRS
+ fromfpf.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpf128
+ HDRS
+ fromfpf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpf16
+ HDRS
+ fromfpf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpl
+ HDRS
+ fromfpl.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpx
+ HDRS
+ fromfpx.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpxbf16
+ HDRS
+ fromfpxbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpxf
+ HDRS
+ fromfpxf.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpxf128
+ HDRS
+ fromfpxf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpxf16
+ HDRS
+ fromfpxf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fromfpxl
+ HDRS
+ fromfpxl.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
add_header_library(
llogbbf16
HDRS
diff --git a/libc/src/__support/math/fromfp.h b/libc/src/__support/math/fromfp.h
new file mode 100644
index 0000000000000..837696dc942fd
--- /dev/null
+++ b/libc/src/__support/math/fromfp.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fromfp ------------------------*- 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_FROMFP_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FROMFP_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double fromfp(double x, int rnd, unsigned int width) {
+ return fputil::fromfp</*IsSigned=*/true>(x, rnd, width);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FROMFP_H
diff --git a/libc/src/__support/math/fromfpbf16.h b/libc/src/__support/math/fromfpbf16.h
new file mode 100644
index 0000000000000..61569a071e9f5
--- /dev/null
+++ b/libc/src/__support/math/fromfpbf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for fromfpbf16 --------------------*- 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_FROMFPBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FROMFPBF16_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 fromfpbf16(bfloat16 x, int rnd,
+ unsigned int width) {
+ return fputil::fromfp</*IsSigned=*/true>(x, rnd, width);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FROMFPBF16_H
diff --git a/libc/src/__support/math/fromfpf.h b/libc/src/__support/math/fromfpf.h
new file mode 100644
index 0000000000000..ca5d575dd9c0b
--- /dev/null
+++ b/libc/src/__support/math/fromfpf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fromfpf -----------------------*- 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_FROMFPF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FROMFPF_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float fromfpf(float x, int rnd, unsigned int width) {
+ return fputil::fromfp</*IsSigned=*/true>(x, rnd, width);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FROMFPF_H
diff --git a/libc/src/__support/math/fromfpf128.h b/libc/src/__support/math/fromfpf128.h
new file mode 100644
index 0000000000000..ea263ffd7e8fc
--- /dev/null
+++ b/libc/src/__support/math/fromfpf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for fromfpf128 --------------------*- 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_FROMFPF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FROMFPF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float128 fromfpf128(float128 x, int rnd,
+ unsigned int width) {
+ return fputil::fromfp</*IsSigned=*/true>(x, rnd, width);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FROMFPF128_H
diff --git a/libc/src/__support/math/fromfpf16.h b/libc/src/__support/math/fromfpf16.h
new file mode 100644
index 0000000000000..08ab6ffe90dba
--- /dev/null
+++ b/libc/src/__support/math/fromfpf16.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for fromfpf16 ---------------------*- 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_FROMFPF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FROMFPF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespac...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/195413
More information about the libc-commits
mailing list