[Beignet] [PATCH] backend: add double support to floor
rander
rander.wang at intel.com
Thu Mar 23 08:41:09 UTC 2017
do bit operations according to IEEE754 spec
Signed-off-by: rander <rander.wang at intel.com>
---
backend/src/libocl/tmpl/ocl_math.tmpl.cl | 33 +++++++++++++++++++++++++++++
backend/src/libocl/tmpl/ocl_math.tmpl.h | 2 +-
backend/src/libocl/tmpl/ocl_math_20.tmpl.cl | 33 +++++++++++++++++++++++++++++
backend/src/libocl/tmpl/ocl_math_20.tmpl.h | 3 +--
4 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
index 83af1c6..bb9bc4d 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
@@ -3931,3 +3931,36 @@ OVERLOADABLE double fabs(double x)
return as_double(qw);
}
+OVERLOADABLE double floor(double x)
+{
+ ulong lval = as_ulong(x);
+ int exp = ((lval >> 52) & 0x7FF) - 1023;
+ int sign = (lval >> 63) & 0x1;
+ if(exp < 0)
+ {
+ if(sign)
+ {
+ if(lval & DF_ABS_MASK)
+ return -1L;
+ else
+ return 0.0;
+ }
+ else return 0.0;
+ }
+ else
+ {
+ if(exp >= 52)
+ return x;
+ long i = (1L << (52 - exp));
+ i = 0x10000000000000 - i;
+ unsigned long uv = 0xFFF0000000000000 + i;
+ ulong vv = lval & uv;
+ double dp = as_double(vv);
+ if(vv != lval)
+ dp -= sign;
+
+ return dp;
+ }
+}
+
+
diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.h b/backend/src/libocl/tmpl/ocl_math.tmpl.h
index dab45ae..f699ab2 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.h
@@ -235,4 +235,4 @@ OVERLOADABLE float half_tan(float x);
//------- double -----------
OVERLOADABLE double ceil(double x);
OVERLOADABLE double fabs(double x);
-
+OVERLOADABLE double floor(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 83c889a..a032f59 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
@@ -3832,3 +3832,36 @@ OVERLOADABLE double fabs(double x)
return as_double(qw);
}
+OVERLOADABLE double floor(double x)
+{
+ ulong lval = as_ulong(x);
+ int exp = ((lval >> 52) & 0x7FF) - 1023;
+ int sign = (lval >> 63) & 0x1;
+ if(exp < 0)
+ {
+ if(sign)
+ {
+ if(lval & DF_ABS_MASK)
+ return -1L;
+ else
+ return 0.0;
+ }
+ else return 0.0;
+ }
+ else
+ {
+ if(exp >= 52)
+ return x;
+ long i = (1L << (52 - exp));
+ i = 0x10000000000000 - i;
+ unsigned long uv = 0xFFF0000000000000 + i;
+ ulong vv = lval & uv;
+ double dp = as_double(vv);
+ if(vv != lval)
+ dp -= sign;
+
+ return dp;
+ }
+}
+
+
diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
index 76778dd..bf7ac13 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
@@ -212,5 +212,4 @@ OVERLOADABLE float half_tan(float x);
//------- double -----------
OVERLOADABLE double ceil(double x);
OVERLOADABLE double fabs(double x);
-
-
+OVERLOADABLE double floor(double x);
--
2.7.4
More information about the Beignet
mailing list