[Beignet] [PATCH] fix builtin function 'frexp'

Yang, Rong R rong.r.yang at intel.com
Wed Nov 6 21:31:31 PST 2013


LGTM, thanks.

-----Original Message-----
From: beignet-bounces+rong.r.yang=intel.com at lists.freedesktop.org [mailto:beignet-bounces+rong.r.yang=intel.com at lists.freedesktop.org] On Behalf Of Homer Hsing
Sent: Wednesday, November 06, 2013 9:05 AM
To: beignet at lists.freedesktop.org
Subject: [Beignet] [PATCH] fix builtin function 'frexp'

returns correct value for nan or inf.
also returns correct value for very small float value.

Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 backend/src/ocl_stdlib.tmpl.h | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index cd14535..cfb5b2c 100644
--- a/backend/src/ocl_stdlib.tmpl.h
+++ b/backend/src/ocl_stdlib.tmpl.h
@@ -1636,17 +1636,28 @@ DECL_MIN_MAX_CLAMP(ulong)  #undef DECL_MIN_MAX_CLAMP
 
 #define BODY \
-  uint u = as_uint(x); \
-  if ((u & 0x7FFFFFFFu) == 0) { \
+  if (isnan(x) || isinf(x)) { \
     *exp = 0; \
     return x; \
   } \
-  int e = (u >> 23) & 255; \
-  if (e == 255) \
+  uint u = as_uint(x); \
+  uint a = u & 0x7FFFFFFFu; \
+  if (a == 0) { \
+    *exp = 0; \
     return x; \
-  *exp = e - 126; \
-  u = (u & (0x807FFFFFu)) | 0x3F000000; \
-  return as_float(u);
+  } \
+  if (a >= 0x800000) { \
+    *exp = (a >> 23) - 126; \
+    return as_float((u & (0x807FFFFFu)) | 0x3F000000); \  } \  int e = 
+ -126; \  while (a < 0x400000) { \
+    e --; \
+    a <<= 1; \
+  } \
+  a <<= 1; \
+  *exp = e; \
+  return as_float((a & (0x807FFFFFu)) | (u & 0x80000000u) | 
+ 0x3F000000);
 INLINE_OVERLOADABLE float frexp(float x, global int *exp) { BODY; }  INLINE_OVERLOADABLE float frexp(float x, local int *exp) { BODY; }  INLINE_OVERLOADABLE float frexp(float x, private int *exp) { BODY; }
--
1.8.3.2

_______________________________________________
Beignet mailing list
Beignet at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list