[libc][math][c++23] Add {nearbyint,rint,lrint,llrint,lround,llround}bf16 math functions (#153882)
This PR adds the following basic math functions for BFloat16 type along
with the tests:
- nearbyintbf16
- rintbf16
- lrintbf16
- llrintbf16
- lroundbf16
- llroundbf16
---------
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
GitOrigin-RevId: 60743358d15f19b89e3ef5daa1b28e7b1bef453e
diff --git a/config/baremetal/aarch64/entrypoints.txt b/config/baremetal/aarch64/entrypoints.txt
index c4ec03f..1784e10 100644
--- a/config/baremetal/aarch64/entrypoints.txt
+++ b/config/baremetal/aarch64/entrypoints.txt
@@ -785,16 +785,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/baremetal/arm/entrypoints.txt b/config/baremetal/arm/entrypoints.txt
index d9e173a..9a58ebd 100644
--- a/config/baremetal/arm/entrypoints.txt
+++ b/config/baremetal/arm/entrypoints.txt
@@ -788,16 +788,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/baremetal/riscv/entrypoints.txt b/config/baremetal/riscv/entrypoints.txt
index 9b0cf14..2422551 100644
--- a/config/baremetal/riscv/entrypoints.txt
+++ b/config/baremetal/riscv/entrypoints.txt
@@ -788,16 +788,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/darwin/aarch64/entrypoints.txt b/config/darwin/aarch64/entrypoints.txt
index 2a63485..a3e7aad 100644
--- a/config/darwin/aarch64/entrypoints.txt
+++ b/config/darwin/aarch64/entrypoints.txt
@@ -618,16 +618,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/darwin/x86_64/entrypoints.txt b/config/darwin/x86_64/entrypoints.txt
index 6a18d55..2343a3d 100644
--- a/config/darwin/x86_64/entrypoints.txt
+++ b/config/darwin/x86_64/entrypoints.txt
@@ -261,16 +261,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/gpu/amdgpu/entrypoints.txt b/config/gpu/amdgpu/entrypoints.txt
index 008f7c7..7b9ee44 100644
--- a/config/gpu/amdgpu/entrypoints.txt
+++ b/config/gpu/amdgpu/entrypoints.txt
@@ -644,16 +644,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/gpu/nvptx/entrypoints.txt b/config/gpu/nvptx/entrypoints.txt
index 7d36aa4..5b724a3 100644
--- a/config/gpu/nvptx/entrypoints.txt
+++ b/config/gpu/nvptx/entrypoints.txt
@@ -646,16 +646,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/linux/aarch64/entrypoints.txt b/config/linux/aarch64/entrypoints.txt
index d04a382..1f2c58c 100644
--- a/config/linux/aarch64/entrypoints.txt
+++ b/config/linux/aarch64/entrypoints.txt
@@ -873,16 +873,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/linux/arm/entrypoints.txt b/config/linux/arm/entrypoints.txt
index 865392a..daeeee5 100644
--- a/config/linux/arm/entrypoints.txt
+++ b/config/linux/arm/entrypoints.txt
@@ -488,16 +488,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/linux/riscv/entrypoints.txt b/config/linux/riscv/entrypoints.txt
index 207608c..3a42342 100644
--- a/config/linux/riscv/entrypoints.txt
+++ b/config/linux/riscv/entrypoints.txt
@@ -891,16 +891,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/linux/x86_64/entrypoints.txt b/config/linux/x86_64/entrypoints.txt
index 2ba2b68..fc52bf6 100644
--- a/config/linux/x86_64/entrypoints.txt
+++ b/config/linux/x86_64/entrypoints.txt
@@ -924,16 +924,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/config/windows/entrypoints.txt b/config/windows/entrypoints.txt
index 32a6a57..413a7a3 100644
--- a/config/windows/entrypoints.txt
+++ b/config/windows/entrypoints.txt
@@ -334,16 +334,22 @@
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.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
libc.src.math.nanbf16
+ libc.src.math.nearbyintbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.rintbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/docs/headers/math/index.rst b/docs/headers/math/index.rst
index 1481992..b0fd807 100644
--- a/docs/headers/math/index.rst
+++ b/docs/headers/math/index.rst
@@ -199,21 +199,21 @@
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| 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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| 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| | |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| | |check| | 7.12.11.3 | F.10.8.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
@@ -227,7 +227,7 @@
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| remquo | |check| | |check| | |check| | |check| | |check| | | 7.12.10.3 | F.10.7.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| rint | |check| | |check| | |check| | |check| | |check| | | 7.12.9.4 | F.10.6.4 |
+| rint | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.4 | F.10.6.4 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| round | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.6 | F.10.6.6 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
diff --git a/src/__support/FPUtil/bfloat16.h b/src/__support/FPUtil/bfloat16.h
index f74fa0c..ba97b42 100644
--- a/src/__support/FPUtil/bfloat16.h
+++ b/src/__support/FPUtil/bfloat16.h
@@ -59,6 +59,11 @@
return cpp::bit_cast<float>(x_bits);
}
+ template <typename T, cpp::enable_if_t<cpp::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/src/math/CMakeLists.txt b/src/math/CMakeLists.txt
index a90c5eb..2fe3d19 100644
--- a/src/math/CMakeLists.txt
+++ b/src/math/CMakeLists.txt
@@ -392,24 +392,28 @@
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)
@@ -429,6 +433,7 @@
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)
@@ -479,6 +484,7 @@
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/src/math/generic/CMakeLists.txt b/src/math/generic/CMakeLists.txt
index 3f13066..1a61ccb 100644
--- a/src/math/generic/CMakeLists.txt
+++ b/src/math/generic/CMakeLists.txt
@@ -1013,6 +1013,19 @@
)
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
llround.cpp
@@ -1065,6 +1078,19 @@
)
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
rint.cpp
@@ -1125,6 +1151,21 @@
)
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
lrint.cpp
@@ -1177,6 +1218,19 @@
)
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
llrint.cpp
@@ -1229,6 +1283,17 @@
)
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
nearbyint.cpp
@@ -1281,6 +1346,19 @@
)
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
erff.cpp
diff --git a/src/math/generic/llrintbf16.cpp b/src/math/generic/llrintbf16.cpp
new file mode 100644
index 0000000..ec85454
--- /dev/null
+++ b/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/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(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/src/math/generic/llroundbf16.cpp b/src/math/generic/llroundbf16.cpp
new file mode 100644
index 0000000..2497b6b
--- /dev/null
+++ b/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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/llroundbf16.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(long long, llroundbf16, (bfloat16 x)) {
+ return fputil::round_to_signed_integer<bfloat16, long long>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/src/math/generic/lrintbf16.cpp b/src/math/generic/lrintbf16.cpp
new file mode 100644
index 0000000..4b37890
--- /dev/null
+++ b/src/math/generic/lrintbf16.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of lrintbf16 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/lrintbf16.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(long, lrintbf16, (bfloat16 x)) {
+ return fputil::round_to_signed_integer_using_current_rounding_mode<bfloat16,
+ long>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/src/math/generic/lroundbf16.cpp b/src/math/generic/lroundbf16.cpp
new file mode 100644
index 0000000..89095d1
--- /dev/null
+++ b/src/math/generic/lroundbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of lroundbf16 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/lroundbf16.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(long, lroundbf16, (bfloat16 x)) {
+ return fputil::round_to_signed_integer<bfloat16, long>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/src/math/generic/nearbyintbf16.cpp b/src/math/generic/nearbyintbf16.cpp
new file mode 100644
index 0000000..a639199
--- /dev/null
+++ b/src/math/generic/nearbyintbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of nearbyintbf16 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/nearbyintbf16.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, nearbyintbf16, (bfloat16 x)) {
+ return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/src/math/generic/rintbf16.cpp b/src/math/generic/rintbf16.cpp
new file mode 100644
index 0000000..2ffe16a
--- /dev/null
+++ b/src/math/generic/rintbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of rintbf16 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/rintbf16.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, rintbf16, (bfloat16 x)) {
+ return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/src/math/llrintbf16.h b/src/math/llrintbf16.h
new file mode 100644
index 0000000..23402a5
--- /dev/null
+++ b/src/math/llrintbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for llrintbf16 --------------------*- 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_LLRINTBF16_H
+#define LLVM_LIBC_SRC_MATH_LLRINTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long long llrintbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_LLRINTBF16_H
diff --git a/src/math/llroundbf16.h b/src/math/llroundbf16.h
new file mode 100644
index 0000000..69878e4
--- /dev/null
+++ b/src/math/llroundbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for llroundbf16 -------------------*- 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_LLROUNDBF16_H
+#define LLVM_LIBC_SRC_MATH_LLROUNDBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long long llroundbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_LLROUNDBF16_H
diff --git a/src/math/lrintbf16.h b/src/math/lrintbf16.h
new file mode 100644
index 0000000..ec24472
--- /dev/null
+++ b/src/math/lrintbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for lrintbf16 ---------------------*- 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_LRINTBF16_H
+#define LLVM_LIBC_SRC_MATH_LRINTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long lrintbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_LRINTBF16_H
diff --git a/src/math/lroundbf16.h b/src/math/lroundbf16.h
new file mode 100644
index 0000000..c08db7a
--- /dev/null
+++ b/src/math/lroundbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for lroundbf16 --------------------*- 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_LROUNDBF16_H
+#define LLVM_LIBC_SRC_MATH_LROUNDBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long lroundbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_LROUNDBF16_H
diff --git a/src/math/nearbyintbf16.h b/src/math/nearbyintbf16.h
new file mode 100644
index 0000000..bc7eb3b
--- /dev/null
+++ b/src/math/nearbyintbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for nearbyintbf16 -----------------*- 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_NEARBYINTBF16_H
+#define LLVM_LIBC_SRC_MATH_NEARBYINTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 nearbyintbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_NEARBYINTBF16_H
diff --git a/src/math/rintbf16.h b/src/math/rintbf16.h
new file mode 100644
index 0000000..aae1541
--- /dev/null
+++ b/src/math/rintbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for rintbf16 ----------------------*- 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_RINTBF16_H
+#define LLVM_LIBC_SRC_MATH_RINTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 rintbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_RINTBF16_H
diff --git a/test/src/math/CMakeLists.txt b/test/src/math/CMakeLists.txt
index e15df14..8e24c5d 100644
--- a/test/src/math/CMakeLists.txt
+++ b/test/src/math/CMakeLists.txt
@@ -669,6 +669,25 @@
)
add_fp_unittest(
+ lroundbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ lroundbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.errno.errno
+ libc.src.math.lroundbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
llround_test
NEED_MPFR
SUITE
@@ -741,6 +760,25 @@
)
add_fp_unittest(
+ llroundbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ llroundbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.errno.errno
+ libc.src.math.llroundbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
nearbyint_test
NEED_MPFR
SUITE
@@ -801,6 +839,22 @@
)
add_fp_unittest(
+ nearbyintbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ nearbyintbf16_test.cpp
+ HDRS
+ NearbyIntTest.h
+ DEPENDS
+ libc.src.math.nearbyintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.CPP.array
+ libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
rint_test
NEED_MPFR
SUITE
@@ -869,6 +923,24 @@
)
add_fp_unittest(
+ rintbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ rintbf16_test.cpp
+ HDRS
+ RIntTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.math.rintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
lrint_test
NEED_MPFR
SUITE
@@ -933,6 +1005,23 @@
)
add_fp_unittest(
+ lrintbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ lrintbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.math.lrintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
llrint_test
NEED_MPFR
SUITE
@@ -997,6 +1086,23 @@
)
add_fp_unittest(
+ llrintbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ llrintbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.math.llrintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
exp_test
NEED_MPFR
SUITE
diff --git a/test/src/math/RoundToIntegerTest.h b/test/src/math/RoundToIntegerTest.h
index 6af9cfe..e5e9386 100644
--- a/test/src/math/RoundToIntegerTest.h
+++ b/test/src/math/RoundToIntegerTest.h
@@ -127,8 +127,8 @@
test_one_input(func, FloatType(-1.0), IntType(-1), false);
test_one_input(func, FloatType(10.0), IntType(10), false);
test_one_input(func, FloatType(-10.0), IntType(-10), false);
- test_one_input(func, FloatType(1234.0), IntType(1234), false);
- test_one_input(func, FloatType(-1234.0), IntType(-1234), false);
+ test_one_input(func, FloatType(1232.0), IntType(1232), false);
+ test_one_input(func, FloatType(-1232.0), IntType(-1232), false);
// The rest of this function compares with an equivalent MPFR function
// which rounds floating point numbers to long values. There is no MPFR
diff --git a/test/src/math/llrintbf16_test.cpp b/test/src/math/llrintbf16_test.cpp
new file mode 100644
index 0000000..e841e62
--- /dev/null
+++ b/test/src/math/llrintbf16_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for llrintbf16 ------------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/llrintbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long long,
+ LIBC_NAMESPACE::llrintbf16)
diff --git a/test/src/math/llroundbf16_test.cpp b/test/src/math/llroundbf16_test.cpp
new file mode 100644
index 0000000..c3b7ea4
--- /dev/null
+++ b/test/src/math/llroundbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for llroundbf16 -----------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/llroundbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long long, LIBC_NAMESPACE::llroundbf16)
diff --git a/test/src/math/lrintbf16_test.cpp b/test/src/math/lrintbf16_test.cpp
new file mode 100644
index 0000000..65a5633
--- /dev/null
+++ b/test/src/math/lrintbf16_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for lrintbf16 -------------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/lrintbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long,
+ LIBC_NAMESPACE::lrintbf16)
diff --git a/test/src/math/lroundbf16_test.cpp b/test/src/math/lroundbf16_test.cpp
new file mode 100644
index 0000000..2f2b7b1
--- /dev/null
+++ b/test/src/math/lroundbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for lroundbf16 ------------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/lroundbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long, LIBC_NAMESPACE::lroundbf16)
diff --git a/test/src/math/nearbyintbf16_test.cpp b/test/src/math/nearbyintbf16_test.cpp
new file mode 100644
index 0000000..2d64fc5
--- /dev/null
+++ b/test/src/math/nearbyintbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for nearbyintbf16 ---------------------------------------===//
+//
+// 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 "NearbyIntTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/nearbyintbf16.h"
+
+LIST_NEARBYINT_TESTS(bfloat16, LIBC_NAMESPACE::nearbyintbf16)
diff --git a/test/src/math/rintbf16_test.cpp b/test/src/math/rintbf16_test.cpp
new file mode 100644
index 0000000..c78dcf6
--- /dev/null
+++ b/test/src/math/rintbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for rintbf16 --------------------------------------------===//
+//
+// 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 "RIntTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/rintbf16.h"
+
+LIST_RINT_TESTS(bfloat16, LIBC_NAMESPACE::rintbf16)
diff --git a/test/src/math/smoke/CMakeLists.txt b/test/src/math/smoke/CMakeLists.txt
index 65da119..929d7b0 100644
--- a/test/src/math/smoke/CMakeLists.txt
+++ b/test/src/math/smoke/CMakeLists.txt
@@ -937,6 +937,23 @@
)
add_fp_unittest(
+ lroundbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ lroundbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.lroundbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
llround_test
SUITE
libc-math-smoke-tests
@@ -1017,6 +1034,23 @@
)
add_fp_unittest(
+ llroundbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ llroundbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.llroundbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
rint_test
SUITE
libc-math-smoke-tests
@@ -1087,6 +1121,21 @@
)
add_fp_unittest(
+ rintbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ rintbf16_test.cpp
+ HDRS
+ RIntTest.h
+ DEPENDS
+ libc.src.math.rintbf16
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
lrint_test
SUITE
libc-math-smoke-tests
@@ -1167,6 +1216,23 @@
)
add_fp_unittest(
+ lrintbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ lrintbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.lrintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
llrint_test
SUITE
libc-math-smoke-tests
@@ -1247,6 +1313,23 @@
)
add_fp_unittest(
+ llrintbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ llrintbf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.errno.errno
+ libc.src.math.llrintbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
exp_test
SUITE
libc-math-smoke-tests
@@ -3597,6 +3680,20 @@
)
add_fp_unittest(
+ nearbyintbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ nearbyintbf16_test.cpp
+ HDRS
+ NearbyIntTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.math.nearbyintbf16
+ libc.src.__support.FPUtil.bfloat16
+)
+
+add_fp_unittest(
nextafter_test
SUITE
libc-math-smoke-tests
diff --git a/test/src/math/smoke/RoundToIntegerTest.h b/test/src/math/smoke/RoundToIntegerTest.h
index 2b460ae..6866e91 100644
--- a/test/src/math/smoke/RoundToIntegerTest.h
+++ b/test/src/math/smoke/RoundToIntegerTest.h
@@ -97,8 +97,8 @@
test_one_input(func, F(-1.0), I(-1), false);
test_one_input(func, F(10.0), I(10), false);
test_one_input(func, F(-10.0), I(-10), false);
- test_one_input(func, F(1234.0), I(1234), false);
- test_one_input(func, F(-1234.0), I(-1234), false);
+ test_one_input(func, F(1232.0), I(1232), false);
+ test_one_input(func, F(-1232.0), I(-1232), false);
}
void testRoundNumbers(RoundToIntegerFunc func) {
@@ -124,7 +124,7 @@
continue;
// All subnormal numbers should round to zero.
if (TestModes) {
- if (x > 0) {
+ if (x > zero) {
LIBC_NAMESPACE::fputil::set_round(FE_UPWARD);
test_one_input(func, x, I(1), false);
LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD);
diff --git a/test/src/math/smoke/llrintbf16_test.cpp b/test/src/math/smoke/llrintbf16_test.cpp
new file mode 100644
index 0000000..e841e62
--- /dev/null
+++ b/test/src/math/smoke/llrintbf16_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for llrintbf16 ------------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/llrintbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long long,
+ LIBC_NAMESPACE::llrintbf16)
diff --git a/test/src/math/smoke/llroundbf16_test.cpp b/test/src/math/smoke/llroundbf16_test.cpp
new file mode 100644
index 0000000..c3b7ea4
--- /dev/null
+++ b/test/src/math/smoke/llroundbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for llroundbf16 -----------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/llroundbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long long, LIBC_NAMESPACE::llroundbf16)
diff --git a/test/src/math/smoke/lrintbf16_test.cpp b/test/src/math/smoke/lrintbf16_test.cpp
new file mode 100644
index 0000000..65a5633
--- /dev/null
+++ b/test/src/math/smoke/lrintbf16_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for lrintbf16 -------------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/lrintbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long,
+ LIBC_NAMESPACE::lrintbf16)
diff --git a/test/src/math/smoke/lroundbf16_test.cpp b/test/src/math/smoke/lroundbf16_test.cpp
new file mode 100644
index 0000000..2f2b7b1
--- /dev/null
+++ b/test/src/math/smoke/lroundbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for lroundbf16 ------------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/lroundbf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long, LIBC_NAMESPACE::lroundbf16)
diff --git a/test/src/math/smoke/nearbyintbf16_test.cpp b/test/src/math/smoke/nearbyintbf16_test.cpp
new file mode 100644
index 0000000..2d64fc5
--- /dev/null
+++ b/test/src/math/smoke/nearbyintbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for nearbyintbf16 ---------------------------------------===//
+//
+// 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 "NearbyIntTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/nearbyintbf16.h"
+
+LIST_NEARBYINT_TESTS(bfloat16, LIBC_NAMESPACE::nearbyintbf16)
diff --git a/test/src/math/smoke/rintbf16_test.cpp b/test/src/math/smoke/rintbf16_test.cpp
new file mode 100644
index 0000000..c78dcf6
--- /dev/null
+++ b/test/src/math/smoke/rintbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for rintbf16 --------------------------------------------===//
+//
+// 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 "RIntTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/rintbf16.h"
+
+LIST_RINT_TESTS(bfloat16, LIBC_NAMESPACE::rintbf16)
diff --git a/utils/MPFRWrapper/MPFRUtils.cpp b/utils/MPFRWrapper/MPFRUtils.cpp
index ff3bebb..2155f32 100644
--- a/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/utils/MPFRWrapper/MPFRUtils.cpp
@@ -791,6 +791,8 @@
template bool round_to_long<float128>(float128, long &);
#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bool round_to_long<bfloat16>(bfloat16, long &);
+
template <typename T> bool round_to_long(T x, RoundingMode mode, long &result) {
MPFRNumber mpfr(x);
return mpfr.round_to_long(get_mpfr_rounding_mode(mode), result);
@@ -808,6 +810,8 @@
template bool round_to_long<float128>(float128, RoundingMode, long &);
#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bool round_to_long<bfloat16>(bfloat16, RoundingMode, long &);
+
template <typename T> T round(T x, RoundingMode mode) {
MPFRNumber mpfr(x);
MPFRNumber result = mpfr.rint(get_mpfr_rounding_mode(mode));
@@ -826,6 +830,8 @@
template float128 round<float128>(float128, RoundingMode);
#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bfloat16 round<bfloat16>(bfloat16, RoundingMode);
+
} // namespace mpfr
} // namespace testing
} // namespace LIBC_NAMESPACE_DECL