[libc-commits] [libc] 5edb24e - [libc][GPU] Enable scalbn/ldexp, rand, remainder for SPIR-V (#242212)
via libc-commits
libc-commits at lists.llvm.org
Sun Nov 15 21:08:31 PST 2026
Author: jinge90
Date: 2026-11-16T13:08:26+08:00
New Revision: 5edb24e9f6f2e3703c0dc74e187de7dcf1d29165
URL: https://github.com/llvm/llvm-project/commit/5edb24e9f6f2e3703c0dc74e187de7dcf1d29165
DIFF: https://github.com/llvm/llvm-project/commit/5edb24e9f6f2e3703c0dc74e187de7dcf1d29165.diff
LOG: [libc][GPU] Enable scalbn/ldexp, rand, remainder for SPIR-V (#242212)
This PR is a follow up of
https://github.com/llvm/llvm-project/pull/236324 to fix more build
issues for SPIR-V compiler-rt builtin tests. "Undefined symbols" from
libc and libm still lead to a bunch of build failures such as rand,
srand, scalbn/f, remainder/f. Before the fix, building results:
Total Discovered Tests: 275
Unsupported: 125 (45.45%)
Passed : 128 (46.55%)
Failed : 22 (8.00%)
After the fix:
Total Discovered Tests: 275
Unsupported: 125 (45.45%)
Passed : 136 (49.45%)
Failed : 14 (5.09%)
8 more tests can build pass now.
All of the enabled functions are simple without RPC mechanism. For
srand, rand, scalbn and scalbnf, the exact same implementations have
been used in downstream compiler for SYCL and OpenMP offloading on Intel
GPU for years covering both Linux and Windows. The remainder/f aligns
with AMD and NV approach to use generic version and also verified on
Intel GPU + L0 for both Linux and Windows.
Signed-off-by: jinge90 <ge.jin at intel.com>
Added:
libc/src/math/spirv/CMakeLists.txt
libc/src/math/spirv/ldexp.cpp
libc/src/math/spirv/ldexpf.cpp
libc/src/math/spirv/scalbn.cpp
libc/src/math/spirv/scalbnf.cpp
Modified:
libc/config/gpu/spirv/entrypoints.txt
Removed:
################################################################################
diff --git a/libc/config/gpu/spirv/entrypoints.txt b/libc/config/gpu/spirv/entrypoints.txt
index 5b21d12c84af24..ea671c68b62a85 100644
--- a/libc/config/gpu/spirv/entrypoints.txt
+++ b/libc/config/gpu/spirv/entrypoints.txt
@@ -92,11 +92,19 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib.ldiv
libc.src.stdlib.llabs
libc.src.stdlib.lldiv
+ libc.src.stdlib.rand
+ libc.src.stdlib.srand
)
set(TARGET_LIBM_ENTRYPOINTS
# math.h entrypoints
+ libc.src.math.ldexp
+ libc.src.math.ldexpf
libc.src.math.logbf
+ libc.src.math.remainder
+ libc.src.math.remainderf
+ libc.src.math.scalbn
+ libc.src.math.scalbnf
# complex.h entrypoints
libc.src.complex.cabs
libc.src.complex.cabsf
diff --git a/libc/src/math/spirv/CMakeLists.txt b/libc/src/math/spirv/CMakeLists.txt
new file mode 100644
index 00000000000000..075624d181c9ad
--- /dev/null
+++ b/libc/src/math/spirv/CMakeLists.txt
@@ -0,0 +1,31 @@
+add_entrypoint_object(
+ ldexp
+ SRCS
+ ldexp.cpp
+ HDRS
+ ../ldexp.h
+)
+
+add_entrypoint_object(
+ ldexpf
+ SRCS
+ ldexpf.cpp
+ HDRS
+ ../ldexpf.h
+)
+
+add_entrypoint_object(
+ scalbn
+ SRCS
+ scalbn.cpp
+ HDRS
+ ../scalbn.h
+)
+
+add_entrypoint_object(
+ scalbnf
+ SRCS
+ scalbnf.cpp
+ HDRS
+ ../scalbnf.h
+)
diff --git a/libc/src/math/spirv/ldexp.cpp b/libc/src/math/spirv/ldexp.cpp
new file mode 100644
index 00000000000000..5b786a9b21e709
--- /dev/null
+++ b/libc/src/math/spirv/ldexp.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the ldexp function for GPU ----------------------===//
+//
+// 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/ldexp.h"
+#include "src/__support/common.h"
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(double, ldexp, (double x, int y)) {
+ return __builtin_ldexp(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/spirv/ldexpf.cpp b/libc/src/math/spirv/ldexpf.cpp
new file mode 100644
index 00000000000000..d3aa77fe592cbf
--- /dev/null
+++ b/libc/src/math/spirv/ldexpf.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the ldexpf function for GPU ---------------------===//
+//
+// 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/ldexpf.h"
+#include "src/__support/common.h"
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, ldexpf, (float x, int y)) {
+ return __builtin_ldexpf(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/spirv/scalbn.cpp b/libc/src/math/spirv/scalbn.cpp
new file mode 100644
index 00000000000000..fd3d0435369d68
--- /dev/null
+++ b/libc/src/math/spirv/scalbn.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the GPU scalbn 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/scalbn.h"
+#include "src/__support/common.h"
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(double, scalbn, (double x, int y)) {
+ return __builtin_ldexp(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/spirv/scalbnf.cpp b/libc/src/math/spirv/scalbnf.cpp
new file mode 100644
index 00000000000000..b5cb06f7bda0ab
--- /dev/null
+++ b/libc/src/math/spirv/scalbnf.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of the GPU scalbnf 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/scalbnf.h"
+#include "src/__support/common.h"
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, scalbnf, (float x, int y)) {
+ return __builtin_ldexpf(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
More information about the libc-commits
mailing list