[libclc] 94/291: Implement isnan() builtin

Andreas Beckmann anbe at moszumanska.debian.org
Tue Sep 8 10:53:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

anbe pushed a commit to branch master
in repository libclc.

commit 6c1a2533f977195456f639ccf7f306b85ce9a5e3
Author: Tom Stellard <thomas.stellard at amd.com>
Date:   Thu Oct 10 19:08:41 2013 +0000

    Implement isnan() builtin
    
    git-svn-id: https://llvm.org/svn/llvm-project/libclc/trunk@192382 91177308-0d34-0410-b5e6-96231b3b80d8
---
 generic/include/clc/clc.h              |  1 +
 generic/include/clc/clcmacro.h         |  6 ++++++
 generic/include/clc/relational/isnan.h | 21 +++++++++++++++++++++
 generic/lib/SOURCES                    |  1 +
 generic/lib/relational/isnan.cl        | 17 +++++++++++++++++
 5 files changed, 46 insertions(+)

diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 467cd58..fce9f6e 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -94,6 +94,7 @@
 /* 6.11.6 Relational Functions */
 #include <clc/relational/any.h>
 #include <clc/relational/bitselect.h>
+#include <clc/relational/isnan.h>
 #include <clc/relational/select.h>
 
 /* 6.11.8 Synchronization Functions */
diff --git a/generic/include/clc/clcmacro.h b/generic/include/clc/clcmacro.h
index d10a613..ece0d3b 100644
--- a/generic/include/clc/clcmacro.h
+++ b/generic/include/clc/clcmacro.h
@@ -40,3 +40,9 @@
   DECLSPEC RET_TYPE##16 FUNCTION(ARG1_TYPE##16 x, ARG2_TYPE##16 y) { \
     return (RET_TYPE##16)(FUNCTION(x.lo, y.lo), FUNCTION(x.hi, y.hi)); \
   }
+
+#define _CLC_DEFINE_UNARY_BUILTIN(RET_TYPE, FUNCTION, BUILTIN, ARG1_TYPE) \
+_CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x) { \
+  return BUILTIN(x); \
+} \
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, RET_TYPE, FUNCTION, ARG1_TYPE)
diff --git a/generic/include/clc/relational/isnan.h b/generic/include/clc/relational/isnan.h
new file mode 100644
index 0000000..93eb9df
--- /dev/null
+++ b/generic/include/clc/relational/isnan.h
@@ -0,0 +1,21 @@
+
+#define _CLC_ISNAN_DECL(RET_TYPE, ARG_TYPE) \
+  _CLC_OVERLOAD _CLC_DECL RET_TYPE isnan(ARG_TYPE);
+
+#define _CLC_VECTOR_ISNAN_DECL(RET_TYPE, ARG_TYPE) \
+  _CLC_ISNAN_DECL(RET_TYPE##2, ARG_TYPE##2) \
+  _CLC_ISNAN_DECL(RET_TYPE##3, ARG_TYPE##3) \
+  _CLC_ISNAN_DECL(RET_TYPE##4, ARG_TYPE##4) \
+  _CLC_ISNAN_DECL(RET_TYPE##8, ARG_TYPE##8) \
+  _CLC_ISNAN_DECL(RET_TYPE##16, ARG_TYPE##16)
+
+_CLC_ISNAN_DECL(int, float)
+_CLC_VECTOR_ISNAN_DECL(int, float)
+
+#ifdef cl_khr_fp64
+_CLC_ISNAN_DECL(int, double)
+_CLC_VECTOR_ISNAN_DECL(long, double)
+#endif
+
+#undef _CLC_ISNAN_DECL
+#undef _CLC_VECTOR_ISNAN_DECL
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 16db9bc..383a66e 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -27,6 +27,7 @@ math/fmin.cl
 math/hypot.cl
 math/mad.cl
 relational/any.cl
+relational/isnan.cl
 shared/clamp.cl
 shared/max.cl
 shared/min.cl
diff --git a/generic/lib/relational/isnan.cl b/generic/lib/relational/isnan.cl
new file mode 100644
index 0000000..1a64f67
--- /dev/null
+++ b/generic/lib/relational/isnan.cl
@@ -0,0 +1,17 @@
+#include <clc/clc.h>
+
+_CLC_DEFINE_UNARY_BUILTIN(int, isnan, __builtin_isnan, float)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+// The scalar version of isnan(double) returns an int, but the vector versions
+// return long.
+_CLC_DEF _CLC_OVERLOAD int isnan(double x) {
+  return __builtin_isnan(x);
+}
+
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, long, isnan, double)
+
+#endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opencl/libclc.git



More information about the Pkg-opencl-commits mailing list