From 18c49179cd9cd92dac5007f1b9bc0542478cb3c8 Mon Sep 17 00:00:00 2001 From: Homer Hsing Date: Fri, 8 Nov 2013 15:35:41 +0800 Subject: [PATCH] fix builtin function "fmax" if an parameter is nan, then returns another parameter. v2: no need to test nan for integer Signed-off-by: Homer Hsing Reviewed-by: Zhigang Gong --- backend/src/ocl_stdlib.tmpl.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index 7af39ce..50795ef 100644 --- a/backend/src/ocl_stdlib.tmpl.h +++ b/backend/src/ocl_stdlib.tmpl.h @@ -1608,7 +1608,6 @@ INLINE_OVERLOADABLE TYPE min(TYPE a, TYPE b) { \ INLINE_OVERLOADABLE TYPE clamp(TYPE v, TYPE l, TYPE u) { \ return max(min(v, u), l); \ } -DECL_MIN_MAX_CLAMP(float) DECL_MIN_MAX_CLAMP(int) DECL_MIN_MAX_CLAMP(short) DECL_MIN_MAX_CLAMP(char) @@ -1618,6 +1617,19 @@ DECL_MIN_MAX_CLAMP(unsigned char) DECL_MIN_MAX_CLAMP(long) DECL_MIN_MAX_CLAMP(ulong) #undef DECL_MIN_MAX_CLAMP +INLINE_OVERLOADABLE float max(float a, float b) { + if(isnan(b)) + return a; + return a > b ? a : b; +} +INLINE_OVERLOADABLE float min(float a, float b) { + if(isnan(b)) + return a; + return a < b ? a : b; +} +INLINE_OVERLOADABLE float clamp(float v, float l, float u) { + return max(min(v, u), l); +} #define BODY \ if (isnan(x) || isinf(x)) { \ -- 2.7.4