[libclc] 2dfb29a - [libclc] Move nan to the CLC library (#128521)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 24 07:41:35 PST 2025
Author: Fraser Cormack
Date: 2025-02-24T15:41:31Z
New Revision: 2dfb29a9b2f63e8dcbace2bf9b73ecc770f62b4d
URL: https://github.com/llvm/llvm-project/commit/2dfb29a9b2f63e8dcbace2bf9b73ecc770f62b4d
DIFF: https://github.com/llvm/llvm-project/commit/2dfb29a9b2f63e8dcbace2bf9b73ecc770f62b4d.diff
LOG: [libclc] Move nan to the CLC library (#128521)
Added:
libclc/clc/include/clc/math/clc_nan.h
libclc/clc/include/clc/math/clc_nan.inc
libclc/clc/lib/generic/math/clc_nan.cl
libclc/clc/lib/generic/math/clc_nan.inc
Modified:
libclc/clc/lib/generic/SOURCES
libclc/generic/lib/math/nan.cl
libclc/generic/lib/math/nan.inc
Removed:
################################################################################
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