[Beignet] [PATCH] GBE: Fix logb implementation.

Song, Ruiling ruiling.song at intel.com
Tue Dec 17 22:43:59 PST 2013


Ping for review. Thanks!

-----Original Message-----
From: Song, Ruiling 
Sent: Wednesday, December 11, 2013 2:38 PM
To: beignet at lists.freedesktop.org
Cc: Song, Ruiling
Subject: [PATCH] GBE: Fix logb implementation.

Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
 backend/src/ocl_stdlib.tmpl.h |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index e5f356e..673c849 100644
--- a/backend/src/ocl_stdlib.tmpl.h
+++ b/backend/src/ocl_stdlib.tmpl.h
@@ -1586,7 +1586,20 @@ INLINE_OVERLOADABLE float log1p(float x) {
      return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f);
 
 }
-INLINE_OVERLOADABLE float logb(float x) { return __gen_ocl_rndd(native_log2(x)); }
+INLINE_OVERLOADABLE float logb(float x) { union {float f; unsigned i;} 
+u;
+  u.f = x;
+  int e =  ((u.i & 0x7f800000) >> 23);
+  if(e == 0) {
+    /* sub normal or +/-0 */
+    return -INFINITY;
+  } else if(e == 0xff) {
+    /* inf & nan */
+    return x*x;
+  } else {
+    return (float)(e-127);
+  }
+}
 #define FP_ILOGB0 (-0x7FFFFFFF-1)
 #define FP_ILOGBNAN FP_ILOGB0
 INLINE_OVERLOADABLE int ilogb(float x) {
--
1.7.9.5



More information about the Beignet mailing list