[Libclc-dev] [PATCH 1/2] Implement fmin using __builtin_fmin

Tom Stellard tom at stellard.net
Fri Mar 20 06:11:31 PDT 2015


On Fri, Mar 20, 2015 at 11:16:51AM +0000, Jeroen Ketema wrote:
> 
> > On 19 Mar 2015, at 20:30, Tom Stellard <thomas.stellard at amd.com> wrote:
> > 
> > This ensures correct handling of NaN / INF.
> > 
> > This has been tested with piglit, OpenCV, and the ocl conformance tests.
> > ---
> > generic/include/clc/math/fmin.h |  5 +----
> > generic/lib/math/fmin.cl        | 13 +++++++++----
> > generic/lib/math/fmin.inc       | 18 ++++++++++++++++++
> > 3 files changed, 28 insertions(+), 8 deletions(-)
> > create mode 100644 generic/lib/math/fmin.inc
> > 
> > diff --git a/generic/include/clc/math/fmin.h b/generic/include/clc/math/fmin.h
> > index 5588ba9..d45f572 100644
> > --- a/generic/include/clc/math/fmin.h
> > +++ b/generic/include/clc/math/fmin.h
> > @@ -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
> 
> Wasn’t this done to avoid name collisions with the standard math library?
> 

We are passing -fno-builtin to clang, which as far as I understand
prevents this problem.

-Tom

> Otherwise: LGTM.
> 
> Jeroen
> 
> > 
> > #include <clc/math/gentype.inc>
> > 
> > diff --git a/generic/lib/math/fmin.cl b/generic/lib/math/fmin.cl
> > index a61ad47..28c7d01 100644
> > --- a/generic/lib/math/fmin.cl
> > +++ b/generic/lib/math/fmin.cl
> > @@ -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>
> > diff --git a/generic/lib/math/fmin.inc b/generic/lib/math/fmin.inc
> > new file mode 100644
> > index 0000000..d4b5ac2
> > --- /dev/null
> > +++ b/generic/lib/math/fmin.inc
> > @@ -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)
> > -- 
> > 2.0.4
> > 
> > 
> > _______________________________________________
> > Libclc-dev mailing list
> > Libclc-dev at pcc.me.uk
> > http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev
> 
> 
> _______________________________________________
> Libclc-dev mailing list
> Libclc-dev at pcc.me.uk
> http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev




More information about the Libclc-dev mailing list