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

rander rander.wang at intel.com
Tue Mar 28 02:12:22 UTC 2017


	copy from float version, and make it work with double type

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

diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
index ff75b1a..95fbf0b 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
@@ -4380,6 +4380,40 @@ OVERLOADABLE double nan(ulong code)
 	return as_double(DF_POSITIVE_INF + (code&DF_MAN_MASK));
 }
 
+OVERLOADABLE double nextafter(double x, double y)
+{
+	long hx, hy, ix, iy;
+	hx = as_long(x);
+	hy = as_long(y);
+	ix = hx & DF_ABS_MASK;
+	iy = hy & DF_ABS_MASK;
+
+	if(ix>DF_POSITIVE_INF|| iy>DF_POSITIVE_INF)
+	  return x+y;
+	if(hx == hy)
+	  return y;
+	if(ix == 0) {
+	  if(iy == 0)
+		return y;
+	  else
+		return as_double((hy&DF_SIGN_MASK) | 1);
+	}
+	if(hx >= 0) {
+	  if(hx > hy) {
+		hx -= 1;
+	  } else {
+		hx += 1;
+	  }
+	} else {
+	  if(hy >= 0 || hx > hy){
+		hx -= 1;
+	  } else {
+		hx += 1;
+	  }
+	}
+	return as_double(hx);
+}
+
 OVERLOADABLE double fmax(double a, double b)
 {
 	ulong ua = as_ulong(a);
diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.h b/backend/src/libocl/tmpl/ocl_math.tmpl.h
index 6dca21f..2e2938a 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.h
@@ -254,6 +254,7 @@ OVERLOADABLE double logb(double x);
 OVERLOADABLE int ilogb(double x);
 OVERLOADABLE double mad(double a, double b, double c);
 OVERLOADABLE double nan(ulong code);
+OVERLOADABLE double nextafter(double x, double y);
 OVERLOADABLE double rint(double x);
 OVERLOADABLE double round(double x);
 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 755bb9d..e639e27 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl
@@ -4256,6 +4256,40 @@ OVERLOADABLE double nan(ulong code)
 	return as_double(DF_POSITIVE_INF + (code&DF_MAN_MASK));
 }
 
+OVERLOADABLE double nextafter(double x, double y)
+{
+	long hx, hy, ix, iy;
+	hx = as_long(x);
+	hy = as_long(y);
+	ix = hx & DF_ABS_MASK;
+	iy = hy & DF_ABS_MASK;
+
+	if(ix>DF_POSITIVE_INF|| iy>DF_POSITIVE_INF)
+	  return x+y;
+	if(hx == hy)
+	  return y;
+	if(ix == 0) {
+	  if(iy == 0)
+		return y;
+	  else
+		return as_double((hy&DF_SIGN_MASK) | 1);
+	}
+	if(hx >= 0) {
+	  if(hx > hy) {
+		hx -= 1;
+	  } else {
+		hx += 1;
+	  }
+	} else {
+	  if(hy >= 0 || hx > hy){
+		hx -= 1;
+	  } else {
+		hx += 1;
+	  }
+	}
+	return as_double(hx);
+}
+
 OVERLOADABLE double fmax(double a, double b)
 {
 	ulong ua = as_ulong(a);
diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
index a753d52..4ef159c 100644
--- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
+++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h
@@ -231,6 +231,7 @@ OVERLOADABLE double logb(double x);
 OVERLOADABLE int ilogb(double x);
 OVERLOADABLE double mad(double a, double b, double c);
 OVERLOADABLE double nan(ulong code);
+OVERLOADABLE double nextafter(double x, double y);
 OVERLOADABLE double rint(double x);
 OVERLOADABLE double round(double x);
 OVERLOADABLE double trunc(double x);
-- 
2.7.4



More information about the Beignet mailing list