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

rander rander.wang at intel.com
Fri Mar 24 01:44:05 UTC 2017


Signed-off-by: rander <rander.wang at intel.com>
---
 backend/src/libocl/tmpl/ocl_math.tmpl.cl    | 38 +++++++++++++++++++++++++++++
 backend/src/libocl/tmpl/ocl_math_20.tmpl.cl | 37 ++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
index f0c40fc..0adf49f 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
@@ -4171,3 +4171,41 @@ OVERLOADABLE double log2(double x)
 	}
 }
 
+OVERLOADABLE double log10(double x)
+{
+	double zero = 0.0,
+	two54	   =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
+	ivln10	   =  4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
+	log10_2hi  =  3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
+	log10_2lo  =  3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
+
+	double y,z;
+	int i,k,hx;
+	unsigned lx;
+
+	hx = __HI(x);	/* high word of x */
+	lx = __LO(x);	/* low word of x */
+
+	k=0;
+	if (hx < 0x00100000)
+	{  /* x < 2**-1022  */
+		if (((hx&0x7fffffff)|lx)==0)
+			return -two54/zero; /* log(+-0)=-inf */
+
+		if (hx<0)
+			return (x-x)/zero;/* log(-#) = NaN */
+
+		k -= 54; x *= two54; /* subnormal number, scale up x */
+		hx = __HI(x);/* high word of x */
+	}
+
+	if (hx >= 0x7ff00000) return x+x;
+	k += (hx>>20)-1023;
+	i  = ((unsigned)k&0x80000000)>>31;
+	hx = (hx&0x000fffff)|((0x3ff-i)<<20);
+	y  = (double)(k+i);
+	__setHigh(&x, hx);
+	z  = y*log10_2lo + ivln10*log(x);
+	return  z+y*log10_2hi;
+}
+
diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
index ea2ee37..38d5820 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
@@ -4047,5 +4047,42 @@ OVERLOADABLE double log2(double x)
 	}
 }
 
+OVERLOADABLE double log10(double x)
+{
+	double zero = 0.0,
+	two54	   =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
+	ivln10	   =  4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
+	log10_2hi  =  3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
+	log10_2lo  =  3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
+
+	double y,z;
+	int i,k,hx;
+	unsigned lx;
+
+	hx = __HI(x);	/* high word of x */
+	lx = __LO(x);	/* low word of x */
+
+	k=0;
+	if (hx < 0x00100000)
+	{  /* x < 2**-1022  */
+		if (((hx&0x7fffffff)|lx)==0)
+			return -two54/zero; /* log(+-0)=-inf */
+
+		if (hx<0)
+			return (x-x)/zero;/* log(-#) = NaN */
+
+		k -= 54; x *= two54; /* subnormal number, scale up x */
+		hx = __HI(x);/* high word of x */
+	}
+
+	if (hx >= 0x7ff00000) return x+x;
+	k += (hx>>20)-1023;
+	i  = ((unsigned)k&0x80000000)>>31;
+	hx = (hx&0x000fffff)|((0x3ff-i)<<20);
+	y  = (double)(k+i);
+	__setHigh(&x, hx);
+	z  = y*log10_2lo + ivln10*log(x);
+	return  z+y*log10_2hi;
+}
 
 
-- 
2.7.4



More information about the Beignet mailing list