[Libclc-dev] [PATCH 3/4] relational: Implement isnotequal
Aaron Watry
awatry at gmail.com
Wed Jun 11 12:15:24 PDT 2014
Signed-off-by: Aaron Watry <awatry at gmail.com>
---
generic/include/clc/clc.h | 1 +
generic/include/clc/relational/isnotequal.h | 18 +++++++++++++++
generic/lib/SOURCES | 1 +
generic/lib/relational/isnotequal.cl | 36 +++++++++++++++++++++++++++++
4 files changed, 56 insertions(+)
create mode 100644 generic/include/clc/relational/isnotequal.h
create mode 100644 generic/lib/relational/isnotequal.cl
diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index a220da5..e68de4c 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -107,6 +107,7 @@
#include <clc/relational/isgreater.h>
#include <clc/relational/isgreaterequal.h>
#include <clc/relational/isnan.h>
+#include <clc/relational/isnotequal.h>
#include <clc/relational/select.h>
/* 6.11.8 Synchronization Functions */
diff --git a/generic/include/clc/relational/isnotequal.h b/generic/include/clc/relational/isnotequal.h
new file mode 100644
index 0000000..0a6a060
--- /dev/null
+++ b/generic/include/clc/relational/isnotequal.h
@@ -0,0 +1,18 @@
+
+#define _CLC_ISNOTEQUAL_DECL(TYPE, RETTYPE) \
+ _CLC_OVERLOAD _CLC_DECL RETTYPE isnotequal(TYPE x, TYPE y);
+
+#define _CLC_VECTOR_ISNOTEQUAL_DECL(TYPE, RETTYPE) \
+ _CLC_ISNOTEQUAL_DECL(TYPE##2, RETTYPE##2) \
+ _CLC_ISNOTEQUAL_DECL(TYPE##3, RETTYPE##3) \
+ _CLC_ISNOTEQUAL_DECL(TYPE##4, RETTYPE##4) \
+ _CLC_ISNOTEQUAL_DECL(TYPE##8, RETTYPE##8) \
+ _CLC_ISNOTEQUAL_DECL(TYPE##16, RETTYPE##16)
+
+_CLC_ISNOTEQUAL_DECL(float, int)
+_CLC_VECTOR_ISNOTEQUAL_DECL(float, int)
+
+#ifdef cl_khr_fp64
+_CLC_ISNOTEQUAL_DECL(double, int)
+_CLC_VECTOR_ISNOTEQUAL_DECL(double, long)
+#endif
\ No newline at end of file
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 9b8cf89..e0425f5 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -37,6 +37,7 @@ math/sincos.cl
relational/any.cl
relational/isgreater.cl
relational/isgreaterequal.cl
+relational/isnotequal.cl
relational/isnan.cl
shared/clamp.cl
shared/max.cl
diff --git a/generic/lib/relational/isnotequal.cl b/generic/lib/relational/isnotequal.cl
new file mode 100644
index 0000000..5e544c5
--- /dev/null
+++ b/generic/lib/relational/isnotequal.cl
@@ -0,0 +1,36 @@
+#include <clc/clc.h>
+
+//Note: It would be nice to use __builtin_isnotequal, but that seems to only take scalar values as input, which will
+// produce incorrect output for vector input types.
+//
+// For the the same reason (1 vs -1 output), we can't use the _CLC_DEFINE_BINARY_BUILTIN macro here as that expands
+// all vector operations to multiple scalar operations
+
+#define _CLC_DEFINE_ISNOTEQUAL(RET_TYPE, FUNCTION, ARG1_TYPE, ARG2_TYPE) \
+_CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x, ARG2_TYPE y) { \
+ return (x != y); \
+} \
+
+_CLC_DEFINE_ISNOTEQUAL(int, isnotequal, float, float)
+_CLC_DEFINE_ISNOTEQUAL(int2, isnotequal, float2, float2)
+_CLC_DEFINE_ISNOTEQUAL(int3, isnotequal, float3, float3)
+_CLC_DEFINE_ISNOTEQUAL(int4, isnotequal, float4, float4)
+_CLC_DEFINE_ISNOTEQUAL(int8, isnotequal, float8, float8)
+_CLC_DEFINE_ISNOTEQUAL(int16, isnotequal, float16, float16)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+// The scalar version of isnotequal(double) returns an int, but the vector versions
+// return long.
+_CLC_DEFINE_ISNOTEQUAL(int, isnotequal, double, double)
+_CLC_DEFINE_ISNOTEQUAL(long2, isnotequal, double2, double2)
+_CLC_DEFINE_ISNOTEQUAL(long3, isnotequal, double3, double3)
+_CLC_DEFINE_ISNOTEQUAL(long4, isnotequal, double4, double4)
+_CLC_DEFINE_ISNOTEQUAL(long8, isnotequal, double8, double8)
+_CLC_DEFINE_ISNOTEQUAL(long16, isnotequal, double16, double16)
+
+#endif
+
+#undef _CLC_DEFINE_ISNOTEQUAL
\ No newline at end of file
--
1.9.1
More information about the Libclc-dev
mailing list