[Libclc-dev] [PATCH v3 14/14] half_powr: Implement using exp2 and log2

Jan Vesely via Libclc-dev libclc-dev at lists.llvm.org
Thu Jan 18 13:08:30 PST 2018


Passes CTS on carrizo
v2: Use full precision implementation
v3: Use log2 + exp2 formula instead of full precision powr

Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
This version actually passes the CTS

 generic/include/clc/clc.h            | 1 +
 generic/include/clc/math/half_powr.h | 7 +++++++
 generic/lib/SOURCES                  | 1 +
 generic/lib/math/half_powr.cl        | 5 +++++
 generic/lib/math/half_powr.inc       | 5 +++++
 5 files changed, 19 insertions(+)
 create mode 100644 generic/include/clc/math/half_powr.h
 create mode 100644 generic/lib/math/half_powr.cl
 create mode 100644 generic/lib/math/half_powr.inc

diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 930bbfc..fa48639 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -78,6 +78,7 @@
 #include <clc/math/half_log.h>
 #include <clc/math/half_log10.h>
 #include <clc/math/half_log2.h>
+#include <clc/math/half_powr.h>
 #include <clc/math/half_recip.h>
 #include <clc/math/half_rsqrt.h>
 #include <clc/math/half_sin.h>
diff --git a/generic/include/clc/math/half_powr.h b/generic/include/clc/math/half_powr.h
new file mode 100644
index 0000000..c4e5242
--- /dev/null
+++ b/generic/include/clc/math/half_powr.h
@@ -0,0 +1,7 @@
+#define __CLC_BODY <clc/math/binary_decl_tt.inc>
+#define __CLC_FUNCTION half_powr
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 9dbd35e..5aa2ba6 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -112,6 +112,7 @@ math/half_exp2.cl
 math/half_log.cl
 math/half_log10.cl
 math/half_log2.cl
+math/half_powr.cl
 math/half_recip.cl
 math/half_rsqrt.cl
 math/half_sin.cl
diff --git a/generic/lib/math/half_powr.cl b/generic/lib/math/half_powr.cl
new file mode 100644
index 0000000..df7f124
--- /dev/null
+++ b/generic/lib/math/half_powr.cl
@@ -0,0 +1,5 @@
+#include <clc/clc.h>
+
+#define __CLC_BODY <half_powr.inc>
+#define __FLOAT_ONLY
+#include <clc/math/gentype.inc>
diff --git a/generic/lib/math/half_powr.inc b/generic/lib/math/half_powr.inc
new file mode 100644
index 0000000..4862c4b
--- /dev/null
+++ b/generic/lib/math/half_powr.inc
@@ -0,0 +1,5 @@
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE half_powr(__CLC_GENTYPE x, __CLC_GENTYPE y) {
+  // x^y == 2^{log2 x^y} == 2^{y * log2 x}
+  // for x < 0 propagate nan created by log2
+  return exp2(y * log2(x));
+}
-- 
2.14.3



More information about the Libclc-dev mailing list