[Beignet] [PATCH] backend: add double support to trunc
rander
rander.wang at intel.com
Tue Mar 28 01:40:52 UTC 2017
do it according to spec:Round to integral value using the round to zero
rounding mode. just like floor with absolute input, then add sign
Signed-off-by: rander <rander.wang at intel.com>
---
backend/src/libocl/tmpl/ocl_math.tmpl.cl | 5 +++++
backend/src/libocl/tmpl/ocl_math.tmpl.h | 1 +
backend/src/libocl/tmpl/ocl_math_20.tmpl.cl | 6 ++++++
backend/src/libocl/tmpl/ocl_math_20.tmpl.h | 1 +
4 files changed, 13 insertions(+)
diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
index fec5a38..f7d599d 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
@@ -4403,5 +4403,10 @@ OVERLOADABLE double fmin(double a, double b)
return (c <= 0) ? a:b;
}
+OVERLOADABLE double trunc(double x)
+{
+ double ret = floor(fabs(x));
+ return copysign(ret, x);
+}
diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.h b/backend/src/libocl/tmpl/ocl_math.tmpl.h
index dca7f62..8318085 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.h
@@ -253,6 +253,7 @@ OVERLOADABLE double log1p(double x);
OVERLOADABLE double logb(double x);
OVERLOADABLE int ilogb(double x);
OVERLOADABLE double mad(double a, double b, double c);
+OVERLOADABLE double trunc(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 c43f817..941127f 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
@@ -4279,3 +4279,9 @@ OVERLOADABLE double fmin(double a, double b)
return (c <= 0) ? a:b;
}
+OVERLOADABLE double trunc(double x)
+{
+ double ret = floor(fabs(x));
+ return copysign(ret, x);
+}
+
diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
index 1d7434a..34e29e0 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
@@ -230,5 +230,6 @@ OVERLOADABLE double log1p(double x);
OVERLOADABLE double logb(double x);
OVERLOADABLE int ilogb(double x);
OVERLOADABLE double mad(double a, double b, double c);
+OVERLOADABLE double trunc(double x);
--
2.7.4
More information about the Beignet
mailing list