[libclc] [NFC][libclc] Simplify __clc_smoothstep and smoothstep macros (PR #164203)
Wenju He via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 19 21:54:24 PDT 2025
https://github.com/wenju-he created https://github.com/llvm/llvm-project/pull/164203
This is NFC because implementation doesn't change.
>From db1f69d9df0ae88095f759b47d5050b452c3215e Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Mon, 20 Oct 2025 06:51:42 +0200
Subject: [PATCH] [NFC][libclc] Simplify __clc_smoothstep and smoothstep macros
This is NFC because implementation doesn't change.
---
.../clc/lib/generic/common/clc_smoothstep.cl | 29 +---------
.../clc/lib/generic/common/clc_smoothstep.inc | 15 +++++
.../opencl/lib/generic/common/smoothstep.cl | 58 +------------------
.../opencl/lib/generic/common/smoothstep.inc | 23 ++++++++
4 files changed, 42 insertions(+), 83 deletions(-)
create mode 100644 libclc/clc/lib/generic/common/clc_smoothstep.inc
create mode 100644 libclc/opencl/lib/generic/common/smoothstep.inc
diff --git a/libclc/clc/lib/generic/common/clc_smoothstep.cl b/libclc/clc/lib/generic/common/clc_smoothstep.cl
index b409c7d7b6440..d97f811ed4649 100644
--- a/libclc/clc/lib/generic/common/clc_smoothstep.cl
+++ b/libclc/clc/lib/generic/common/clc_smoothstep.cl
@@ -8,30 +8,5 @@
#include <clc/internal/clc.h>
#include <clc/shared/clc_clamp.h>
-#define SMOOTHSTEP_SINGLE_DEF(edge_type, x_type, lit_suff) \
- _CLC_OVERLOAD _CLC_DEF x_type __clc_smoothstep(edge_type edge0, \
- edge_type edge1, x_type x) { \
- x_type t = __clc_clamp((x - edge0) / (edge1 - edge0), 0.0##lit_suff, \
- 1.0##lit_suff); \
- return t * t * (3.0##lit_suff - 2.0##lit_suff * t); \
- }
-
-#define SMOOTHSTEP_DEF(type, lit_suffix) \
- SMOOTHSTEP_SINGLE_DEF(type, type, lit_suffix) \
- SMOOTHSTEP_SINGLE_DEF(type##2, type##2, lit_suffix) \
- SMOOTHSTEP_SINGLE_DEF(type##3, type##3, lit_suffix) \
- SMOOTHSTEP_SINGLE_DEF(type##4, type##4, lit_suffix) \
- SMOOTHSTEP_SINGLE_DEF(type##8, type##8, lit_suffix) \
- SMOOTHSTEP_SINGLE_DEF(type##16, type##16, lit_suffix)
-
-SMOOTHSTEP_DEF(float, F)
-
-#ifdef cl_khr_fp64
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-SMOOTHSTEP_DEF(double, );
-#endif
-
-#ifdef cl_khr_fp16
-#pragma OPENCL EXTENSION cl_khr_fp16 : enable
-SMOOTHSTEP_DEF(half, H);
-#endif
+#define __CLC_BODY <clc_smoothstep.inc>
+#include <clc/math/gentype.inc>
diff --git a/libclc/clc/lib/generic/common/clc_smoothstep.inc b/libclc/clc/lib/generic/common/clc_smoothstep.inc
new file mode 100644
index 0000000000000..f7d853c27b558
--- /dev/null
+++ b/libclc/clc/lib/generic/common/clc_smoothstep.inc
@@ -0,0 +1,15 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_smoothstep(__CLC_GENTYPE edge0,
+ __CLC_GENTYPE edge1,
+ __CLC_GENTYPE x) {
+ __CLC_GENTYPE t = __clc_clamp((x - edge0) / (edge1 - edge0),
+ __CLC_FP_LIT(0.0), __CLC_FP_LIT(1.0));
+ return t * t * (__CLC_FP_LIT(3.0) - __CLC_FP_LIT(2.0) * t);
+}
diff --git a/libclc/opencl/lib/generic/common/smoothstep.cl b/libclc/opencl/lib/generic/common/smoothstep.cl
index 84ed7417de3cf..ee37718231929 100644
--- a/libclc/opencl/lib/generic/common/smoothstep.cl
+++ b/libclc/opencl/lib/generic/common/smoothstep.cl
@@ -9,59 +9,5 @@
#include <clc/common/clc_smoothstep.h>
#include <clc/opencl/common/smoothstep.h>
-#define SMOOTHSTEP_SINGLE_DEF(X_TYPE) \
- _CLC_OVERLOAD _CLC_DEF X_TYPE smoothstep(X_TYPE edge0, X_TYPE edge1, \
- X_TYPE x) { \
- return __clc_smoothstep(edge0, edge1, x); \
- }
-
-#define SMOOTHSTEP_S_S_V_DEFS(X_TYPE) \
- _CLC_OVERLOAD _CLC_DEF X_TYPE##2 smoothstep(X_TYPE x, X_TYPE y, \
- X_TYPE##2 z) { \
- return __clc_smoothstep((X_TYPE##2)x, (X_TYPE##2)y, z); \
- } \
- \
- _CLC_OVERLOAD _CLC_DEF X_TYPE##3 smoothstep(X_TYPE x, X_TYPE y, \
- X_TYPE##3 z) { \
- return __clc_smoothstep((X_TYPE##3)x, (X_TYPE##3)y, z); \
- } \
- \
- _CLC_OVERLOAD _CLC_DEF X_TYPE##4 smoothstep(X_TYPE x, X_TYPE y, \
- X_TYPE##4 z) { \
- return __clc_smoothstep((X_TYPE##4)x, (X_TYPE##4)y, z); \
- } \
- \
- _CLC_OVERLOAD _CLC_DEF X_TYPE##8 smoothstep(X_TYPE x, X_TYPE y, \
- X_TYPE##8 z) { \
- return __clc_smoothstep((X_TYPE##8)x, (X_TYPE##8)y, z); \
- } \
- \
- _CLC_OVERLOAD _CLC_DEF X_TYPE##16 smoothstep(X_TYPE x, X_TYPE y, \
- X_TYPE##16 z) { \
- return __clc_smoothstep((X_TYPE##16)x, (X_TYPE##16)y, z); \
- }
-
-#define SMOOTHSTEP_DEF(type) \
- SMOOTHSTEP_SINGLE_DEF(type) \
- SMOOTHSTEP_SINGLE_DEF(type##2) \
- SMOOTHSTEP_SINGLE_DEF(type##3) \
- SMOOTHSTEP_SINGLE_DEF(type##4) \
- SMOOTHSTEP_SINGLE_DEF(type##8) \
- SMOOTHSTEP_SINGLE_DEF(type##16) \
- SMOOTHSTEP_S_S_V_DEFS(type)
-
-SMOOTHSTEP_DEF(float)
-
-#ifdef cl_khr_fp64
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-
-SMOOTHSTEP_DEF(double);
-
-#endif
-
-#ifdef cl_khr_fp16
-#pragma OPENCL EXTENSION cl_khr_fp16 : enable
-
-SMOOTHSTEP_DEF(half);
-
-#endif
+#define __CLC_BODY <smoothstep.inc>
+#include <clc/math/gentype.inc>
diff --git a/libclc/opencl/lib/generic/common/smoothstep.inc b/libclc/opencl/lib/generic/common/smoothstep.inc
new file mode 100644
index 0000000000000..ece87aa2e0c35
--- /dev/null
+++ b/libclc/opencl/lib/generic/common/smoothstep.inc
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE smoothstep(__CLC_GENTYPE edge0,
+ __CLC_GENTYPE edge1,
+ __CLC_GENTYPE x) {
+ return __clc_smoothstep(edge0, edge1, x);
+}
+
+#if !defined(__CLC_SCALAR)
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE smoothstep(__CLC_SCALAR_GENTYPE edge0,
+ __CLC_SCALAR_GENTYPE edge1,
+ __CLC_GENTYPE x) {
+ return __clc_smoothstep((__CLC_GENTYPE)edge0, (__CLC_GENTYPE)edge1, x);
+}
+
+#endif
More information about the cfe-commits
mailing list