[Libclc-dev] [PATCH 1/5] add isfinite builtin

Jan Vesely jan.vesely at rutgers.edu
Thu Sep 4 08:50:10 PDT 2014


Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
 generic/include/clc/clc.h                 |  1 +
 generic/include/clc/relational/isfinite.h | 22 ++++++++++++++++++++++
 generic/lib/SOURCES                       |  1 +
 generic/lib/relational/isfinite.cl        | 19 +++++++++++++++++++
 4 files changed, 43 insertions(+)
 create mode 100644 generic/include/clc/relational/isfinite.h
 create mode 100644 generic/lib/relational/isfinite.cl

diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 17d8454..f7085ce 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -114,6 +114,7 @@
 #include <clc/relational/any.h>
 #include <clc/relational/bitselect.h>
 #include <clc/relational/isequal.h>
+#include <clc/relational/isfinite.h>
 #include <clc/relational/isgreater.h>
 #include <clc/relational/isgreaterequal.h>
 #include <clc/relational/isinf.h>
diff --git a/generic/include/clc/relational/isfinite.h b/generic/include/clc/relational/isfinite.h
new file mode 100644
index 0000000..60dea56
--- /dev/null
+++ b/generic/include/clc/relational/isfinite.h
@@ -0,0 +1,22 @@
+
+#define _CLC_ISINF_DECL(RET_TYPE, ARG_TYPE) \
+  _CLC_OVERLOAD _CLC_DECL RET_TYPE isfinite(ARG_TYPE);
+
+#define _CLC_VECTOR_ISINF_DECL(RET_TYPE, ARG_TYPE) \
+  _CLC_ISINF_DECL(RET_TYPE##2, ARG_TYPE##2) \
+  _CLC_ISINF_DECL(RET_TYPE##3, ARG_TYPE##3) \
+  _CLC_ISINF_DECL(RET_TYPE##4, ARG_TYPE##4) \
+  _CLC_ISINF_DECL(RET_TYPE##8, ARG_TYPE##8) \
+  _CLC_ISINF_DECL(RET_TYPE##16, ARG_TYPE##16)
+
+_CLC_ISINF_DECL(int, float)
+_CLC_VECTOR_ISINF_DECL(int, float)
+
+#ifdef cl_khr_fp64
+_CLC_ISINF_DECL(int, double)
+_CLC_VECTOR_ISINF_DECL(long, double)
+#endif
+
+#undef _CLC_ISINF_DECL
+#undef _CLC_VECTOR_ISINF_DECL
+
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index fb80124..3c02118 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -49,6 +49,7 @@ math/sincos_helpers.cl
 relational/all.cl
 relational/any.cl
 relational/isequal.cl
+relational/isfinite.cl
 relational/isgreater.cl
 relational/isgreaterequal.cl
 relational/isinf.cl
diff --git a/generic/lib/relational/isfinite.cl b/generic/lib/relational/isfinite.cl
new file mode 100644
index 0000000..7d96e10
--- /dev/null
+++ b/generic/lib/relational/isfinite.cl
@@ -0,0 +1,19 @@
+#include <clc/clc.h>
+#include "relational.h"
+
+_CLC_DEFINE_RELATIONAL_UNARY(int, isfinite, __builtin_isfinite, float)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+// The scalar version of isfinite(double) returns an int, but the vector versions
+// return long.
+_CLC_DEF _CLC_OVERLOAD int isfinite(double x) {
+  return __builtin_isfinite(x);
+}
+
+_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(long, isfinite, double)
+
+#endif
+
-- 
1.9.3




More information about the Libclc-dev mailing list