[Libclc-dev] [PATCH 4/4] Implement fmax() and fmin() builtins
Tom Stellard
tom at stellard.net
Thu Feb 7 09:54:34 PST 2013
From: Tom Stellard <thomas.stellard at amd.com>
---
generic/include/clc/clc.h | 2 ++
generic/include/clc/math/binary_decl.inc | 6 ++++++
generic/include/clc/math/fmax.h | 11 +++++++++++
generic/include/clc/math/fmin.h | 11 +++++++++++
generic/include/clc/math/gentype.inc | 4 ++++
generic/lib/SOURCES | 2 ++
generic/lib/math/binary_impl.inc | 18 ++++++++++++++++++
generic/lib/math/fmax.cl | 11 +++++++++++
generic/lib/math/fmin.cl | 11 +++++++++++
9 files changed, 76 insertions(+), 0 deletions(-)
create mode 100644 generic/include/clc/math/binary_decl.inc
create mode 100644 generic/include/clc/math/fmax.h
create mode 100644 generic/include/clc/math/fmin.h
create mode 100644 generic/lib/math/binary_impl.inc
create mode 100644 generic/lib/math/fmax.cl
create mode 100644 generic/lib/math/fmin.cl
diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 315693b..c917a46 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -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>
diff --git a/generic/include/clc/math/binary_decl.inc b/generic/include/clc/math/binary_decl.inc
new file mode 100644
index 0000000..1a49e26
--- /dev/null
+++ b/generic/include/clc/math/binary_decl.inc
@@ -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
diff --git a/generic/include/clc/math/fmax.h b/generic/include/clc/math/fmax.h
new file mode 100644
index 0000000..d26e5d6
--- /dev/null
+++ b/generic/include/clc/math/fmax.h
@@ -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
+
diff --git a/generic/include/clc/math/fmin.h b/generic/include/clc/math/fmin.h
new file mode 100644
index 0000000..3506aef
--- /dev/null
+++ b/generic/include/clc/math/fmin.h
@@ -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
+
diff --git a/generic/include/clc/math/gentype.inc b/generic/include/clc/math/gentype.inc
index 4506920..b525c4b 100644
--- a/generic/include/clc/math/gentype.inc
+++ b/generic/include/clc/math/gentype.inc
@@ -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
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index d29ca1f..86c008b 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -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
diff --git a/generic/lib/math/binary_impl.inc b/generic/lib/math/binary_impl.inc
new file mode 100644
index 0000000..e4b1e5f
--- /dev/null
+++ b/generic/lib/math/binary_impl.inc
@@ -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);
+}
diff --git a/generic/lib/math/fmax.cl b/generic/lib/math/fmax.cl
new file mode 100644
index 0000000..68a67ac
--- /dev/null
+++ b/generic/lib/math/fmax.cl
@@ -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>
diff --git a/generic/lib/math/fmin.cl b/generic/lib/math/fmin.cl
new file mode 100644
index 0000000..cac188e
--- /dev/null
+++ b/generic/lib/math/fmin.cl
@@ -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>
--
1.7.8.6
More information about the Libclc-dev
mailing list