summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Watry <awatry@gmail.com>2013-03-20 17:48:04 -0500
committerAaron Watry <awatry@gmail.com>2013-03-20 17:48:04 -0500
commit0e990d39ce61f9d1a0dd47cb46a3263476d626c6 (patch)
tree576baefbf2392b04ee142c1313d390b38e75c88d
parent42678915299cc85229c3806ae644ed5793d2ab27 (diff)
libclc: Add clamp() builtin for integer/floating point
Created under a new shared/ directory for functions which are available for both integer and floating point types.
-rw-r--r--generic/include/clc/clc.h3
-rw-r--r--generic/include/clc/shared/clamp.h5
-rw-r--r--generic/include/clc/shared/clamp.inc1
-rw-r--r--generic/lib/SOURCES1
-rw-r--r--generic/lib/shared/clamp.cl11
-rw-r--r--generic/lib/shared/clamp.inc3
6 files changed, 24 insertions, 0 deletions
diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index f6668a3..80ecd01 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -67,6 +67,9 @@
#include <clc/integer/max.h>
#include <clc/integer/sub_sat.h>
+/* 6.11.2 and 6.11.3 Shared Integer/Math Functions */
+#include <clc/shared/clamp.h>
+
/* 6.11.5 Geometric Functions */
#include <clc/geometric/cross.h>
#include <clc/geometric/dot.h>
diff --git a/generic/include/clc/shared/clamp.h b/generic/include/clc/shared/clamp.h
new file mode 100644
index 0000000..5c2ebd0
--- /dev/null
+++ b/generic/include/clc/shared/clamp.h
@@ -0,0 +1,5 @@
+#define BODY <clc/shared/clamp.inc>
+#include <clc/integer/gentype.inc>
+
+#define BODY <clc/shared/clamp.inc>
+#include <clc/math/gentype.inc>
diff --git a/generic/include/clc/shared/clamp.inc b/generic/include/clc/shared/clamp.inc
new file mode 100644
index 0000000..3e3a435
--- /dev/null
+++ b/generic/include/clc/shared/clamp.inc
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL GENTYPE clamp(GENTYPE x, GENTYPE y, GENTYPE z);
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index a97213b..0d477ba 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -18,5 +18,6 @@ math/hypot.cl
math/mad.cl
math/max.cl
relational/any.cl
+shared/clamp.cl
workitem/get_global_id.cl
workitem/get_global_size.cl
diff --git a/generic/lib/shared/clamp.cl b/generic/lib/shared/clamp.cl
new file mode 100644
index 0000000..0e8d223
--- /dev/null
+++ b/generic/lib/shared/clamp.cl
@@ -0,0 +1,11 @@
+#include <clc/clc.h>
+
+#define BODY <clamp.inc>
+#include <clc/integer/gentype.inc>
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+#endif
+
+#define BODY <clamp.inc>
+#include <clc/math/gentype.inc>
diff --git a/generic/lib/shared/clamp.inc b/generic/lib/shared/clamp.inc
new file mode 100644
index 0000000..ed49b8e
--- /dev/null
+++ b/generic/lib/shared/clamp.inc
@@ -0,0 +1,3 @@
+_CLC_OVERLOAD _CLC_DEF GENTYPE clamp(GENTYPE x, GENTYPE y, GENTYPE z) {
+ return (x > z ? z : (x < y ? y : x));
+}