[Libclc-dev] [PATCH 2/2] Implement fmax using __builtin_fmax

Tom Stellard thomas.stellard at amd.com
Thu Mar 19 13:30:06 PDT 2015


This ensures correct handling of NaN / INF.

This has been tested with piglit, OpenCV, and the ocl conformance tests.
---
 generic/include/clc/math/fmax.h |  5 +----
 generic/lib/math/fmax.cl        | 13 +++++++++----
 generic/lib/math/fmax.inc       | 18 ++++++++++++++++++
 3 files changed, 28 insertions(+), 8 deletions(-)
 create mode 100644 generic/lib/math/fmax.inc

diff --git a/generic/include/clc/math/fmax.h b/generic/include/clc/math/fmax.h
index d6956af..71ee859 100644
--- a/generic/include/clc/math/fmax.h
+++ b/generic/include/clc/math/fmax.h
@@ -1,8 +1,5 @@
-#undef fmax
-#define fmax __clc_fmax
-
 #define __CLC_BODY <clc/math/binary_decl.inc>
-#define __CLC_FUNCTION __clc_fmax
+#define __CLC_FUNCTION fmax
 
 #include <clc/math/gentype.inc>
 
diff --git a/generic/lib/math/fmax.cl b/generic/lib/math/fmax.cl
index 58583d6..239da3d 100644
--- a/generic/lib/math/fmax.cl
+++ b/generic/lib/math/fmax.cl
@@ -1,11 +1,16 @@
 #include <clc/clc.h>
 
+#include "../clcmacro.h"
+
+_CLC_DEFINE_BINARY_BUILTIN(float, fmax, __builtin_fmaxf, float, float);
+
 #ifdef cl_khr_fp64
+
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
-#endif
 
-#define FUNCTION __clc_fmax
-#define FUNCTION_IMPL(x, y) ((x) < (y) ? (y) : (x))
+_CLC_DEFINE_BINARY_BUILTIN(double, fmax, __builtin_fmax, double, double);
+
+#endif
 
-#define __CLC_BODY <binary_impl.inc>
+#define __CLC_BODY <fmax.inc>
 #include <clc/math/gentype.inc>
diff --git a/generic/lib/math/fmax.inc b/generic/lib/math/fmax.inc
new file mode 100644
index 0000000..8315c5f
--- /dev/null
+++ b/generic/lib/math/fmax.inc
@@ -0,0 +1,18 @@
+
+#if !defined(__CLC_SCALAR)
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fmax(__CLC_GENTYPE x, float y) {
+  return fmax(x, (__CLC_GENTYPE)((__CLC_SCALAR_GENTYPE)y));
+}
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fmax(__CLC_GENTYPE x, double y) {
+  return fmax(x, (__CLC_GENTYPE)((__CLC_SCALAR_GENTYPE)y));
+}
+
+#endif // ifdef cl_khr_fp64
+
+#endif // !defined(__CLC_SCALAR)
-- 
2.0.4





More information about the Libclc-dev mailing list