[Beignet] [PATCH v2] fix builtin function "fmax"
Homer Hsing
homer.xing at intel.com
Thu Nov 7 23:35:41 PST 2013
if an parameter is nan, then returns another parameter.
v2: no need to test nan for integer
Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
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 bff2b1c..d613656 100644
--- a/backend/src/ocl_stdlib.tmpl.h
+++ b/backend/src/ocl_stdlib.tmpl.h
@@ -1629,7 +1629,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)
@@ -1639,6 +1638,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)) { \
--
1.8.3.2
More information about the Beignet
mailing list