summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2012-10-08 03:39:21 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2012-10-08 03:39:21 +0000
commit14e5a4f2116dd512d3bd6489d55760aa487cc3dd (patch)
tree8bfe75f4ad9455b3107c4a71a6cea00d3ed8f920
parent5c2bfa665589a07301860bb2da3912ce5a8323db (diff)
Implement any() builtin. Patch by Tom Stellard!
git-svn-id: https://llvm.org/svn/llvm-project/libclc/trunk@165386 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--generic/include/clc/clc.h1
-rw-r--r--generic/include/clc/relational/any.h16
-rw-r--r--generic/lib/SOURCES1
-rw-r--r--generic/lib/relational/any.cl30
4 files changed, 48 insertions, 0 deletions
diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index fc41f76..315693b 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -69,6 +69,7 @@
#include <clc/geometric/normalize.h>
/* 6.11.6 Relational Functions */
+#include <clc/relational/any.h>
#include <clc/relational/select.h>
/* 6.11.8 Synchronization Functions */
diff --git a/generic/include/clc/relational/any.h b/generic/include/clc/relational/any.h
new file mode 100644
index 0000000..4687ed2
--- /dev/null
+++ b/generic/include/clc/relational/any.h
@@ -0,0 +1,16 @@
+
+#define _CLC_ANY_DECL(TYPE) \
+ _CLC_OVERLOAD _CLC_DECL int any(TYPE v);
+
+#define _CLC_VECTOR_ANY_DECL(TYPE) \
+ _CLC_ANY_DECL(TYPE) \
+ _CLC_ANY_DECL(TYPE##2) \
+ _CLC_ANY_DECL(TYPE##3) \
+ _CLC_ANY_DECL(TYPE##4) \
+ _CLC_ANY_DECL(TYPE##8) \
+ _CLC_ANY_DECL(TYPE##16)
+
+_CLC_VECTOR_ANY_DECL(char)
+_CLC_VECTOR_ANY_DECL(short)
+_CLC_VECTOR_ANY_DECL(int)
+_CLC_VECTOR_ANY_DECL(long)
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 1d56c40..d29ca1f 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -12,5 +12,6 @@ integer/sub_sat.ll
integer/sub_sat_impl.ll
math/hypot.cl
math/mad.cl
+relational/any.cl
workitem/get_global_id.cl
workitem/get_global_size.cl
diff --git a/generic/lib/relational/any.cl b/generic/lib/relational/any.cl
new file mode 100644
index 0000000..4d37210
--- /dev/null
+++ b/generic/lib/relational/any.cl
@@ -0,0 +1,30 @@
+#include <clc/clc.h>
+
+#define _CLC_ANY(v) (((v) >> ((sizeof(v) * 8) - 1)) & 0x1)
+#define _CLC_ANY2(v) (_CLC_ANY((v).s0) | _CLC_ANY((v).s1))
+#define _CLC_ANY3(v) (_CLC_ANY2((v)) | _CLC_ANY((v).s2))
+#define _CLC_ANY4(v) (_CLC_ANY3((v)) | _CLC_ANY((v).s3))
+#define _CLC_ANY8(v) (_CLC_ANY4((v)) | _CLC_ANY((v).s4) | _CLC_ANY((v).s5) \
+ | _CLC_ANY((v).s6) | _CLC_ANY((v).s7))
+#define _CLC_ANY16(v) (_CLC_ANY8((v)) | _CLC_ANY((v).s8) | _CLC_ANY((v).s9) \
+ | _CLC_ANY((v).sA) | _CLC_ANY((v).sB) \
+ | _CLC_ANY((v).sC) | _CLC_ANY((v).sD) \
+ | _CLC_ANY((v).sE) | _CLC_ANY((v).sf))
+
+
+#define ANY_ID(TYPE) \
+ _CLC_OVERLOAD _CLC_DEF int any(TYPE v)
+
+#define ANY_VECTORIZE(TYPE) \
+ ANY_ID(TYPE) { return _CLC_ANY(v); } \
+ ANY_ID(TYPE##2) { return _CLC_ANY2(v); } \
+ ANY_ID(TYPE##3) { return _CLC_ANY3(v); } \
+ ANY_ID(TYPE##4) { return _CLC_ANY4(v); } \
+ ANY_ID(TYPE##8) { return _CLC_ANY8(v); } \
+ ANY_ID(TYPE##16) { return _CLC_ANY16(v); }
+
+ANY_VECTORIZE(char)
+ANY_VECTORIZE(short)
+ANY_VECTORIZE(int)
+ANY_VECTORIZE(long)
+