[Beignet] [PATCH 08/18] Add the relational functions into the ocl lib.

junyan.he at inbox.com junyan.he at inbox.com
Tue Aug 12 00:32:08 PDT 2014


From: Junyan He <junyan.he at linux.intel.com>

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 backend/src/libocl/Makefile.in                |   4 +-
 backend/src/libocl/include/ocl_relational.inh |  78 +++++++++++++
 backend/src/libocl/lib/ocl_relational.inc     | 151 ++++++++++++++++++++++++++
 backend/src/libocl/script/ocl_relational.def  |  34 ++++++
 4 files changed, 265 insertions(+), 2 deletions(-)
 create mode 100644 backend/src/libocl/include/ocl_relational.inh
 create mode 100644 backend/src/libocl/lib/ocl_relational.inc
 create mode 100644 backend/src/libocl/script/ocl_relational.def

diff --git a/backend/src/libocl/Makefile.in b/backend/src/libocl/Makefile.in
index 78f8668..c89050e 100644
--- a/backend/src/libocl/Makefile.in
+++ b/backend/src/libocl/Makefile.in
@@ -3,8 +3,8 @@
 HEADER_INSTALL_PREFIX=@OCL_HEADER_DIR@
 BITCODE_INSTALL_PREFIX=@OCL_BITCODE_DIR@
 
-GENERATED_FILES=ocl_as.cl ocl_convert.cl ocl_common.cl
-GENERATED_HEADERS=ocl_defines.h ocl_as.h ocl_convert.h ocl_common.h
+GENERATED_FILES=ocl_as.cl ocl_convert.cl ocl_common.cl ocl_relational.cl
+GENERATED_HEADERS=ocl_defines.h ocl_as.h ocl_convert.h ocl_common.h ocl_relational.h
 GENERATED_CL_SRCS=$(addprefix lib/, $(GENERATED_FILES))
 GENERATED_CL_HEADERS=$(addprefix include/, $(GENERATED_HEADERS))
 CL_FILE_NAMES=ocl_workitem.cl ocl_atom.cl ocl_async.cl ocl_sync.cl $(GENERATED_FILES)
