[Libclc-dev] [PATCH 4/5] Implement sign() builtin
Tom Stellard
tom at stellard.net
Thu Sep 12 15:07:13 PDT 2013
From: Tom Stellard <thomas.stellard at amd.com>
---
generic/include/clc/clc.h | 3 +++
generic/include/clc/common/sign.h | 5 +++++
generic/lib/SOURCES | 1 +
generic/lib/common/sign.cl | 27 +++++++++++++++++++++++++++
4 files changed, 36 insertions(+)
create mode 100644 generic/include/clc/common/sign.h
create mode 100644 generic/lib/common/sign.cl
diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 580750d..e698990 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -85,6 +85,9 @@
#include <clc/shared/vload.h>
#include <clc/shared/vstore.h>
+/* 6.11.4 Common Functions */
+#include <clc/common/sign.h>
+
/* 6.11.5 Geometric Functions */
#include <clc/geometric/cross.h>
#include <clc/geometric/dot.h>
diff --git a/generic/include/clc/common/sign.h b/generic/include/clc/common/sign.h
new file mode 100644
index 0000000..fa9aa09
--- /dev/null
+++ b/generic/include/clc/common/sign.h
@@ -0,0 +1,5 @@
+#define __CLC_FUNCTION sign
+#define __CLC_BODY <clc/math/unary_decl.inc>
+#include <clc/math/gentype.inc>
+#undef __CLC_FUNCTION
+#undef __CLC_BODY
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index e1a2972..35b0739 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -1,5 +1,6 @@
atomic/atomic_impl.ll
convert.cl
+common/sign.cl
geometric/cross.cl
geometric/dot.cl
geometric/length.cl
diff --git a/generic/lib/common/sign.cl b/generic/lib/common/sign.cl
new file mode 100644
index 0000000..070abd5
--- /dev/null
+++ b/generic/lib/common/sign.cl
@@ -0,0 +1,27 @@
+#include <clc/clc.h>
+
+#define SIGN(TYPE, F) \
+_CLC_DEF _CLC_OVERLOAD TYPE sign(TYPE x) { \
+ if (isnan(x)) { \
+ return 0.0F; \
+ } \
+ if (x > 0.0F) { \
+ return 1.0F; \
+ } \
+ if (x < 0.0F) { \
+ return -1.0F; \
+ } \
+ return x; /* -0.0 or +0.0 */ \
+}
+
+SIGN(float, f)
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, sign, float)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+SIGN(double, )
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, sign, double)
+
+#endif
--
1.7.11.4
More information about the Libclc-dev
mailing list