summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrander <rander.wang@intel.com>2017-05-19 11:01:49 +0800
committerYang Rong <rong.r.yang@intel.com>2017-05-23 19:08:50 +0800
commit6b8b74c9c1dd51bc185bf621927a056cbfc347b2 (patch)
treed35805c922e0c7d309c8dbe24d09d48b7531f9a6
parent007683f701a59e0e1cf0c55851f8da6a979761f7 (diff)
backend: fix tgamma error after restructure
Signed-off-by: rander.wang <rander.wang@intel.com> Reviewed-by: Pan Xiuli <xiuli.pan@intel.com>
-rw-r--r--backend/src/libocl/tmpl/ocl_math_common.tmpl.cl56
1 files changed, 31 insertions, 25 deletions
diff --git a/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl b/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl
index 9d4100e3..6b942dbe 100644
--- a/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl
@@ -2550,30 +2550,6 @@ OVERLOADABLE float __gen_ocl_internal_pow(float x, float y) {
return bRet ? retVal:sn*z;
}
-#define BODY \
- if (isnan(x_abs) || isinf(x_abs)) { \
- x_log2 = 0; \
- return x_abs; \
- } \
- uint u = as_uint(x_abs); \
- uint a = u & 0x7FFFFFFFu; \
- if (a == 0) { \
- x_log2 = 0; \
- return x_abs; \
- } \
- if (a >= 0x800000) { \
- x_log2 = (a >> 23) - 126; \
- return as_float((u & (0x807FFFFFu)) | 0x3F000000); \
- } \
- int e = -126; \
- while (a < 0x400000) { \
- e --; \
- a <<= 1; \
- } \
- a <<= 1; \
- x_log2 = e; \
- float x_mant = as_float((a & (0x807FFFFFu)) | (u & 0x80000000u) | 0x3F000000);
-
OVERLOADABLE float tgamma (float x)
{
/* based on glibc __ieee754_gammaf_r by Ulrich Drepper <drepper@cygnus.com> */
@@ -2641,8 +2617,38 @@ OVERLOADABLE float tgamma (float x)
float x_int = __gen_ocl_internal_round (x_abs);
float x_frac = x_abs - x_int;
int x_log2;
+ float x_mant;
+ bool skip = false;
+ if (isnan(x_abs) || isinf(x_abs)) {
+ x_log2 = 0;
+ x_mant = x_abs;
+ skip = true;
+ }
- BODY
+ uint u = as_uint(x_abs);
+ uint a = u & 0x7FFFFFFFu;
+ if (a == 0) {
+ x_log2 = 0;
+ x_mant = x_abs;
+ skip = true;
+ }
+ if (a >= 0x800000 && !skip) {
+ x_log2 = (a >> 23) - 126;
+ x_mant = as_float((u & (0x807FFFFFu)) | 0x3F000000);
+ skip = true;
+ }
+
+ int e = -126;
+ if(!skip)
+ {
+ while (a < 0x400000) {
+ e --;
+ a <<= 1;
+ }
+ a <<= 1;
+ x_log2 = e;
+ x_mant = as_float((a & (0x807FFFFFu)) | (u & 0x80000000u) | 0x3F000000);
+ }
if (x_mant < M_SQRT1_2_F)
{