[libclc] r233712 - Implement fmin using __builtin_fmin

Tom Stellard thomas.stellard at amd.com
Tue Mar 31 09:59:21 PDT 2015


Author: tstellar
Date: Tue Mar 31 11:59:21 2015
New Revision: 233712

URL: http://llvm.org/viewvc/llvm-project?rev=233712&view=rev
Log:
Implement fmin using __builtin_fmin

This ensures correct handling of NaN.

This has been tested with piglit, OpenCV, and the ocl conformance tests.

Added:
    libclc/trunk/generic/lib/math/fmin.inc
Modified:
    libclc/trunk/generic/include/clc/math/fmin.h
    libclc/trunk/generic/lib/math/fmin.cl

Modified: libclc/trunk/generic/include/clc/math/fmin.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/fmin.h?rev=233712&r1=233711&r2=233712&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/math/fmin.h (original)
+++ libclc/trunk/generic/include/clc/math/fmin.h Tue Mar 31 11:59:21 2015
@@ -1,8 +1,5 @@
-#undef fmin
-#define fmin __clc_fmin
-
 #define __CLC_BODY <clc/math/binary_decl.inc>
-#define __CLC_FUNCTION __clc_fmin
+#define __CLC_FUNCTION fmin
 
 #include <clc/math/gentype.inc>
 

Modified: libclc/trunk/generic/lib/math/fmin.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/fmin.cl?rev=233712&r1=233711&r2=233712&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/fmin.cl (original)
+++ libclc/trunk/generic/lib/math/fmin.cl Tue Mar 31 11:59:21 2015
@@ -1,11 +1,16 @@
 #include <clc/clc.h>
 
+#include "../clcmacro.h"
+
+_CLC_DEFINE_BINARY_BUILTIN(float, fmin, __builtin_fminf, float, float);
+
 #ifdef cl_khr_fp64
+
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
-#endif
 
-#define FUNCTION __clc_fmin
-#define FUNCTION_IMPL(x, y) ((y) < (x) ? (y) : (x))
+_CLC_DEFINE_BINARY_BUILTIN(double, fmin, __builtin_fmin, double, double);
+
+#endif
 
-#define __CLC_BODY <binary_impl.inc>
+#define __CLC_BODY <fmin.inc>
 #include <clc/math/gentype.inc>

Added: libclc/trunk/generic/lib/math/fmin.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/fmin.inc?rev=233712&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/fmin.inc (added)
+++ libclc/trunk/generic/lib/math/fmin.inc Tue Mar 31 11:59:21 2015
@@ -0,0 +1,18 @@
+
+#if !defined(__CLC_SCALAR)
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fmin(__CLC_GENTYPE x, float y) {
+  return fmin(x, (__CLC_GENTYPE)((__CLC_SCALAR_GENTYPE)y));
+}
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fmin(__CLC_GENTYPE x, double y) {
+  return fmin(x, (__CLC_GENTYPE)((__CLC_SCALAR_GENTYPE)y));
+}
+
+#endif // ifdef cl_khr_fp64
+
+#endif // !defined(__CLC_SCALAR)





More information about the cfe-commits mailing list