[Beignet] [PATCH] backend: add double version of sinh
rander
rander.wang at intel.com
Thu Mar 30 07:14:07 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 | 40 +++++++++++++++++++++++++
backend/src/libocl/tmpl/ocl_math_common.tmpl.h | 1 +
2 files changed, 41 insertions(+)
diff --git a/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl b/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl
index 290ec6b..378b3b0 100644
--- a/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl
@@ -1732,6 +1732,46 @@ OVERLOADABLE double sin(double x)
}
}
+OVERLOADABLE double sinh(double x)
+{
+ double one = 1.0, shuge = 1.0e307;
+ double t,w,h;
+ int ix,jx;
+ unsigned lx;
+
+ /* High word of |x|. */
+ jx = __HI(x);
+ ix = jx&0x7fffffff;
+
+ /* x is INF or NaN */
+ if(ix>=0x7ff00000) return x+x;
+
+ h = 0.5;
+ if (jx<0) h = -h;
+ /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
+ if (ix < 0x40360000) { /* |x|<22 */
+ if (ix<0x3e300000) /* |x|<2**-28 */
+ if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
+ t = expm1(fabs(x));
+ if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
+ return h*(t+t/(t+one));
+ }
+
+ /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
+ if (ix < 0x40862E42) return h*exp(fabs(x));
+
+ /* |x| in [log(maxdouble), overflowthresold] */
+ lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x);
+ if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d))) {
+ w = exp(0.5*fabs(x));
+ t = h*w;
+ return t*w;
+ }
+
+ /* |x| > overflowthresold, sinh(x) overflow */
+ return x*shuge;
+}
+
OVERLOADABLE double sqrt(double x)
{
double z;
diff --git a/backend/src/libocl/tmpl/ocl_math_common.tmpl.h b/backend/src/libocl/tmpl/ocl_math_common.tmpl.h
index ba246cc..a7959d3 100644
--- a/backend/src/libocl/tmpl/ocl_math_common.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math_common.tmpl.h
@@ -55,6 +55,7 @@ OVERLOADABLE double nextafter(double x, double y);
OVERLOADABLE double rint(double x);
OVERLOADABLE double round(double x);
OVERLOADABLE double sin(double x);
+OVERLOADABLE double sinh(double x);
OVERLOADABLE double sqrt(double x);
OVERLOADABLE double trunc(double x);
--
2.7.4
More information about the Beignet
mailing list