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

rander rander.wang at intel.com
Fri Mar 24 06:37:50 UTC 2017


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

diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
index 3534ef1..7e05b8f 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
@@ -4287,4 +4287,21 @@ OVERLOADABLE double log1p(double x)
 
 }
 
+OVERLOADABLE double logb(double x)
+{
+	int lx,ix;
+	ix = (__HI(x))&0x7fffffff;	/* high |x| */
+	lx = __LO(x);			/* low x */
+	if((ix|lx)==0) return -1.0/fabs(x);
+	if(ix>=0x7ff00000) return x*x;
+	if((ix>>=20)==0) 			/* IEEE 754 logb */
+	{
+		long qx = as_long(x);
+		qx = qx & DF_ABS_MASK;
+		int msbOne = clz(qx);
+		return (double)(-1022 - (53 -(64 -msbOne)));
+	}
+	else
+		return (double) (ix-1023);
+}
 
diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.h b/backend/src/libocl/tmpl/ocl_math.tmpl.h
index 5f715bb..bea8335 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.h
@@ -243,4 +243,5 @@ OVERLOADABLE double log(double x);
 OVERLOADABLE double log2(double x);
 OVERLOADABLE double log10(double x);
 OVERLOADABLE double log1p(double x);
+OVERLOADABLE double logb(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 f42cd0c..a7ec3aa 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
@@ -4163,4 +4163,21 @@ OVERLOADABLE double log1p(double x)
 
 }
 
+OVERLOADABLE double logb(double x)
+{
+	int lx,ix;
+	ix = (__HI(x))&0x7fffffff;	/* high |x| */
+	lx = __LO(x);			/* low x */
+	if((ix|lx)==0) return -1.0/fabs(x);
+	if(ix>=0x7ff00000) return x*x;
+	if((ix>>=20)==0) 			/* IEEE 754 logb */
+	{
+		long qx = as_long(x);
+		qx = qx & DF_ABS_MASK;
+		int msbOne = clz(qx);
+		return (double)(-1022 - (53 -(64 -msbOne)));
+	}
+	else
+		return (double) (ix-1023);
+}
 
diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
index 397db24..48dda70 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
@@ -220,5 +220,6 @@ OVERLOADABLE double log(double x);
 OVERLOADABLE double log2(double x);
 OVERLOADABLE double log10(double x);
 OVERLOADABLE double log1p(double x);
+OVERLOADABLE double logb(double x);
 
 
-- 
2.7.4



More information about the Beignet mailing list