[libclc] [libclc] Move nan to the CLC library (PR #128521)

Fraser Cormack via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 24 07:12:02 PST 2025


https://github.com/frasercrmck created https://github.com/llvm/llvm-project/pull/128521

None

>From 49a2cb5fc5a098dc16f9e348eba8a93b3433a379 Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Mon, 24 Feb 2025 15:11:07 +0000
Subject: [PATCH] [libclc] Move nan to the CLC library

---
 libclc/clc/include/clc/math/clc_nan.h   | 12 ++++++++++++
 libclc/clc/include/clc/math/clc_nan.inc |  1 +
 libclc/clc/lib/generic/SOURCES          |  1 +
 libclc/clc/lib/generic/math/clc_nan.cl  |  5 +++++
 libclc/clc/lib/generic/math/clc_nan.inc | 15 +++++++++++++++
 libclc/generic/lib/math/nan.cl          |  5 ++---
 libclc/generic/lib/math/nan.inc         | 14 +-------------
 7 files changed, 37 insertions(+), 16 deletions(-)
 create mode 100644 libclc/clc/include/clc/math/clc_nan.h
 create mode 100644 libclc/clc/include/clc/math/clc_nan.inc
 create mode 100644 libclc/clc/lib/generic/math/clc_nan.cl
 create mode 100644 libclc/clc/lib/generic/math/clc_nan.inc

diff --git a/libclc/clc/include/clc/math/clc_nan.h b/libclc/clc/include/clc/math/clc_nan.h
new file mode 100644
index 0000000000000..cfea9efa23bf4
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_nan.h
@@ -0,0 +1,12 @@
+#ifndef __CLC_MATH_CLC_NAN_H__
+#define __CLC_MATH_CLC_NAN_H__
+
+#define __CLC_FUNCTION __clc_nan
+#define __CLC_BODY <clc/math/clc_nan.inc>
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_NAN_H__
diff --git a/libclc/clc/include/clc/math/clc_nan.inc b/libclc/clc/include/clc/math/clc_nan.inc
new file mode 100644
index 0000000000000..7972d6c02c830
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_nan.inc
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_nan(__CLC_U_GENTYPE code);
diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index 0ab563df6a274..54b0cd23f1650 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -25,6 +25,7 @@ math/clc_floor.cl
 math/clc_frexp.cl
 math/clc_mad.cl
 math/clc_modf.cl
+math/clc_nan.cl
 math/clc_nextafter.cl
 math/clc_rint.cl
 math/clc_sw_fma.cl
diff --git a/libclc/clc/lib/generic/math/clc_nan.cl b/libclc/clc/lib/generic/math/clc_nan.cl
new file mode 100644
index 0000000000000..69501b886f606
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_nan.cl
@@ -0,0 +1,5 @@
+#include <clc/internal/clc.h>
+#include <clc/utils.h>
+
+#define __CLC_BODY <clc_nan.inc>
+#include <clc/math/gentype.inc>
diff --git a/libclc/clc/lib/generic/math/clc_nan.inc b/libclc/clc/lib/generic/math/clc_nan.inc
new file mode 100644
index 0000000000000..7125af6f82910
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_nan.inc
@@ -0,0 +1,15 @@
+#if __CLC_FPSIZE == 64
+#define NAN_MASK 0x7ff0000000000000ul
+#elif __CLC_FPSIZE == 32
+#define NAN_MASK 0x7fc00000
+#elif __CLC_FPSIZE == 16
+#define NAN_MASK 0x7e00
+#endif
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_nan(__CLC_U_GENTYPE code) {
+  const __CLC_U_GENTYPE mask = NAN_MASK;
+  const __CLC_U_GENTYPE res = code | mask;
+  return __CLC_AS_GENTYPE(res);
+}
+
+#undef NAN_MASK
diff --git a/libclc/generic/lib/math/nan.cl b/libclc/generic/lib/math/nan.cl
index 5ec60d4521fc0..048bf59103d68 100644
--- a/libclc/generic/lib/math/nan.cl
+++ b/libclc/generic/lib/math/nan.cl
@@ -1,6 +1,5 @@
-#include <clc/clc.h>
-#include <clc/utils.h>
+#include <clc/clcmacro.h>
+#include <clc/math/clc_nan.h>
 
-#define __OPENCL_AS_GENTYPE __CLC_XCONCAT(as_, __CLC_GENTYPE)
 #define __CLC_BODY <nan.inc>
 #include <clc/math/gentype.inc>
diff --git a/libclc/generic/lib/math/nan.inc b/libclc/generic/lib/math/nan.inc
index ded7f45072a93..0d04c0eb41537 100644
--- a/libclc/generic/lib/math/nan.inc
+++ b/libclc/generic/lib/math/nan.inc
@@ -1,15 +1,3 @@
-#if __CLC_FPSIZE == 64
-#define NAN_MASK 0x7ff0000000000000ul
-#elif __CLC_FPSIZE == 32
-#define NAN_MASK 0x7fc00000
-#elif __CLC_FPSIZE == 16
-#define NAN_MASK 0x7e00
-#endif
-
 _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE nan(__CLC_U_GENTYPE code) {
-  const __CLC_U_GENTYPE mask = NAN_MASK;
-  const __CLC_U_GENTYPE res = code | mask;
-  return __OPENCL_AS_GENTYPE(res);
+  return __clc_nan(code);
 }
-
-#undef NAN_MASK



More information about the cfe-commits mailing list