Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc][libm][GPU ]Added __builtin_logb and __builtin_logbf to the GPU version of libm #66000

Closed
wants to merge 1 commit into from

Conversation

AntonRydahl
Copy link
Contributor

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.

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 11, 2023

@llvm/pr-subscribers-libc

Changes

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)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants