[libc-commits] [libc] [libc][libm][GPU ]Added `__builtin_logb` and `__builtin_logbf` to the GPU version of `libm` (PR #66000)
Anton Rydahl via libc-commits
libc-commits at lists.llvm.org
Mon Sep 11 12:27:56 PDT 2023
https://github.com/AntonRydahl created https://github.com/llvm/llvm-project/pull/66000:
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`.
>From 2b3e23c63262037585343136decc8774bf0fd8fc Mon Sep 17 00:00:00 2001
From: antonrydahl <rydahl2610 at gmail.com>
Date: Mon, 11 Sep 2023 12:21:14 -0700
Subject: [PATCH] Added __builtin_logb and __builtin_logbf to the GPU version
of libm
---
libc/config/gpu/entrypoints.txt | 2 ++
libc/src/math/gpu/CMakeLists.txt | 20 ++++++++++++++++++++
libc/src/math/gpu/logb.cpp | 16 ++++++++++++++++
libc/src/math/gpu/logbf.cpp | 17 +++++++++++++++++
4 files changed, 55 insertions(+)
create mode 100644 libc/src/math/gpu/logb.cpp
create mode 100644 libc/src/math/gpu/logbf.cpp
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
More information about the libc-commits
mailing list