[libc-commits] [libc] [libc] Use `rint` builtin for rounding on the GPU (PR #98345)

via libc-commits libc-commits at lists.llvm.org
Wed Jul 10 11:00:53 PDT 2024


================
@@ -17,6 +17,18 @@
 #include "x86_64/nearest_integer.h"
 #elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
 #include "aarch64/nearest_integer.h"
+#elif defined(LIBC_TARGET_ARCH_IS_GPU)
+
+namespace LIBC_NAMESPACE {
+namespace fputil {
+
+LIBC_INLINE float nearest_integer(float x) { return __builtin_rintf(x); }
----------------
lntue wrote:

Now I'm curious about the differences between `__builtin_round`, `__builtin_rint`, and `__builtin_roundeven` in terms of efficiency.  I assume in default rounding mode, all of them are the same.

OTOH, if I'm not mistaken, the `__builtin_rint`  will not return the nearest integer in other rounding modes, so `__builtin_round` or `__builtin_roundeven` should be used instead?

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


More information about the libc-commits mailing list