[libclc] [libclc] Move native_(exp10|powr|tan) to CLC library (PR #134080)
Fraser Cormack via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 2 06:15:59 PDT 2025
https://github.com/frasercrmck created https://github.com/llvm/llvm-project/pull/134080
These are the three remaining native builtins not yet ported.
There are elementwise versions of exp10 and tan which correspond to the intrinsics, which may be preferable to the current versions which route through other native builtins. Those could be changed in a follow-up if desired.
>From 3900e2be9ab46ac316073043b4a9e25c3d55cabc Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Wed, 2 Apr 2025 14:10:30 +0100
Subject: [PATCH] [libclc] Move native_(exp10|powr|tan) to CLC library
These are the three remaining native builtins not yet ported.
There are elementwise versions of exp10 and tan which correspond to the
intrinsics, which may be preferable to the current versions which route
through other native builtins. Those could be changed in a follow-up if
desired.
---
libclc/CMakeLists.txt | 4 +++-
.../clc/include/clc/math/clc_native_exp10.h | 22 +++++++++++++++++++
libclc/clc/include/clc/math/clc_native_powr.h | 22 +++++++++++++++++++
libclc/clc/include/clc/math/clc_native_tan.h | 22 +++++++++++++++++++
libclc/clc/lib/generic/SOURCES | 3 +++
.../clc/lib/generic/math/clc_native_exp10.cl | 16 ++++++++++++++
.../lib/generic/math/clc_native_exp10.inc} | 4 ++--
.../clc/lib/generic/math/clc_native_powr.cl | 16 ++++++++++++++
.../lib/generic/math/clc_native_powr.inc} | 5 +++--
libclc/clc/lib/generic/math/clc_native_tan.cl | 16 ++++++++++++++
.../lib/generic/math/clc_native_tan.inc} | 4 ++--
.../generic/include/clc/math/native_divide.h | 2 +-
libclc/generic/include/clc/math/native_powr.h | 2 +-
libclc/generic/lib/math/native_exp10.cl | 5 ++++-
libclc/generic/lib/math/native_powr.cl | 5 ++++-
libclc/generic/lib/math/native_tan.cl | 5 ++++-
16 files changed, 141 insertions(+), 12 deletions(-)
create mode 100644 libclc/clc/include/clc/math/clc_native_exp10.h
create mode 100644 libclc/clc/include/clc/math/clc_native_powr.h
create mode 100644 libclc/clc/include/clc/math/clc_native_tan.h
create mode 100644 libclc/clc/lib/generic/math/clc_native_exp10.cl
rename libclc/{generic/lib/math/native_exp10.inc => clc/lib/generic/math/clc_native_exp10.inc} (75%)
create mode 100644 libclc/clc/lib/generic/math/clc_native_powr.cl
rename libclc/{generic/lib/math/native_powr.inc => clc/lib/generic/math/clc_native_powr.inc} (69%)
create mode 100644 libclc/clc/lib/generic/math/clc_native_tan.cl
rename libclc/{generic/lib/math/native_tan.inc => clc/lib/generic/math/clc_native_tan.inc} (73%)
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index d4753b22ed01c..dbbc29261d3b5 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -266,20 +266,22 @@ set_source_files_properties(
# CLC builtins
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_cos.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_divide.cl
+ ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp10.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp2.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log10.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log2.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log.cl
+ ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_powr.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_recip.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_rsqrt.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sin.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sqrt.cl
+ ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_tan.cl
# Target-specific CLC builtins
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_exp2.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_exp.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_log10.cl
- # Target-specific OpenCL builtins
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/r600/math/clc_native_rsqrt.cl
# OpenCL builtins
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_cos.cl
diff --git a/libclc/clc/include/clc/math/clc_native_exp10.h b/libclc/clc/include/clc/math/clc_native_exp10.h
new file mode 100644
index 0000000000000..302482d670cc1
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_native_exp10.h
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_MATH_CLC_NATIVE_EXP10_H__
+#define __CLC_MATH_CLC_NATIVE_EXP10_H__
+
+#define __FLOAT_ONLY
+#define __CLC_FUNCTION __clc_native_exp10
+#define __CLC_BODY <clc/shared/unary_decl.inc>
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+#undef __FLOAT_ONLY
+
+#endif // __CLC_MATH_CLC_NATIVE_EXP10_H__
diff --git a/libclc/clc/include/clc/math/clc_native_powr.h b/libclc/clc/include/clc/math/clc_native_powr.h
new file mode 100644
index 0000000000000..55d409fffaab3
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_native_powr.h
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_MATH_CLC_NATIVE_POWR_H__
+#define __CLC_MATH_CLC_NATIVE_POWR_H__
+
+#define __FLOAT_ONLY
+#define __CLC_FUNCTION __clc_native_powr
+#define __CLC_BODY <clc/shared/binary_decl.inc>
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+#undef __FLOAT_ONLY
+
+#endif // __CLC_MATH_CLC_NATIVE_POWR_H__
diff --git a/libclc/clc/include/clc/math/clc_native_tan.h b/libclc/clc/include/clc/math/clc_native_tan.h
new file mode 100644
index 0000000000000..5fc96f8d1797a
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_native_tan.h
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_MATH_CLC_NATIVE_TAN_H__
+#define __CLC_MATH_CLC_NATIVE_TAN_H__
+
+#define __FLOAT_ONLY
+#define __CLC_FUNCTION __clc_native_tan
+#define __CLC_BODY <clc/shared/unary_decl.inc>
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+#undef __FLOAT_ONLY
+
+#endif // __CLC_MATH_CLC_NATIVE_TAN_H__
diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index d3ea3faa63c23..75a92a290306e 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -55,14 +55,17 @@ math/clc_nan.cl
math/clc_native_cos.cl
math/clc_native_divide.cl
math/clc_native_exp.cl
+math/clc_native_exp10.cl
math/clc_native_exp2.cl
math/clc_native_log.cl
math/clc_native_log10.cl
math/clc_native_log2.cl
+math/clc_native_powr.cl
math/clc_native_rsqrt.cl
math/clc_native_recip.cl
math/clc_native_sin.cl
math/clc_native_sqrt.cl
+math/clc_native_tan.cl
math/clc_nextafter.cl
math/clc_pow.cl
math/clc_pown.cl
diff --git a/libclc/clc/lib/generic/math/clc_native_exp10.cl b/libclc/clc/lib/generic/math/clc_native_exp10.cl
new file mode 100644
index 0000000000000..7ca5d1992c61c
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_native_exp10.cl
@@ -0,0 +1,16 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <clc/float/definitions.h>
+#include <clc/internal/clc.h>
+#include <clc/math/clc_native_exp2.h>
+
+#define __FLOAT_ONLY
+#define __CLC_BODY <clc_native_exp10.inc>
+
+#include <clc/math/gentype.inc>
diff --git a/libclc/generic/lib/math/native_exp10.inc b/libclc/clc/lib/generic/math/clc_native_exp10.inc
similarity index 75%
rename from libclc/generic/lib/math/native_exp10.inc
rename to libclc/clc/lib/generic/math/clc_native_exp10.inc
index d704152b962e1..c002b5444f432 100644
--- a/libclc/generic/lib/math/native_exp10.inc
+++ b/libclc/clc/lib/generic/math/clc_native_exp10.inc
@@ -6,6 +6,6 @@
//
//===----------------------------------------------------------------------===//
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_exp10(__CLC_GENTYPE val) {
- return native_exp2(val * M_LOG210_F);
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_exp10(__CLC_GENTYPE val) {
+ return __clc_native_exp2(val * M_LOG210_F);
}
diff --git a/libclc/clc/lib/generic/math/clc_native_powr.cl b/libclc/clc/lib/generic/math/clc_native_powr.cl
new file mode 100644
index 0000000000000..7c7dcaf8c508e
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_native_powr.cl
@@ -0,0 +1,16 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <clc/internal/clc.h>
+#include <clc/math/clc_native_exp2.h>
+#include <clc/math/clc_native_log2.h>
+
+#define __FLOAT_ONLY
+#define __CLC_BODY <clc_native_powr.inc>
+
+#include <clc/math/gentype.inc>
diff --git a/libclc/generic/lib/math/native_powr.inc b/libclc/clc/lib/generic/math/clc_native_powr.inc
similarity index 69%
rename from libclc/generic/lib/math/native_powr.inc
rename to libclc/clc/lib/generic/math/clc_native_powr.inc
index eae4d1b0b5fd5..51bd8b5ceb580 100644
--- a/libclc/generic/lib/math/native_powr.inc
+++ b/libclc/clc/lib/generic/math/clc_native_powr.inc
@@ -6,8 +6,9 @@
//
//===----------------------------------------------------------------------===//
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_powr(__CLC_GENTYPE x, __CLC_GENTYPE y) {
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_powr(__CLC_GENTYPE x,
+ __CLC_GENTYPE y) {
// x^y == 2^{log2 x^y} == 2^{y * log2 x}
// for x < 0 propagate nan created by log2
- return native_exp2(y * native_log2(x));
+ return __clc_native_exp2(y * __clc_native_log2(x));
}
diff --git a/libclc/clc/lib/generic/math/clc_native_tan.cl b/libclc/clc/lib/generic/math/clc_native_tan.cl
new file mode 100644
index 0000000000000..a9ac46688c8f3
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_native_tan.cl
@@ -0,0 +1,16 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <clc/internal/clc.h>
+#include <clc/math/clc_native_cos.h>
+#include <clc/math/clc_native_sin.h>
+
+#define __FLOAT_ONLY
+#define __CLC_BODY <clc_native_tan.inc>
+
+#include <clc/math/gentype.inc>
diff --git a/libclc/generic/lib/math/native_tan.inc b/libclc/clc/lib/generic/math/clc_native_tan.inc
similarity index 73%
rename from libclc/generic/lib/math/native_tan.inc
rename to libclc/clc/lib/generic/math/clc_native_tan.inc
index 02e05de74d67f..f61a78968a754 100644
--- a/libclc/generic/lib/math/native_tan.inc
+++ b/libclc/clc/lib/generic/math/clc_native_tan.inc
@@ -6,6 +6,6 @@
//
//===----------------------------------------------------------------------===//
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_tan(__CLC_GENTYPE val) {
- return native_sin(val) / native_cos(val);
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_tan(__CLC_GENTYPE val) {
+ return __clc_native_sin(val) / __clc_native_cos(val);
}
diff --git a/libclc/generic/include/clc/math/native_divide.h b/libclc/generic/include/clc/math/native_divide.h
index 2dd4aad46c3b3..3989a256cf949 100644
--- a/libclc/generic/include/clc/math/native_divide.h
+++ b/libclc/generic/include/clc/math/native_divide.h
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#define __CLC_BODY <clc/math/binary_decl_tt.inc>
+#define __CLC_BODY <clc/shared/binary_decl.inc>
#define __CLC_FUNCTION native_divide
#include <clc/math/gentype.inc>
diff --git a/libclc/generic/include/clc/math/native_powr.h b/libclc/generic/include/clc/math/native_powr.h
index e6fdb81d3cffa..19ae2d1ef9a02 100644
--- a/libclc/generic/include/clc/math/native_powr.h
+++ b/libclc/generic/include/clc/math/native_powr.h
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#define __CLC_BODY <clc/math/binary_decl_tt.inc>
+#define __CLC_BODY <clc/shared/binary_decl.inc>
#define __CLC_FUNCTION native_powr
#include <clc/math/gentype.inc>
diff --git a/libclc/generic/lib/math/native_exp10.cl b/libclc/generic/lib/math/native_exp10.cl
index 4accc5b3c0309..a7f3711cbedfd 100644
--- a/libclc/generic/lib/math/native_exp10.cl
+++ b/libclc/generic/lib/math/native_exp10.cl
@@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#include <clc/clc.h>
+#include <clc/math/clc_native_exp10.h>
-#define __CLC_BODY <native_exp10.inc>
#define __FLOAT_ONLY
+#define FUNCTION native_exp10
+#define __CLC_BODY <clc/shared/unary_def.inc>
+
#include <clc/math/gentype.inc>
diff --git a/libclc/generic/lib/math/native_powr.cl b/libclc/generic/lib/math/native_powr.cl
index a6d6c7a4417f2..31a650b79b609 100644
--- a/libclc/generic/lib/math/native_powr.cl
+++ b/libclc/generic/lib/math/native_powr.cl
@@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#include <clc/clc.h>
+#include <clc/math/clc_native_powr.h>
-#define __CLC_BODY <native_powr.inc>
#define __FLOAT_ONLY
+#define FUNCTION native_powr
+#define __CLC_BODY <clc/shared/binary_def.inc>
+
#include <clc/math/gentype.inc>
diff --git a/libclc/generic/lib/math/native_tan.cl b/libclc/generic/lib/math/native_tan.cl
index c73795f725d89..2b474ed46a5b5 100644
--- a/libclc/generic/lib/math/native_tan.cl
+++ b/libclc/generic/lib/math/native_tan.cl
@@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#include <clc/clc.h>
+#include <clc/math/clc_native_tan.h>
-#define __CLC_BODY <native_tan.inc>
#define __FLOAT_ONLY
+#define FUNCTION native_tan
+#define __CLC_BODY <clc/shared/unary_def.inc>
+
#include <clc/math/gentype.inc>
More information about the cfe-commits
mailing list