[libc-commits] [libc] [libc][math][c++23] Add {nearbyint, rint, lrint, llrint, lround, llround}bf16 math functions (PR #153882)

via libc-commits libc-commits at lists.llvm.org
Fri Aug 15 14:26:58 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-backend-amdgpu

Author: Krishna Pandey (krishna2803)

<details>
<summary>Changes</summary>

This PR adds the following basic math functions for BFloat16 type along with the tests:
- nearbyintbf16
- rintbf16
- lrintbf16
- llrintbf16
- lroundbf16
- llroundbf16

---

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


45 Files Affected:

- (modified) libc/config/baremetal/aarch64/entrypoints.txt (+6) 
- (modified) libc/config/baremetal/arm/entrypoints.txt (+6) 
- (modified) libc/config/baremetal/riscv/entrypoints.txt (+6) 
- (modified) libc/config/darwin/aarch64/entrypoints.txt (+6) 
- (modified) libc/config/darwin/x86_64/entrypoints.txt (+6-1) 
- (modified) libc/config/gpu/amdgpu/entrypoints.txt (+6) 
- (modified) libc/config/gpu/nvptx/entrypoints.txt (+6) 
- (modified) libc/config/linux/aarch64/entrypoints.txt (+6) 
- (modified) libc/config/linux/arm/entrypoints.txt (+6) 
- (modified) libc/config/linux/riscv/entrypoints.txt (+6) 
- (modified) libc/config/linux/x86_64/entrypoints.txt (+6) 
- (modified) libc/config/windows/entrypoints.txt (+6) 
- (modified) libc/docs/headers/math/index.rst (+6-6) 
- (modified) libc/src/__support/FPUtil/bfloat16.h (+5) 
- (modified) libc/src/math/CMakeLists.txt (+6) 
- (modified) libc/src/math/generic/CMakeLists.txt (+78) 
- (added) libc/src/math/generic/llrintbf16.cpp (+23) 
- (added) libc/src/math/generic/llroundbf16.cpp (+21) 
- (added) libc/src/math/generic/lrintbf16.cpp (+22) 
- (added) libc/src/math/generic/lroundbf16.cpp (+21) 
- (added) libc/src/math/generic/nearbyintbf16.cpp (+21) 
- (added) libc/src/math/generic/rintbf16.cpp (+21) 
- (added) libc/src/math/llrintbf16.h (+21) 
- (added) libc/src/math/llroundbf16.h (+21) 
- (added) libc/src/math/lrintbf16.h (+21) 
- (added) libc/src/math/lroundbf16.h (+21) 
- (added) libc/src/math/nearbyintbf16.h (+21) 
- (added) libc/src/math/rintbf16.h (+21) 
- (modified) libc/test/src/math/CMakeLists.txt (+106) 
- (modified) libc/test/src/math/RoundToIntegerTest.h (+2-2) 
- (added) libc/test/src/math/llrintbf16_test.cpp (+15) 
- (added) libc/test/src/math/llroundbf16_test.cpp (+14) 
- (added) libc/test/src/math/lrintbf16_test.cpp (+14) 
- (added) libc/test/src/math/lroundbf16_test.cpp (+14) 
- (added) libc/test/src/math/nearbyintbf16_test.cpp (+15) 
- (added) libc/test/src/math/rintbf16_test.cpp (+14) 
- (modified) libc/test/src/math/smoke/CMakeLists.txt (+97) 
- (modified) libc/test/src/math/smoke/RoundToIntegerTest.h (+3-3) 
- (added) libc/test/src/math/smoke/llrintbf16_test.cpp (+15) 
- (added) libc/test/src/math/smoke/llroundbf16_test.cpp (+14) 
- (added) libc/test/src/math/smoke/lrintbf16_test.cpp (+14) 
- (added) libc/test/src/math/smoke/lroundbf16_test.cpp (+14) 
- (added) libc/test/src/math/smoke/nearbyintbf16_test.cpp (+14) 
- (added) libc/test/src/math/smoke/rintbf16_test.cpp (+14) 
- (modified) libc/utils/MPFRWrapper/MPFRUtils.cpp (+6) 


``````````diff
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 00fd4675e7f09..aa2ce680c0d39 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -785,6 +785,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 9a7800c0f9b86..81a2aed5cdada 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -788,6 +788,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 34b400bdc52c5..6fd2762a515c3 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -788,6 +788,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index d45ec3589c97e..398d817655a88 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -618,6 +618,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 1e12e9e167b73..e17549f4f51bd 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -261,7 +261,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
-
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 4b6f3337036aa..b10aa2e9ca128 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -644,6 +644,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index d24cc740d4234..59f14dddec000 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -645,6 +645,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index e71dc2ee0d02f..05e91d63f540a 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -872,6 +872,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index ec01030c77d4f..6f2f4c0f9e1ee 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -488,6 +488,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 54ea983d64839..e853dfa52e95c 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -891,6 +891,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 1ee10e6d3cade..89045ef70d3bb 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -923,6 +923,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 37a2ee286010a..a6c0db0e74611 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -334,6 +334,12 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.fminimum_magbf16
   libc.src.math.fminimum_mag_numbf16
   libc.src.math.fminimum_numbf16
+  libc.src.math.llrintbf16
+  libc.src.math.llroundbf16
+  libc.src.math.lrintbf16
+  libc.src.math.lroundbf16
+  libc.src.math.nearbyintbf16
+  libc.src.math.rintbf16
   libc.src.math.roundbf16
   libc.src.math.roundevenbf16
   libc.src.math.truncbf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index add34d0e877fd..bd3ae3023f372 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -199,21 +199,21 @@ Basic Operations
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 | llogb            | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.6.10              | F.10.3.10                  |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| llrint           | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.9.5               | F.10.6.5                   |
+| llrint           | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.9.5               | F.10.6.5                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| llround          | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.9.7               | F.10.6.7                   |
+| llround          | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.9.7               | F.10.6.7                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| logb             | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.6.17              | F.10.3.17                  |
+| logb             | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.6.17              | F.10.3.17                  |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| lrint            | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.9.5               | F.10.6.5                   |
+| lrint            | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.9.5               | F.10.6.5                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| lround           | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.9.7               | F.10.6.7                   |
+| lround           | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.9.7               | F.10.6.7                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 | modf             | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.6.18              | F.10.3.18                  |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 | nan              | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.11.2              | F.10.8.2                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| nearbyint        | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.9.3               | F.10.6.3                   |
+| nearbyint        | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.9.3               | F.10.6.3                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 | nextafter        | |check|          | |check|         | |check|                | |check|              | |check|                |                        | 7.12.11.3              | F.10.8.3                   |
 +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index 3fab2b80317de..ea269a45767ee 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -61,6 +61,11 @@ struct BFloat16 {
     return cpp::bit_cast<float>(x_bits);
   }
 
+  template <typename T, cpp::enable_if_t<std::is_integral_v<T>, int> = 0>
+  LIBC_INLINE constexpr explicit operator T() const {
+    return static_cast<T>(static_cast<float>(*this));
+  }
+
   LIBC_INLINE bool operator==(BFloat16 other) const {
     return fputil::equals(*this, other);
   }
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 8db5901afa9c0..f482ace6e197a 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -387,24 +387,28 @@ add_math_entrypoint_object(llrintf)
 add_math_entrypoint_object(llrintl)
 add_math_entrypoint_object(llrintf16)
 add_math_entrypoint_object(llrintf128)
+add_math_entrypoint_object(llrintbf16)
 
 add_math_entrypoint_object(llround)
 add_math_entrypoint_object(llroundf)
 add_math_entrypoint_object(llroundl)
 add_math_entrypoint_object(llroundf16)
 add_math_entrypoint_object(llroundf128)
+add_math_entrypoint_object(llroundbf16)
 
 add_math_entrypoint_object(lrint)
 add_math_entrypoint_object(lrintf)
 add_math_entrypoint_object(lrintl)
 add_math_entrypoint_object(lrintf16)
 add_math_entrypoint_object(lrintf128)
+add_math_entrypoint_object(lrintbf16)
 
 add_math_entrypoint_object(lround)
 add_math_entrypoint_object(lroundf)
 add_math_entrypoint_object(lroundl)
 add_math_entrypoint_object(lroundf16)
 add_math_entrypoint_object(lroundf128)
+add_math_entrypoint_object(lroundbf16)
 
 add_math_entrypoint_object(modf)
 add_math_entrypoint_object(modff)
@@ -423,6 +427,7 @@ add_math_entrypoint_object(nearbyintf)
 add_math_entrypoint_object(nearbyintl)
 add_math_entrypoint_object(nearbyintf16)
 add_math_entrypoint_object(nearbyintf128)
+add_math_entrypoint_object(nearbyintbf16)
 
 add_math_entrypoint_object(nextafter)
 add_math_entrypoint_object(nextafterf)
@@ -469,6 +474,7 @@ add_math_entrypoint_object(rintf)
 add_math_entrypoint_object(rintl)
 add_math_entrypoint_object(rintf16)
 add_math_entrypoint_object(rintf128)
+add_math_entrypoint_object(rintbf16)
 
 add_math_entrypoint_object(round)
 add_math_entrypoint_object(roundf)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 65e4839268443..3baf28d2f04be 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1024,6 +1024,19 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  lroundbf16
+  SRCS
+    lroundbf16.cpp
+  HDRS
+    ../lroundf16.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
 add_entrypoint_object(
   llround
   SRCS
@@ -1076,6 +1089,19 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  llroundbf16
+  SRCS
+    llroundbf16.cpp
+  HDRS
+    ../llroundf16.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
 add_entrypoint_object(
   rint
   SRCS
@@ -1136,6 +1162,21 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  rintbf16
+  SRCS
+    rintbf16.cpp
+  HDRS
+    ../rintbf16.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+  FLAGS
+    ROUND_OPT
+)
+
 add_entrypoint_object(
   lrint
   SRCS
@@ -1188,6 +1229,19 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  lrintbf16
+  SRCS
+    lrintbf16.cpp
+  HDRS
+    ../lrintbf16.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
 add_entrypoint_object(
   llrint
   SRCS
@@ -1240,6 +1294,17 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  llrintbf16
+  SRCS
+    llrintbf16.cpp
+  HDRS
+    ../llrintbf16.h
+  DEPENDS
+    libc.src.__support.macros.properties.types
+    libc.src.__support.FPUtil.nearest_integer_operations
+)
+
 add_entrypoint_object(
   nearbyint
   SRCS
@@ -1292,6 +1357,19 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.nearest_integer_operations
 )
 
+add_entrypoint_object(
+  nearbyintbf16
+  SRCS
+    nearbyintbf16.cpp
+  HDRS
+    ../nearbyintbf16.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
 add_entrypoint_object(
   erff
   SRCS
diff --git a/libc/src/math/generic/llrintbf16.cpp b/libc/src/math/generic/llrintbf16.cpp
new file mode 100644
index 0000000000000..acf4f8574356d
--- /dev/null
+++ b/libc/src/math/generic/llrintbf16.cpp
@@ -0,0 +1,23 @@
+//===-- Implementation of llrintbf16 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/llrintbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(long long, llrintbf16, (bfloat16 x)) {
+  return fputil::round_to_signed_integer_using_current_rounding_mode<bfloat16,
+                                                                     long long>(
+      x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/llroundbf16.cpp b/libc/src/math/generic/llroundbf16.cpp
new file mode 100644
index 0000000000000..ffbf34721f8ed
--- /dev/null
+++ b/libc/src/math/generic/llroundbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of llroundbf16 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
+//
+//===----...
[truncated]

``````````

</details>


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


More information about the libc-commits mailing list