[libc-commits] [libc] [libc][math][c++23] Add {, u}fromfp{, x}bf16 math functions (PR #153992)

via libc-commits libc-commits at lists.llvm.org
Sat Aug 16 20:20:39 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-risc-v

Author: Krishna Pandey (krishna2803)

<details>
<summary>Changes</summary>

This PR adds the following basic math functions for BFloat16 type along with the tests:
- fromfpbf16
- fromfpxbf16
- ufromfpbf16
- ufromfpxbf16

---

Patch is 49.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/153992.diff


32 Files Affected:

- (modified) libc/config/baremetal/aarch64/entrypoints.txt (+4) 
- (modified) libc/config/baremetal/arm/entrypoints.txt (+4) 
- (modified) libc/config/baremetal/riscv/entrypoints.txt (+4) 
- (modified) libc/config/darwin/aarch64/entrypoints.txt (+4) 
- (modified) libc/config/darwin/x86_64/entrypoints.txt (+4-1) 
- (modified) libc/config/gpu/amdgpu/entrypoints.txt (+4) 
- (modified) libc/config/gpu/nvptx/entrypoints.txt (+4) 
- (modified) libc/config/linux/aarch64/entrypoints.txt (+4) 
- (modified) libc/config/linux/arm/entrypoints.txt (+4) 
- (modified) libc/config/linux/riscv/entrypoints.txt (+4) 
- (modified) libc/config/linux/x86_64/entrypoints.txt (+4) 
- (modified) libc/config/windows/entrypoints.txt (+4) 
- (modified) libc/docs/headers/math/index.rst (+4-4) 
- (modified) libc/src/math/CMakeLists.txt (+4) 
- (added) libc/src/math/fromfpbf16.h (+21) 
- (added) libc/src/math/fromfpxbf16.h (+21) 
- (modified) libc/src/math/generic/CMakeLists.txt (+56) 
- (added) libc/src/math/generic/fromfpbf16.cpp (+22) 
- (added) libc/src/math/generic/fromfpxbf16.cpp (+22) 
- (added) libc/src/math/generic/ufromfpbf16.cpp (+22) 
- (added) libc/src/math/generic/ufromfpxbf16.cpp (+22) 
- (added) libc/src/math/ufromfpbf16.h (+21) 
- (added) libc/src/math/ufromfpxbf16.h (+21) 
- (modified) libc/test/src/math/smoke/CMakeLists.txt (+53) 
- (modified) libc/test/src/math/smoke/FromfpTest.h (+26-28) 
- (modified) libc/test/src/math/smoke/FromfpxTest.h (+30-30) 
- (modified) libc/test/src/math/smoke/UfromfpTest.h (+12-14) 
- (modified) libc/test/src/math/smoke/UfromfpxTest.h (+14-14) 
- (added) libc/test/src/math/smoke/fromfpbf16_test.cpp (+14) 
- (added) libc/test/src/math/smoke/fromfpxbf16_test.cpp (+14) 
- (added) libc/test/src/math/smoke/ufromfpbf16_test.cpp (+14) 
- (added) libc/test/src/math/smoke/ufromfpxbf16_test.cpp (+14) 


``````````diff
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 00fd4675e7f09..c2710429b3cfd 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -785,9 +785,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 if(LIBC_TYPES_HAS_FLOAT128)
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 9a7800c0f9b86..6e5389d542f80 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -788,9 +788,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 if(LIBC_TYPES_HAS_FLOAT128)
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 34b400bdc52c5..76da24d2cc876 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -788,9 +788,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 if(LIBC_TYPES_HAS_FLOAT128)
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index d45ec3589c97e..5bfd6c863fabb 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -618,9 +618,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 if(LIBC_TYPES_HAS_FLOAT128)
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 1e12e9e167b73..27d214d06cd0b 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -261,10 +261,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
-
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 4b6f3337036aa..bc75956738e5a 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -644,9 +644,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index d24cc740d4234..c9688284df16c 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -645,9 +645,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index e71dc2ee0d02f..e42bbb14ec119 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -872,9 +872,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 if(LIBC_TYPES_HAS_FLOAT128)
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index ec01030c77d4f..60fc953c2b9f4 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -488,9 +488,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 54ea983d64839..1a03683d72e61 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -891,9 +891,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 if(LIBC_TYPES_HAS_FLOAT128)
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 1ee10e6d3cade..9b4946b883626 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -923,9 +923,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 if(LIBC_TYPES_HAS_FLOAT128)
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 37a2ee286010a..b97e893567038 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -334,9 +334,13 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.fromfpbf16
+  libc.src.math.fromfpxbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
+  libc.src.math.ufromfpbf16
+  libc.src.math.ufromfpxbf16
 )
 
 set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index add34d0e877fd..754c1a55cf449 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -181,9 +181,9 @@ Basic Operations
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 | frexp            | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.6.7               | F.10.3.7                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fromfp           | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.9.10              | F.10.6.10                  |
+| fromfp           | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.9.10              | F.10.6.10                  |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| fromfpx          | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.9.11              | F.10.6.11                  |
+| fromfpx          | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.9.11              | F.10.6.11                  |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 | fsub             | N/A              | |check|         | |check|                | N/A                  | |check|\*              | N/A                    | 7.12.14.2              | F.10.11                    |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
@@ -247,9 +247,9 @@ Basic Operations
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 | trunc            | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.9.9               | F.10.6.9                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ufromfp          | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.9.10              | F.10.6.10                  |
+| ufromfp          | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.9.10              | F.10.6.10                  |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ufromfpx         | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.9.11              | F.10.6.11                  |
+| ufromfpx         | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.9.11              | F.10.6.11                  |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 
 Higher Math Functions
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 8db5901afa9c0..f94120272ce66 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -312,12 +312,14 @@ add_math_entrypoint_object(fromfpf)
 add_math_entrypoint_object(fromfpl)
 add_math_entrypoint_object(fromfpf16)
 add_math_entrypoint_object(fromfpf128)
