[Mesa-dev] [PATCH 2/3] libclc: Add clamp() builtin for integer/floating point

Aaron Watry awatry at gmail.com
Thu Mar 14 20:01:02 PDT 2013


Created under a new shared/ directory for functions which are available for
both integer and floating point types.
---
 generic/include/clc/clc.h            |    3 +++
 generic/include/clc/shared/clamp.h   |    5 +++++
 generic/include/clc/shared/clamp.inc |    1 +
 generic/lib/SOURCES                  |    1 +
 generic/lib/shared/clamp.cl          |   11 +++++++++++
 generic/lib/shared/clamp.inc         |    3 +++
 6 files changed, 24 insertions(+)
 create mode 100644 generic/include/clc/shared/clamp.h
 create mode 100644 generic/include/clc/shared/clamp.inc
 create mode 100644 generic/lib/shared/clamp.cl
 create mode 100644 generic/lib/shared/clamp.inc

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));
+}
-- 
1.7.10.4



More information about the mesa-dev mailing list