[Beignet] [PATCH 08/19] libocl: Add half builtin functions for relational module.
junyan.he at inbox.com
junyan.he at inbox.com
Thu Jun 11 04:24:40 PDT 2015
From: Junyan He <junyan.he at linux.intel.com>
Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
backend/src/libocl/tmpl/ocl_relational.tmpl.cl | 66 +++++++++++++++++++++++++-
backend/src/libocl/tmpl/ocl_relational.tmpl.h | 23 ++++++++-
2 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/backend/src/libocl/tmpl/ocl_relational.tmpl.cl b/backend/src/libocl/tmpl/ocl_relational.tmpl.cl
index 1100815..f66b6c1 100644
--- a/backend/src/libocl/tmpl/ocl_relational.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_relational.tmpl.cl
@@ -68,7 +68,6 @@ OVERLOADABLE int isnormal(float x) {
return (u.u < 0x7F800000) && (u.u >= 0x800000);
}
-
OVERLOADABLE int isordered(float x, float y) {
return isequal(x, x) && isequal(y, y);
}
@@ -82,6 +81,71 @@ OVERLOADABLE int signbit(float x) {
}
+// Half float version.
+OVERLOADABLE int isequal(half x, half y) {
+ return x == y;
+}
+
+OVERLOADABLE int isnotequal(half x, half y) {
+ return x != y;
+}
+
+OVERLOADABLE int isgreater(half x, half y) {
+ return x > y;
+}
+
+OVERLOADABLE int isgreaterequal(half x, half y) {
+ return x >= y;
+}
+
+OVERLOADABLE int isless(half x, half y) {
+ return x < y;
+}
+
+OVERLOADABLE int islessequal(half x, half y) {
+ return x <= y;
+}
+
+OVERLOADABLE int islessgreater(half x, half y) {
+ return (x < y) || (x > y);
+}
+
+OVERLOADABLE int isfinite(half x) {
+ union { ushort u; half h; } u;
+ u.h = x;
+ return (u.u & 0x7FFF) < 0x7C00;
+}
+
+OVERLOADABLE int isinf(half x) {
+ union { ushort u; half h; } u;
+ u.h = x;
+ return (u.u & 0x7FFF) == 0x7C00;
+}
+
+OVERLOADABLE int isnan(half x) {
+ return x != x;
+}
+
+OVERLOADABLE int isnormal(half x) {
+ union { ushort u; half h; } u;
+ u.h = x;
+ u.u &= 0x7FFF;
+ return (u.u < 0x7C00) && (u.u >= 0x400);
+}
+
+OVERLOADABLE int isordered(half x, half y) {
+ return isequal(x, x) && isequal(y, y);
+}
+OVERLOADABLE int isunordered(half x, half y) {
+ return isnan(x) || isnan(y);
+}
+OVERLOADABLE int signbit(half x) {
+ union { ushort u; half h; } u;
+ u.h = x;
+ return u.u >> 15;
+}
+
+
// 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; }
diff --git a/backend/src/libocl/tmpl/ocl_relational.tmpl.h b/backend/src/libocl/tmpl/ocl_relational.tmpl.h
index 9921317..0ec0cbe 100644
--- a/backend/src/libocl/tmpl/ocl_relational.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_relational.tmpl.h
@@ -34,11 +34,29 @@ 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);
+// Half half version.
+OVERLOADABLE int isequal(half x, half y);
+OVERLOADABLE int isnotequal(half x, half y);
+OVERLOADABLE int isgreater(half x, half y);
+OVERLOADABLE int isgreaterequal(half x, half y);
+OVERLOADABLE int isless(half x, half y);
+OVERLOADABLE int islessequal(half x, half y);
+OVERLOADABLE int islessgreater(half x, half y);
+
+OVERLOADABLE int isfinite(half x);
+OVERLOADABLE int isinf(half x);
+OVERLOADABLE int isnan(half x);
+OVERLOADABLE int isnormal(half x);
+
+OVERLOADABLE int isordered(half x, half y);
+OVERLOADABLE int isunordered(half x, half y);
+OVERLOADABLE int signbit(half x);
+
+
// any
#define DEC1(type) OVERLOADABLE int any(type a);
#define DEC2(type) OVERLOADABLE int any(type a);
@@ -94,6 +112,7 @@ 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);
+OVERLOADABLE half bitselect(half a, half b, half c);
#define DEF(TYPE1, TYPE2) \
@@ -116,4 +135,6 @@ DEF(ulong, long)
DEF(ulong, ulong)
DEF(float, int)
DEF(float, uint)
+DEF(half, short)
+DEF(half, ushort)
#undef DEF
--
1.9.1
More information about the Beignet
mailing list