[libc-commits] [libc] [libc][libm][GPU ]Added `__builtin_logb` and `__builtin_logbf` to the GPU version of `libm` (PR #66000)
via libc-commits
libc-commits at lists.llvm.org
Mon Sep 11 12:28:33 PDT 2023
llvmbot wrote:
@llvm/pr-subscribers-libc
<details>
<summary>Changes</summary>
I found that the builtins for `logb` and `logbf` are correctly lowered on both AMD and NVIDIA GPUs, and therefore I think we should include them in the GPU version of `libm`.
--
Full diff: https://github.com/llvm/llvm-project/pull/66000.diff
4 Files Affected:
- (modified) libc/config/gpu/entrypoints.txt (+2)
- (modified) libc/src/math/gpu/CMakeLists.txt (+20)
- (added) libc/src/math/gpu/logb.cpp (+16)
- (added) libc/src/math/gpu/logbf.cpp (+17)
<pre>
diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index 0e314c60870c6ae..b082697403c3bac 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -157,6 +157,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.llrintf
libc.src.math.llround
libc.src.math.llroundf
+ libc.src.math.logb
+ libc.src.math.logbf
libc.src.math.pow
libc.src.math.powf
libc.src.math.sin
diff --git a/libc/src/math/gpu/CMakeLists.txt b/libc/src/math/gpu/CMakeLists.txt
index cee7b7d9db476f2..620b4e24aa1e11e 100644
--- a/libc/src/math/gpu/CMakeLists.txt
+++ b/libc/src/math/gpu/CMakeLists.txt
@@ -183,6 +183,26 @@ add_math_entrypoint_gpu_object(
-O2
)
+add_math_entrypoint_gpu_object(
+ logb
+ SRCS
+ logb.cpp
+ HDRS
+ ../logb.h
+ COMPILE_OPTIONS
+ -O2
+)
+
+add_math_entrypoint_gpu_object(
+ logbf
+ SRCS
+ logbf.cpp
+ HDRS
+ ../logbf.h
+ COMPILE_OPTIONS
+ -O2
+)
+
add_math_entrypoint_gpu_object(
modf
SRCS
diff --git a/libc/src/math/gpu/logb.cpp b/libc/src/math/gpu/logb.cpp
new file mode 100644
index 000000000000000..55c8c737aa9ed15
--- /dev/null
+++ b/libc/src/math/gpu/logb.cpp
@@ -0,0 +1,16 @@
+//===-- Implementation of the GPU logb 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/logb.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(double, logb, (double x)) { return __builtin_logb(x); }
+
+} // namespace __llvm_libc
diff --git a/libc/src/math/gpu/logbf.cpp b/libc/src/math/gpu/logbf.cpp
new file mode 100644
index 000000000000000..acb2625458009c7
--- /dev/null
+++ b/libc/src/math/gpu/logbf.cpp
@@ -0,0 +1,17 @@
+//===-- Implementation of the GPU logbf 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/logbf.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(float, logbf, (float x)) { return __builtin_logbf(x); }
+
+} // namespace __llvm_libc
</pre>
</details>
https://github.com/llvm/llvm-project/pull/66000
More information about the libc-commits
mailing list