Hi: Why not using __gen_ocl_rndd(native_log2(x)) for common case?
-----Original Message----- From: beignet-boun...@lists.freedesktop.org [mailto:beignet-boun...@lists.freedesktop.org] On Behalf Of Homer Hsing Sent: Tuesday, November 05, 2013 3:48 PM To: beignet@lists.freedesktop.org Subject: [Beignet] [PATCH] fix builtin function "ilogb" add FP_ILOGB0, FP_ILOGBNAN return FP_ILOGB0 for zero. return FP_ILOGBNAN for nan. return INT_MAX for inf. also improve function code for other cases. Signed-off-by: Homer Hsing <homer.x...@intel.com> --- backend/src/ocl_stdlib.tmpl.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index a1f365c..01216ae 100644 --- a/backend/src/ocl_stdlib.tmpl.h +++ b/backend/src/ocl_stdlib.tmpl.h @@ -1303,7 +1303,28 @@ INLINE_OVERLOADABLE float native_log10(float x) { } INLINE_OVERLOADABLE float log1p(float x) { return native_log(x + 1); } INLINE_OVERLOADABLE float logb(float x) { return __gen_ocl_rndd(native_log2(x)); } -INLINE_OVERLOADABLE int ilogb(float x) { return __gen_ocl_rndd(native_log2(x)); } +#define FP_ILOGB0 (-0x7FFFFFFF-1) +#define FP_ILOGBNAN FP_ILOGB0 +INLINE_OVERLOADABLE int ilogb(float x) { + union { int i; float f; } u; + if (isnan(x)) + return FP_ILOGBNAN; + if (isinf(x)) + return 0x7FFFFFFF; + u.f = x; + u.i &= 0x7fffffff; + if (u.i == 0) + return FP_ILOGB0; + if (u.i >= 0x800000) + return (u.i >> 23) - 127; + int r = -126; + int a = u.i & 0x7FFFFF; + while(a < 0x800000) { + a <<= 1; + r --; + } + return r; +} INLINE_OVERLOADABLE float nan(uint code) { return NAN; } -- 1.8.3.2 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/beignet _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/beignet