[Beignet] [PATCH] fix builtin function "fract"

Xing, Homer homer.xing at intel.com
Wed Nov 6 22:35:56 PST 2013


This patch has already considered " +inf" and "-inf". It distinguishes +inf and -inf, following the spec.

-----Original Message-----
From: Yang, Rong R 
Sent: Thursday, November 7, 2013 1:14 PM
To: Xing, Homer; beignet at lists.freedesktop.org
Subject: RE: [Beignet] [PATCH] fix builtin function "fract"

Hi,

In openCL spec:
fract ( +inf, iptr ) returns +0 and +inf in iptr.
fract ( -inf, iptr ) returns -0 and -inf in iptr.

So should distinguish +inf and -inf.

-----Original Message-----
From: beignet-bounces at lists.freedesktop.org [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of Homer Hsing
Sent: Tuesday, November 05, 2013 4:27 PM
To: beignet at lists.freedesktop.org
Subject: [Beignet] [PATCH] fix builtin function "fract"

return nan for nan, zero for inf

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

diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index 01216ae..cd14535 100644
--- a/backend/src/ocl_stdlib.tmpl.h
+++ b/backend/src/ocl_stdlib.tmpl.h
@@ -1717,7 +1717,14 @@ INLINE_OVERLOADABLE float __gen_ocl_internal_fdim(float x, float y) {
   return __gen_ocl_internal_fmax(x, y) - y;  }  #define BODY \
+  if (isnan(x)) { \
+    *p = x; \
+    return x; \
+  } \
   *p = __gen_ocl_internal_floor(x); \
+  if (isinf(x)) { \
+    return 0; \
+  } \
   return __gen_ocl_internal_fmin(x - *p, 0x1.FFFFFep-1F);  INLINE_OVERLOADABLE float fract(float x, global float *p) { BODY; }  INLINE_OVERLOADABLE float fract(float x, local float *p) { 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