[Beignet] [PATCH] backend: add double support to ceil

rander rander.wang at intel.com
Wed Mar 22 06:01:04 UTC 2017


	do bit operations according IEEE754 spec

Signed-off-by: rander <rander.wang at intel.com>
---
 backend/src/libocl/tmpl/ocl_math.tmpl.cl    | 28 ++++++++++++++++++++++++++++
 backend/src/libocl/tmpl/ocl_math.tmpl.h     |  4 ++++
 backend/src/libocl/tmpl/ocl_math_20.tmpl.cl | 26 ++++++++++++++++++++++++++
 backend/src/libocl/tmpl/ocl_math_20.tmpl.h  |  5 +++++
 4 files changed, 63 insertions(+)

diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
index 9f10713..9cded64 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
@@ -20,6 +20,7 @@
 #include "ocl_relational.h"
 #include "ocl_common.h"
 #include "ocl_integer.h"
+#include "ocl_convert.h"
 
 extern constant int __ocl_math_fastpath_flag;
 
@@ -3895,3 +3896,30 @@ OVERLOADABLE half rootn(half x, int n) {
   float _x = (float)x;
   return (half)rootn(_x, n);
 }
+
+
+
+//-----------------double -----------------------
+
+OVERLOADABLE double ceil(double x)
+{
+    double ret;
+    ulong lval = as_ulong(x);
+    int exp = ((lval >> 52) & 0x7FF) - 1023;
+    int sign = (lval >> 63) & 0x1;
+
+    long i = (1L << (52 - exp));
+    long mask = 0x10000000000000 - i;
+    unsigned long uv = 0xFFF0000000000000 + mask;
+    ulong vv = lval & uv;
+    double	dp = as_double(vv);
+    ret = ((vv != lval) && !sign) ? dp +1.0:dp;
+
+    ret = ((exp < 0) && sign) ? 0:ret;
+    double tmp = (lval & DF_ABS_MASK) ? 1.0:0.0;
+    ret = ((exp < 0) && !sign) ? tmp:ret;
+    ret = (exp >= 52) ? x:ret;
+
+     return ret;
+}
+
diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.h b/backend/src/libocl/tmpl/ocl_math.tmpl.h
index 0de3642..fb126ed 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.h
@@ -231,3 +231,7 @@ OVERLOADABLE float half_rsqrt(float x);
 OVERLOADABLE float half_sin(float x);
 OVERLOADABLE float half_sqrt(float x);
 OVERLOADABLE float half_tan(float x);
+
+//------- double -----------
+OVERLOADABLE double ceil(double x);
+
diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
index d47e0a2..25ef835 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
@@ -3799,3 +3799,29 @@ OVERLOADABLE half rootn(half x, int n) {
   float _x = (float)x;
   return (half)rootn(_x, n);
 }
+
+
+//-----------------double -----------------------
+
+OVERLOADABLE double ceil(double x)
+{
+    double ret;
+    ulong lval = as_ulong(x);
+    int exp = ((lval >> 52) & 0x7FF) - 1023;
+    int sign = (lval >> 63) & 0x1;
+
+    long i = (1L << (52 - exp));
+    long mask = 0x10000000000000 - i;
+    unsigned long uv = 0xFFF0000000000000 + mask;
+    ulong vv = lval & uv;
+    double	dp = as_double(vv);
+    ret = ((vv != lval) && !sign) ? dp +1.0:dp;
+
+    ret = ((exp < 0) && sign) ? 0:ret;
+    double tmp = (lval & DF_ABS_MASK) ? 1.0:0.0;
+    ret = ((exp < 0) && !sign) ? tmp:ret;
+    ret = (exp >= 52) ? x:ret;
+
+     return ret;
+}
+
diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
index 271075c..3b10595 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
@@ -207,3 +207,8 @@ OVERLOADABLE float half_rsqrt(float x);
 OVERLOADABLE float half_sin(float x);
 OVERLOADABLE float half_sqrt(float x);
 OVERLOADABLE float half_tan(float x);
+
+
+//------- double -----------
+OVERLOADABLE double ceil(double x);
+
-- 
2.7.4



More information about the Beignet mailing list