[libclc] r184987 - Implement fmax() and fmin() builtins
Tom Stellard
thomas.stellard at amd.com
Wed Jun 26 11:20:25 PDT 2013
Author: tstellar
Date: Wed Jun 26 13:20:25 2013
New Revision: 184987
URL: http://llvm.org/viewvc/llvm-project?rev=184987&view=rev
Log:
Implement fmax() and fmin() builtins
Added:
libclc/trunk/generic/include/clc/math/binary_decl.inc
libclc/trunk/generic/include/clc/math/fmax.h
libclc/trunk/generic/include/clc/math/fmin.h
libclc/trunk/generic/lib/math/binary_impl.inc
libclc/trunk/generic/lib/math/fmax.cl
libclc/trunk/generic/lib/math/fmin.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/include/clc/math/gentype.inc
libclc/trunk/generic/lib/SOURCES
Modified: libclc/trunk/generic/include/clc/clc.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=184987&r1=184986&r2=184987&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Wed Jun 26 13:20:25 2013
@@ -38,6 +38,8 @@
#include <clc/math/fabs.h>
#include <clc/math/floor.h>
#include <clc/math/fma.h>
+#include <clc/math/fmax.h>
+#include <clc/math/fmin.h>
#include <clc/math/hypot.h>
#include <clc/math/log.h>
#include <clc/math/log2.h>
Added: libclc/trunk/generic/include/clc/math/binary_decl.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/binary_decl.inc?rev=184987&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/math/binary_decl.inc (added)
+++ libclc/trunk/generic/include/clc/math/binary_decl.inc Wed Jun 26 13:20:25 2013
@@ -0,0 +1,6 @@
+_CLC_OVERLOAD _CLC_DECL GENTYPE FUNCTION(GENTYPE a, GENTYPE b);
+_CLC_OVERLOAD _CLC_DECL GENTYPE FUNCTION(GENTYPE a, float b);
+
+#ifdef cl_khr_fp64
+_CLC_OVERLOAD _CLC_DECL GENTYPE FUNCTION(GENTYPE a, double b);
+#endif
Added: libclc/trunk/generic/include/clc/math/fmax.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/fmax.h?rev=184987&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/math/fmax.h (added)
+++ libclc/trunk/generic/include/clc/math/fmax.h Wed Jun 26 13:20:25 2013
@@ -0,0 +1,11 @@
+#undef fmax
+#define fmax __clc_fmax
+
+#define BODY <clc/math/binary_decl.inc>
+#define FUNCTION __clc_fmax
+
+#include <clc/math/gentype.inc>
+
+#undef BODY
+#undef FUNCTION
+
Added: libclc/trunk/generic/include/clc/math/fmin.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/fmin.h?rev=184987&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/math/fmin.h (added)
+++ libclc/trunk/generic/include/clc/math/fmin.h Wed Jun 26 13:20:25 2013
@@ -0,0 +1,11 @@
+#undef fmin
+#define fmin __clc_fmin
+
+#define BODY <clc/math/binary_decl.inc>
+#define FUNCTION __clc_fmin
+
+#include <clc/math/gentype.inc>
+
+#undef BODY
+#undef FUNCTION
+
Modified: libclc/trunk/generic/include/clc/math/gentype.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/gentype.inc?rev=184987&r1=184986&r2=184987&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/math/gentype.inc (original)
+++ libclc/trunk/generic/include/clc/math/gentype.inc Wed Jun 26 13:20:25 2013
@@ -1,6 +1,8 @@
#define GENTYPE float
+#define SCALAR
#include BODY
#undef GENTYPE
+#undef SCALAR
#define GENTYPE float2
#include BODY
@@ -23,9 +25,11 @@
#undef GENTYPE
#ifdef cl_khr_fp64
+#define SCALAR
#define GENTYPE double
#include BODY
#undef GENTYPE
+#undef SCALAR
#define GENTYPE double2
#include BODY
Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=184987&r1=184986&r2=184987&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Wed Jun 26 13:20:25 2013
@@ -10,6 +10,8 @@ integer/add_sat_impl.ll
integer/sub_sat.cl
integer/sub_sat.ll
integer/sub_sat_impl.ll
+math/fmax.cl
+math/fmin.cl
math/hypot.cl
math/mad.cl
relational/any.cl
Added: libclc/trunk/generic/lib/math/binary_impl.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/binary_impl.inc?rev=184987&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/binary_impl.inc (added)
+++ libclc/trunk/generic/lib/math/binary_impl.inc Wed Jun 26 13:20:25 2013
@@ -0,0 +1,18 @@
+
+#ifndef SCALAR
+
+_CLC_OVERLOAD _CLC_DEF GENTYPE FUNCTION(GENTYPE x, GENTYPE y) {
+ return FUNCTION_IMPL(x, y);
+}
+
+#endif
+
+_CLC_OVERLOAD _CLC_DEF GENTYPE FUNCTION(GENTYPE x, double y) {
+ GENTYPE vec_y = (GENTYPE) (y);
+ return FUNCTION_IMPL(x, vec_y);
+}
+
+_CLC_OVERLOAD _CLC_DEF GENTYPE FUNCTION(GENTYPE x, float y) {
+ GENTYPE vec_y = (GENTYPE) (y);
+ return FUNCTION_IMPL(x, vec_y);
+}
Added: libclc/trunk/generic/lib/math/fmax.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/fmax.cl?rev=184987&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/fmax.cl (added)
+++ libclc/trunk/generic/lib/math/fmax.cl Wed Jun 26 13:20:25 2013
@@ -0,0 +1,11 @@
+#include <clc/clc.h>
+
+#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))
+
+#define BODY <binary_impl.inc>
+#include <clc/math/gentype.inc>
Added: libclc/trunk/generic/lib/math/fmin.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/fmin.cl?rev=184987&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/fmin.cl (added)
+++ libclc/trunk/generic/lib/math/fmin.cl Wed Jun 26 13:20:25 2013
@@ -0,0 +1,11 @@
+#include <clc/clc.h>
+
+#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))
+
+#define BODY <binary_impl.inc>
+#include <clc/math/gentype.inc>
More information about the cfe-commits
mailing list