diff options
author | rander <rander.wang@intel.com> | 2017-03-31 14:55:21 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2017-04-17 16:08:49 +0800 |
commit | c6090182c7ea1527afd28303dc9c3bdd7a9e3321 (patch) | |
tree | d5b3440ac9e6dbd957f34e4a5910e102096b18c0 | |
parent | 9b7a7955e1b992c947a595b5d82ca89fbe7cd73c (diff) |
backend: add double version of remquo
cp from fdlibm, need to be refined to pass cft
Signed-off-by: rander <rander.wang@intel.com>
Tested-by: Yang Rong <rong.r.yang@intel.com>
-rw-r--r-- | backend/src/libocl/tmpl/ocl_math.tmpl.cl | 145 | ||||
-rw-r--r-- | backend/src/libocl/tmpl/ocl_math.tmpl.h | 4 | ||||
-rw-r--r-- | backend/src/libocl/tmpl/ocl_math_20.tmpl.cl | 49 | ||||
-rw-r--r-- | backend/src/libocl/tmpl/ocl_math_20.tmpl.h | 1 |
4 files changed, 199 insertions, 0 deletions
diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl b/backend/src/libocl/tmpl/ocl_math.tmpl.cl index 3ea97510..850d198c 100644 --- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl +++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl @@ -4465,5 +4465,150 @@ OVERLOADABLE double lgamma_r(double x, private int *signgamp) return r; } +OVERLOADABLE double remquo(double x, double p, global int *quo) +{ + int hx,hp; + unsigned sx,lx,lp; + double p_half, zero = 0.0; + double xx = x; + + hx = __HI(x); /* high word of x */ + lx = __LO(x); /* low word of x */ + hp = __HI(p); /* high word of p */ + lp = __LO(p); /* low word of p */ + sx = hx&0x80000000; + hp &= 0x7fffffff; + hx &= 0x7fffffff; + + /* purge off exception values */ + if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */ + if((hx>=0x7ff00000)|| /* x not finite */ + ((hp>=0x7ff00000)&& /* p is NaN */ + (((hp-0x7ff00000)|lp)!=0))) + return (x*p)/(x*p); + + + if (hp<=0x7fdfffff) x = fmod(x,p+p); /* now x < 2p */ + if (((hx-hp)|(lx-lp))==0) return zero*x; + x = fabs(x); + p = fabs(p); + if (hp<0x00200000) + { + if(x+x>p) { + x-=p; + if(x+x>=p) x -= p; + } + } + else + { + p_half = 0.5*p; + if(x>p_half) + { + x-=p; + if(x>=p_half) x -= p; + } + } + __setHigh(&x, __HI(x) ^sx); + *quo = (xx -x)/p; + return x; +} + +OVERLOADABLE double remquo(double x, double p, local int *quo) +{ + int hx,hp; + unsigned sx,lx,lp; + double p_half, zero = 0.0; + double xx = x; + + hx = __HI(x); /* high word of x */ + lx = __LO(x); /* low word of x */ + hp = __HI(p); /* high word of p */ + lp = __LO(p); /* low word of p */ + sx = hx&0x80000000; + hp &= 0x7fffffff; + hx &= 0x7fffffff; + + /* purge off exception values */ + if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */ + if((hx>=0x7ff00000)|| /* x not finite */ + ((hp>=0x7ff00000)&& /* p is NaN */ + (((hp-0x7ff00000)|lp)!=0))) + return (x*p)/(x*p); + + + if (hp<=0x7fdfffff) x = fmod(x,p+p); /* now x < 2p */ + if (((hx-hp)|(lx-lp))==0) return zero*x; + x = fabs(x); + p = fabs(p); + if (hp<0x00200000) + { + if(x+x>p) { + x-=p; + if(x+x>=p) x -= p; + } + } + else + { + p_half = 0.5*p; + if(x>p_half) + { + x-=p; + if(x>=p_half) x -= p; + } + } + __setHigh(&x, __HI(x) ^sx); + *quo = (xx -x)/p; + return x; + +} + +OVERLOADABLE double remquo(double x, double p, private int *quo) +{ + int hx,hp; + unsigned sx,lx,lp; + double p_half, zero = 0.0; + double xx = x; + + hx = __HI(x); /* high word of x */ + lx = __LO(x); /* low word of x */ + hp = __HI(p); /* high word of p */ + lp = __LO(p); /* low word of p */ + sx = hx&0x80000000; + hp &= 0x7fffffff; + hx &= 0x7fffffff; + + /* purge off exception values */ + if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */ + if((hx>=0x7ff00000)|| /* x not finite */ + ((hp>=0x7ff00000)&& /* p is NaN */ + (((hp-0x7ff00000)|lp)!=0))) + return (x*p)/(x*p); + + + if (hp<=0x7fdfffff) x = fmod(x,p+p); /* now x < 2p */ + if (((hx-hp)|(lx-lp))==0) return zero*x; + x = fabs(x); + p = fabs(p); + if (hp<0x00200000) + { + if(x+x>p) { + x-=p; + if(x+x>=p) x -= p; + } + } + else + { + p_half = 0.5*p; + if(x>p_half) + { + x-=p; + if(x>=p_half) x -= p; + } + } + __setHigh(&x, __HI(x) ^sx); + *quo = (xx -x)/p; + return x; + +} diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.h b/backend/src/libocl/tmpl/ocl_math.tmpl.h index 936f72f6..1619210e 100644 --- a/backend/src/libocl/tmpl/ocl_math.tmpl.h +++ b/backend/src/libocl/tmpl/ocl_math.tmpl.h @@ -243,4 +243,8 @@ OVERLOADABLE double frexp(double x, private int *exp); OVERLOADABLE double lgamma_r(double x, global int *signgamp); OVERLOADABLE double lgamma_r(double x, local int *signgamp); OVERLOADABLE double lgamma_r(double x, private int *signgamp); +OVERLOADABLE double remquo(double x, double y, global int *quo); +OVERLOADABLE double remquo(double x, double y, local int *quo); +OVERLOADABLE double remquo(double x, double y, private int *quo); + diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl index 50fbff28..dd35b84b 100644 --- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl +++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.cl @@ -4020,4 +4020,53 @@ OVERLOADABLE double lgamma_r(double x, int *signgamp) return r; } +OVERLOADABLE double remquo(double x, double p, int *quo) +{ + int hx,hp; + unsigned sx,lx,lp; + double p_half, zero = 0.0; + double xx = x; + + hx = __HI(x); /* high word of x */ + lx = __LO(x); /* low word of x */ + hp = __HI(p); /* high word of p */ + lp = __LO(p); /* low word of p */ + sx = hx&0x80000000; + hp &= 0x7fffffff; + hx &= 0x7fffffff; + + /* purge off exception values */ + if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */ + if((hx>=0x7ff00000)|| /* x not finite */ + ((hp>=0x7ff00000)&& /* p is NaN */ + (((hp-0x7ff00000)|lp)!=0))) + return (x*p)/(x*p); + + + if (hp<=0x7fdfffff) x = fmod(x,p+p); /* now x < 2p */ + if (((hx-hp)|(lx-lp))==0) return zero*x; + x = fabs(x); + p = fabs(p); + if (hp<0x00200000) + { + if(x+x>p) { + x-=p; + if(x+x>=p) x -= p; + } + } + else + { + p_half = 0.5*p; + if(x>p_half) + { + x-=p; + if(x>=p_half) x -= p; + } + } + __setHigh(&x, __HI(x) ^sx); + *quo = (xx -x)/p; + return x; + +} + diff --git a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h index 419f06e1..79383ef5 100644 --- a/backend/src/libocl/tmpl/ocl_math_20.tmpl.h +++ b/backend/src/libocl/tmpl/ocl_math_20.tmpl.h @@ -214,4 +214,5 @@ OVERLOADABLE float half_tan(float x); OVERLOADABLE double fract(double x, double *p); OVERLOADABLE double frexp(double x, int *exp); OVERLOADABLE double lgamma_r(double x, int *signgamp); +OVERLOADABLE double remquo(double x, double y, int *quo); |