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

Homer Hsing homer.xing at intel.com
Mon Nov 11 21:12:35 PST 2013


check whether input is NaN. fix the code if input is inf

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

diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h
index 3f642b7..bedfe02 100644
--- a/backend/src/ocl_stdlib.tmpl.h
+++ b/backend/src/ocl_stdlib.tmpl.h
@@ -1747,7 +1747,11 @@ INLINE_OVERLOADABLE float __gen_ocl_internal_minmag(float x, float y) {
 }
 INLINE_OVERLOADABLE float mix(float x, float y, float a) { return x + (y-x)*a;}
 INLINE_OVERLOADABLE float __gen_ocl_internal_fdim(float x, float y) {
-  return __gen_ocl_internal_fmax(x, y) - y;
+  if(isnan(x))
+    return x;
+  if(isnan(y))
+    return y;
+  return x > y ? (x - y) : +0.f;
 }
 #define BODY \
   if (isnan(x)) { \
-- 
1.8.3.2



More information about the Beignet mailing list