diff --git a/backend/src/libocl/include/ocl_relational.inh b/backend/src/libocl/include/ocl_relational.inh
new file mode 100644
index 0000000..8033775
--- /dev/null
+++ b/backend/src/libocl/include/ocl_relational.inh
@@ -0,0 +1,78 @@
+#ifndef __OCL_RELATIONAL_H__
+#define __OCL_RELATIONAL_H__
+
+#include "ocl_types.h"
+#include "ocl_as.h"
+
+OVERLOADABLE int isequal(float x, float y);
+OVERLOADABLE int isnotequal(float x, float y);
+OVERLOADABLE int isgreater(float x, float y);
+OVERLOADABLE int isgreaterequal(float x, float y);
+OVERLOADABLE int isless(float x, float y);
+OVERLOADABLE int islessequal(float x, float y);
+OVERLOADABLE int islessgreater(float x, float y);
+
+OVERLOADABLE int isfinite(float x);
+OVERLOADABLE int isinf(float x);
+OVERLOADABLE int isnan(float x);
+OVERLOADABLE int isnormal(float x);
+
+
+OVERLOADABLE int isordered(float x, float y);
+OVERLOADABLE int isunordered(float x, float y);
+OVERLOADABLE int signbit(float x);
+
+
+#define DEC1(type) OVERLOADABLE int all(type a);
+#define DEC2(type) OVERLOADABLE int all(type a);
+#define DEC3(type) OVERLOADABLE int all(type a);
+#define DEC4(type) OVERLOADABLE int all(type a);
+#define DEC8(type) OVERLOADABLE int all(type a);
+#define DEC16(type) OVERLOADABLE int all(type a);
+DEC1(char)
+DEC1(short)
+DEC1(int)
+DEC1(long)
+#define DEC(n) DEC##n(char##n) DEC##n(short##n) DEC##n(int##n) DEC##n(long##n)
+DEC(2)
+DEC(3)
+DEC(4)
+DEC(8)
+DEC(16)
+#undef DEC
+#undef DEC1
+#undef DEC2
+#undef DEC3
+#undef DEC4
+#undef DEC8
+#undef DEC16
+
+#define DEF(type) OVERLOADABLE type bitselect(type a, type b, type c);
+DEF(char) DEF(uchar) DEF(short) DEF(ushort) DEF(int) DEF(uint)
+DEF(long) DEF(ulong)
+#undef DEF
+OVERLOADABLE float bitselect(float a, float b, float c);
+
+
+#define DEF(TYPE1, TYPE2) \
+OVERLOADABLE TYPE1 select(TYPE1 src0, TYPE1 src1, TYPE2 cond);
+DEF(char, char)
+DEF(char, uchar)
+DEF(uchar, char)
+DEF(uchar, uchar)
+DEF(short, short)
+DEF(short, ushort)
+DEF(ushort, short)
+DEF(ushort, ushort)
+DEF(int, int)
+DEF(int, uint)
+DEF(uint, int)
+DEF(uint, uint)
+DEF(long, long)
+DEF(long, ulong)
+DEF(ulong, long)
+DEF(ulong, ulong)
+DEF(float, int)
+DEF(float, uint)
+#undef DEF
+
diff --git a/backend/src/libocl/lib/ocl_relational.inc b/backend/src/libocl/lib/ocl_relational.inc
new file mode 100644
index 0000000..0b218f4
--- /dev/null
+++ b/backend/src/libocl/lib/ocl_relational.inc
@@ -0,0 +1,151 @@
+#include "ocl_relational.h"
+
+OVERLOADABLE int isequal(float x, float y) {
+  return x == y;
+}
+
+OVERLOADABLE int isnotequal(float x, float y) {
+  return x != y; 
+}
+
+OVERLOADABLE int isgreater(float x, float y) {
+  return x > y;
+}
+
+OVERLOADABLE int isgreaterequal(float x, float y) {
+  return x >= y;
+}
+
+OVERLOADABLE int isless(float x, float y) {
+  return x < y;
+}
+
+OVERLOADABLE int islessequal(float x, float y) {
+  return x <= y;
+}
+
+OVERLOADABLE int islessgreater(float x, float y) {
+  return (x < y) || (x > y);
+}
+
+OVERLOADABLE int isfinite(float x) {
+  union { uint u; float f; } u;
+  u.f = x;
+  return (u.u & 0x7FFFFFFF) < 0x7F800000;
+}
+
+OVERLOADABLE int isinf(float x) {
+  union { uint u; float f; } u;
+  u.f = x;
+  return (u.u & 0x7FFFFFFF) == 0x7F800000;
+}
+
+OVERLOADABLE int isnan(float x) {
+  return x != x;
+}
+
+OVERLOADABLE int isnormal(float x) {
+  union { uint u; float f; } u;
+  u.f = x;
+  u.u &= 0x7FFFFFFF;
+  return (u.u < 0x7F800000) && (u.u >= 0x800000);
+}
+
+
+OVERLOADABLE int isordered(float x, float y) {
+  return isequal(x, x) && isequal(y, y);
+}
+OVERLOADABLE int isunordered(float x, float y) {
+  return isnan(x) || isnan(y);
+}
+OVERLOADABLE int signbit(float x) {
+  union { uint u; float f; } u;
+  u.f = x;
+  return u.u >> 31;
+}
+
+
+// any
+#define DEC1(type) OVERLOADABLE int any(type a) { return a<0; }
+#define DEC2(type) OVERLOADABLE int any(type a) { return a.s0<0 || a.s1<0; }
+#define DEC3(type) OVERLOADABLE int any(type a) { return a.s0<0 || a.s1<0 || a.s2<0; }
+#define DEC4(type) OVERLOADABLE int any(type a) { return a.s0<0 || a.s1<0 || a.s2<0 || a.s3<0; }
+#define DEC8(type) OVERLOADABLE int any(type a) { return a.s0<0 || a.s1<0 || a.s2<0 || a.s3<0 || a.s4<0 || a.s5<0 || a.s6<0 || a.s7<0; }
+#define DEC16(type) OVERLOADABLE int any(type a) { return a.s0<0 || a.s1<0 || a.s2<0 || a.s3<0 || a.s4<0 || a.s5<0 || a.s6<0 || a.s7<0 || a.s8<0 || a.s9<0 || a.sA<0 || a.sB<0 || a.sC<0 || a.sD<0 || a.sE<0 || a.sF<0; }
+DEC1(char);
+DEC1(short);
+DEC1(int);
+DEC1(long);
+#define DEC(n) DEC##n(char##n); DEC##n(short##n); DEC##n(int##n); DEC##n(long##n);
+DEC(2);
+DEC(3);
+DEC(4);
+DEC(8);
+DEC(16);
+#undef DEC
+#undef DEC1
+#undef DEC2
+#undef DEC3
+#undef DEC4
+#undef DEC8
+#undef DEC16
+
+// all
+#define DEC1(type) OVERLOADABLE int all(type a) { return a<0; }
+#define DEC2(type) OVERLOADABLE int all(type a) { return a.s0<0 && a.s1<0; }
+#define DEC3(type) OVERLOADABLE int all(type a) { return a.s0<0 && a.s1<0 && a.s2<0; }
+#define DEC4(type) OVERLOADABLE int all(type a) { return a.s0<0 && a.s1<0 && a.s2<0 && a.s3<0; }
+#define DEC8(type) OVERLOADABLE int all(type a) { return a.s0<0 && a.s1<0 && a.s2<0 && a.s3<0 && a.s4<0 && a.s5<0 && a.s6<0 && a.s7<0; }
+#define DEC16(type) OVERLOADABLE int all(type a) { return a.s0<0 && a.s1<0 && a.s2<0 && a.s3<0 && a.s4<0 && a.s5<0 && a.s6<0 && a.s7<0 && a.s8<0 && a.s9<0 && a.sA<0 && a.sB<0 && a.sC<0 && a.sD<0 && a.sE<0 && a.sF<0; }
+DEC1(char);
+DEC1(short);
+DEC1(int);
+DEC1(long);
+#define DEC(n) DEC##n(char##n); DEC##n(short##n); DEC##n(int##n); DEC##n(long##n);
+DEC(2);
+DEC(3);
+DEC(4);
+DEC(8);
+DEC(16);
+#undef DEC
+#undef DEC1
+#undef DEC2
+#undef DEC3
+#undef DEC4
+#undef DEC8
+#undef DEC16
+
+#define DEF(type) OVERLOADABLE type bitselect(type a, type b, type c) { return (a & ~c) | (b & c); }
+DEF(char); DEF(uchar); DEF(short); DEF(ushort); DEF(int); DEF(uint)
+DEF(long); DEF(ulong)
+#undef DEF
+OVERLOADABLE float bitselect(float a, float b, float c) {
+  return as_float(bitselect(as_int(a), as_int(b), as_int(c)));
+}
+
+
+// select
+#define DEF(TYPE1, TYPE2) \
+OVERLOADABLE TYPE1 select(TYPE1 src0, TYPE1 src1, TYPE2 cond) { \
+  return cond ? src1 : src0; \
+}
+DEF(char, char)
+DEF(char, uchar)
+DEF(uchar, char)
+DEF(uchar, uchar)
+DEF(short, short)
+DEF(short, ushort)
+DEF(ushort, short)
+DEF(ushort, ushort)
+DEF(int, int)
+DEF(int, uint)
+DEF(uint, int)
+DEF(uint, uint)
+DEF(long, long)
+DEF(long, ulong)
+DEF(ulong, long)
+DEF(ulong, ulong)
+DEF(float, int)
+DEF(float, uint)
+#undef DEF
+
diff --git a/backend/src/libocl/script/ocl_relational.def b/backend/src/libocl/script/ocl_relational.def
new file mode 100644
index 0000000..379c511
--- /dev/null
+++ b/backend/src/libocl/script/ocl_relational.def
@@ -0,0 +1,34 @@
+##relational
+intn isequal (floatn x, floatn y)
+longn isequal (doublen x, doublen y)
+intn isnotequal (floatn x, floatn y)
+longn isnotequal (doublen x, doublen y)
+intn isgreater (floatn x, floatn y)
+longn isgreater (doublen x, doublen y)
+intn isgreaterequal (floatn x, floatn y)
+longn isgreaterequal (doublen x, doublen y)
+intn isless (floatn x, floatn y)
+longn isless (doublen x, doublen y)
+intn islessequal (floatn x, floatn y)
+longn islessequal (doublen x, doublen y)
+intn islessgreater (floatn x, floatn y)
+longn islessgreater (doublen x, doublen y)
+intn isfinite (floatn
+longn isfinite (doublen)
+intn isinf (floatn)
+longn isinf (doublen)
+intn isnan (floatn)
+longn isnan (doublen)
+intn isnormal (floatn)
+longn isnormal (doublen)
+intn isordered (floatn x, floatn y)
+longn isordered (doublen x, doublen y)
+intn isunordered (floatn x, floatn y)
+longn isunordered (doublen x, doublen y)
+intn signbit (floatn)
+longn signbit (doublen)
+int any (igentype x)
+int all (igentype x)
+gentype bitselect (gentype a, gentype b, gentype c)
+gentype select (gentype a, gentype b, igentype c)
+gentype select (gentype a, gentype b, ugentype c)
-- 
1.8.3.2



More information about the Beignet mailing list