[Libclc-dev] [PATCH 4/4] relational: Implement signbit

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


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

diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index e68de4c..4aa9caa 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -109,6 +109,7 @@
 #include <clc/relational/isnan.h>
 #include <clc/relational/isnotequal.h>
 #include <clc/relational/select.h>
+#include <clc/relational/signbit.h>
 
 /* 6.11.8 Synchronization Functions */
 #include <clc/synchronization/cl_mem_fence_flags.h>
diff --git a/generic/include/clc/relational/signbit.h b/generic/include/clc/relational/signbit.h
new file mode 100644
index 0000000..774d6e0
--- /dev/null
+++ b/generic/include/clc/relational/signbit.h
@@ -0,0 +1,18 @@
+
+#define _CLC_SIGNBIT_DECL(TYPE, RETTYPE) \
+  _CLC_OVERLOAD _CLC_DECL RETTYPE signbit(TYPE x);
+
+#define _CLC_VECTOR_SIGNBIT_DECL(TYPE, RETTYPE) \
+  _CLC_SIGNBIT_DECL(TYPE##2, RETTYPE##2)  \
+  _CLC_SIGNBIT_DECL(TYPE##3, RETTYPE##3)  \
+  _CLC_SIGNBIT_DECL(TYPE##4, RETTYPE##4)  \
+  _CLC_SIGNBIT_DECL(TYPE##8, RETTYPE##8)  \
+  _CLC_SIGNBIT_DECL(TYPE##16, RETTYPE##16)
+
+_CLC_SIGNBIT_DECL(float, int)
+_CLC_VECTOR_SIGNBIT_DECL(float, int)
+
+#ifdef cl_khr_fp64
+_CLC_SIGNBIT_DECL(double, int)
+_CLC_VECTOR_SIGNBIT_DECL(double, long)
+#endif
\ No newline at end of file
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index e0425f5..45f7c4a 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -39,6 +39,7 @@ relational/isgreater.cl
 relational/isgreaterequal.cl
 relational/isnotequal.cl
 relational/isnan.cl
+relational/signbit.cl
 shared/clamp.cl
 shared/max.cl
 shared/min.cl
diff --git a/generic/lib/relational/signbit.cl b/generic/lib/relational/signbit.cl
new file mode 100644
index 0000000..0a9209a
--- /dev/null
+++ b/generic/lib/relational/signbit.cl
@@ -0,0 +1,36 @@
+#include <clc/clc.h>
+
+//For float, sign bit is the first bit (most significant)
+
+#define _CLC_DEFINE_SIGNBIT(RET_TYPE, FUNCTION, ARG_TYPE, SCALAR_SIZE) \
+_CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG_TYPE x) { \
+  return (as_##RET_TYPE(x) >> (SCALAR_SIZE - 1)) != 0; \
+} \
+
+_CLC_DEFINE_SIGNBIT(int, signbit, float, 32)
+_CLC_DEFINE_SIGNBIT(int2, signbit, float2, 32)
+_CLC_DEFINE_SIGNBIT(int3, signbit, float3, 32)
+_CLC_DEFINE_SIGNBIT(int4, signbit, float4, 32)
+_CLC_DEFINE_SIGNBIT(int8, signbit, float8, 32)
+_CLC_DEFINE_SIGNBIT(int16, signbit, float16, 32)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+// The scalar version of signbit(double) returns an int, but the vector versions
+// return long.
+
+_CLC_DEF _CLC_OVERLOAD int signbit(double x) { \
+  return (as_long(x) >> 63) != 0; \
+} \
+
+_CLC_DEFINE_SIGNBIT(long2, signbit, double2, 64)
+_CLC_DEFINE_SIGNBIT(long3, signbit, double3, 64)
+_CLC_DEFINE_SIGNBIT(long4, signbit, double4, 64)
+_CLC_DEFINE_SIGNBIT(long8, signbit, double8, 64)
+_CLC_DEFINE_SIGNBIT(long16, signbit, double16, 64)
+
+#endif
+
+#undef _CLC_DEFINE_SIGNBIT
\ No newline at end of file
-- 
1.9.1





More information about the Libclc-dev mailing list