[Beignet] [PATCH] backend: add double version of atanh

rander rander.wang at intel.com
Thu Mar 30 06:29:46 UTC 2017


	cp from fdlibm and pass the cft after refined

Signed-off-by: rander <rander.wang at intel.com>
---
 backend/src/libocl/tmpl/ocl_math_common.tmpl.cl | 26 +++++++++++++++++++++++++
 backend/src/libocl/tmpl/ocl_math_common.tmpl.h  |  1 +
 2 files changed, 27 insertions(+)

diff --git a/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl b/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl
index 363523d..819dc26 100644
--- a/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl
@@ -406,6 +406,32 @@ OVERLOADABLE double atan2pi(double x, double y)
 	return atan2(x, y)/M_PI;
 }
 
+OVERLOADABLE double atanh(double x)
+{
+		double one = 1.0, huge = 1e300;
+
+	double t, zero = 0;
+	int hx,ix;
+	unsigned lx;
+	hx = __HI(x);		/* high word */
+	lx = __LO(x);		/* low word */
+	ix = hx&0x7fffffff;
+	if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */
+		return (x-x)/(x-x);
+	if(ix==0x3ff00000)
+		return x/zero;
+	if(ix<0x3e300000&&(huge+x)>zero) return x;	/* x<2**-28 */
+	__setHigh(&x, ix);		/* x <- |x| */
+	if(ix<0x3fe00000) {		/* x < 0.5 */
+		t = x+x;
+		t = 0.5*log1p(t+t*x/(one-x));
+	} else
+		t = 0.5*log1p((x+x)/(one-x));
+	if(hx>=0) return t; else return -t;
+
+		return 0.0;
+}
+
 OVERLOADABLE double ceil(double x)
 {
     double ret;
diff --git a/backend/src/libocl/tmpl/ocl_math_common.tmpl.h b/backend/src/libocl/tmpl/ocl_math_common.tmpl.h
index 22c1d0d..76ce952 100644
--- a/backend/src/libocl/tmpl/ocl_math_common.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math_common.tmpl.h
@@ -30,6 +30,7 @@ OVERLOADABLE double atan(double x);
 OVERLOADABLE double atan2(double x, double y);
 OVERLOADABLE double atanpi(double x);
 OVERLOADABLE double atan2pi(double x, double y);
+OVERLOADABLE double atanh(double x);
 OVERLOADABLE double ceil(double x);
 OVERLOADABLE double copysign(double x, double y);
 OVERLOADABLE double fabs(double x);
-- 
2.7.4



More information about the Beignet mailing list