+add_math_entrypoint_object(fromfpbf16)
 
 add_math_entrypoint_object(fromfpx)
 add_math_entrypoint_object(fromfpxf)
 add_math_entrypoint_object(fromfpxl)
 add_math_entrypoint_object(fromfpxf16)
 add_math_entrypoint_object(fromfpxf128)
+add_math_entrypoint_object(fromfpxbf16)
 
 add_math_entrypoint_object(fsub)
 add_math_entrypoint_object(fsubl)
@@ -567,12 +569,14 @@ add_math_entrypoint_object(ufromfpf)
 add_math_entrypoint_object(ufromfpl)
 add_math_entrypoint_object(ufromfpf16)
 add_math_entrypoint_object(ufromfpf128)
+add_math_entrypoint_object(ufromfpbf16)
 
 add_math_entrypoint_object(ufromfpx)
 add_math_entrypoint_object(ufromfpxf)
 add_math_entrypoint_object(ufromfpxl)
 add_math_entrypoint_object(ufromfpxf16)
 add_math_entrypoint_object(ufromfpxf128)
+add_math_entrypoint_object(ufromfpxbf16)
 
 add_math_entrypoint_object(bf16add)
 add_math_entrypoint_object(bf16addf)
diff --git a/libc/src/math/fromfpbf16.h b/libc/src/math/fromfpbf16.h
new file mode 100644
index 0000000000000..bff991c6c1ed5
--- /dev/null
+++ b/libc/src/math/fromfpbf16.h
@@ -0,0 +1,21 @@
+//===-- 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_MATH_FROMFPBF16_H
+#define LLVM_LIBC_SRC_MATH_FROMFPBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 fromfpbf16(bfloat16 x, int rnd, unsigned int width);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FROMFPBF16_H
diff --git a/libc/src/math/fromfpxbf16.h b/libc/src/math/fromfpxbf16.h
new file mode 100644
index 0000000000000..e40d975617ef2
--- /dev/null
+++ b/libc/src/math/fromfpxbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for fromfpxbf16 -------------------*- 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_MATH_FROMFPXBF16_H
+#define LLVM_LIBC_SRC_MATH_FROMFPXBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 fromfpxbf16(bfloat16 x, int rnd, unsigned int width);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FROMFPXBF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 65e4839268443..1608bed87cb6b 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3745,6 +3745,20 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  fromfpbf16
+  SRCS
+    fromfpbf16.cpp
+  HDRS
+    ../fromfpbf16.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
+
 add_entrypoint_object(
   fromfpx
   SRCS
@@ -3797,6 +3811,20 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  fromfpxbf16
+  SRCS
+    fromfpxbf16.cpp
+  HDRS
+    ../fromfpxbf16.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
+
 add_entrypoint_object(
   ufromfp
   SRCS
@@ -3849,6 +3877,20 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  ufromfpbf16
+  SRCS
+    ufromfpbf16.cpp
+  HDRS
+    ../ufromfpbf16.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
+
 add_entrypoint_object(
   ufromfpx
   SRCS
@@ -3901,6 +3943,20 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  ufromfpxbf16
+  SRCS
+    ufromfpxbf16.cpp
+  HDRS
+    ../ufromfpxbf16.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
+
 add_entrypoint_object(
   coshf
   SRCS
diff --git a/libc/src/math/generic/fromfpbf16.cpp b/libc/src/math/generic/fromfpbf16.cpp
new file mode 100644
index 0000000000000..db1b8f18f6810
--- /dev/null
+++ b/libc/src/math/generic/fromfpbf16.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of fromfpbf16 function -----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/fromfpbf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, fromfpbf16,
+                   (bfloat16 x, int rnd, unsigned int width)) {
+  return fputil::fromfp</*IsSigned=*/true>(x, rnd, width);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fromfpxbf16.cpp b/libc/src/math/generic/fromfpxbf16.cpp
new file mode 100644
index 0000000000000..8c16c411265ab
--- /dev/null
+++ b/libc/src/math/generic/fromfpxbf16.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of fromfpxbf16 function ----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/fromfpxbf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, fromfpxbf16,
+                   (bfloat16 x, int rnd, unsigned int width)) {
+  return fputil::fromfpx</*IsSigned=*/true>(x, rnd, width);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ufromfpbf16.cpp b/libc/src/math/generic/ufromfpbf16.cpp
new file mode 100644
index 0000000000000..336771b695d97
--- /dev/null
+++ b/libc/src/math/generic/ufromfpbf16.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of ufromfpbf16 function ----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/ufromfpbf16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, ufromfpbf16,
+                   (bfloat16 x, int rnd, unsigned int width)) {
+  return fputil::fromfp</*IsSigned=*/f...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/153992


More information about the libc-commits mailing list