[Beignet] [PATCH 1/2] libocl: Fix precision of builtin tanpi.
Ruiling Song
ruiling.song at intel.com
Mon Dec 8 18:24:43 PST 2014
This was originally submitted in f2111f368d9d7eeafe1762ecb0160d9da69d9214
But it was missed during libocl change. So add it back here.
Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
backend/src/libocl/tmpl/ocl_math.tmpl.cl | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
index 236fa0b..ddfde83 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
@@ -1528,7 +1528,33 @@ OVERLOADABLE float nan(uint code) {
return NAN;
}
OVERLOADABLE float __gen_ocl_internal_tanpi(float x) {
- return native_tan(x * M_PI_F);
+ float sign = 1.0f;
+ int ix;
+ if(isinf(x)) return NAN;
+ if(x < 0.0f) { x = -x; sign = -1.0f; }
+ GEN_OCL_GET_FLOAT_WORD(ix, x);
+ if(x> 0x1.0p24) return 0.0f;
+ float m = __gen_ocl_internal_floor(x);
+ ix = (int)m;
+ m = x-m;
+ int n = __gen_ocl_internal_floor(m*4.0f);
+ if(m == 0.5f) {
+ return (ix&0x1) == 0 ? sign*INFINITY : sign*-INFINITY;
+ }
+ if(m == 0.0f) {
+ return (ix&0x1) == 0 ? 0.0f : -0.0f;
+ }
+
+ switch(n) {
+ case 0:
+ return sign * __kernel_tanf(m*M_PI_F, 0.0f, 1);
+ case 1:
+ return sign * 1.0f/__kernel_tanf((0.5f-m)*M_PI_F, 0.0f, 1);
+ case 2:
+ return sign * 1.0f/__kernel_tanf((0.5f-m)*M_PI_F, 0.0f, 1);
+ default:
+ return sign * -1.0f*__kernel_tanf((1.0f-m)*M_PI_F, 0.0f, 1);
+ }
}
OVERLOADABLE float __gen_ocl_internal_cbrt(float x) {
/* copied from fdlibm */
--
1.7.10.4
More information about the Beignet
mailing list