[Libclc-dev] [PATCH 1/4] relational: Implement isgreater

Aaron Watry awatry at gmail.com
Wed Jun 11 12:15:22 PDT 2014


Signed-off-by: Aaron Watry <awatry at gmail.com>
---
 generic/include/clc/clc.h                  |  1 +
 generic/include/clc/relational/isgreater.h | 18 +++++++++++++++
 generic/lib/SOURCES                        |  1 +
 generic/lib/relational/isgreater.cl        | 36 ++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
 create mode 100644 generic/include/clc/relational/isgreater.h
 create mode 100644 generic/lib/relational/isgreater.cl

diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index f8c1853..040ed2c 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -106,6 +106,7 @@
 #include <clc/relational/bitselect.h>
 #include <clc/relational/isnan.h>
 #include <clc/relational/select.h>
+#include <clc/relational/isgreater.h>
 
 /* 6.11.8 Synchronization Functions */
 #include <clc/synchronization/cl_mem_fence_flags.h>
diff --git a/generic/include/clc/relational/isgreater.h b/generic/include/clc/relational/isgreater.h
new file mode 100644
index 0000000..5106d7a
--- /dev/null
+++ b/generic/include/clc/relational/isgreater.h
@@ -0,0 +1,18 @@
+
+#define _CLC_ISGREATER_DECL(TYPE, RETTYPE) \
+  _CLC_OVERLOAD _CLC_DECL RETTYPE isgreater(TYPE x, TYPE y);
+
+#define _CLC_VECTOR_ISGREATER_DECL(TYPE, RETTYPE) \
+  _CLC_ISGREATER_DECL(TYPE##2, RETTYPE##2)  \
+  _CLC_ISGREATER_DECL(TYPE##3, RETTYPE##3)  \
+  _CLC_ISGREATER_DECL(TYPE##4, RETTYPE##4)  \
+  _CLC_ISGREATER_DECL(TYPE##8, RETTYPE##8)  \
+  _CLC_ISGREATER_DECL(TYPE##16, RETTYPE##16)
+
+_CLC_ISGREATER_DECL(float, int)
+_CLC_VECTOR_ISGREATER_DECL(float, int)
+
+#ifdef cl_khr_fp64
+_CLC_ISGREATER_DECL(double, int)
+_CLC_VECTOR_ISGREATER_DECL(double, long)
+#endif
\ No newline at end of file
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 6ccdf48..6479b53 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -35,6 +35,7 @@ math/clc_nextafter.cl
 math/nextafter.cl
 math/sincos.cl
 relational/any.cl
+relational/isgreater.cl
 relational/isnan.cl
 shared/clamp.cl
 shared/max.cl
diff --git a/generic/lib/relational/isgreater.cl b/generic/lib/relational/isgreater.cl
new file mode 100644
index 0000000..ea497cd
--- /dev/null
+++ b/generic/lib/relational/isgreater.cl
@@ -0,0 +1,36 @@
+#include <clc/clc.h>
+
+//Note: It would be nice to use __builtin_isgreater, 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_ISGREATER(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_ISGREATER(int, isgreater, float, float)
+_CLC_DEFINE_ISGREATER(int2, isgreater, float2, float2)
+_CLC_DEFINE_ISGREATER(int3, isgreater, float3, float3)
+_CLC_DEFINE_ISGREATER(int4, isgreater, float4, float4)
+_CLC_DEFINE_ISGREATER(int8, isgreater, float8, float8)
+_CLC_DEFINE_ISGREATER(int16, isgreater, float16, float16)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+// The scalar version of isgreater(double) returns an int, but the vector versions
+// return long.
+_CLC_DEFINE_ISGREATER(int, isgreater, double, double)
+_CLC_DEFINE_ISGREATER(long2, isgreater, double2, double2)
+_CLC_DEFINE_ISGREATER(long3, isgreater, double3, double3)
+_CLC_DEFINE_ISGREATER(long4, isgreater, double4, double4)
+_CLC_DEFINE_ISGREATER(long8, isgreater, double8, double8)
+_CLC_DEFINE_ISGREATER(long16, isgreater, double16, double16)
+
+#endif
+
+#undef _CLC_DEFINE_ISGREATER
\ No newline at end of file
-- 
1.9.1





More information about the Libclc-dev mailing list