<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 14 Nov 2017, at 22:37, Jan Vesely <<a href="mailto:jan.vesely@rutgers.edu" class="">jan.vesely@rutgers.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On Tue, 2017-11-14 at 21:42 +0100, Jeroen Ketema via Libclc-dev wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">Hi Jan,<br class=""><br class="">Thanks for the clarification. Looking back at the code<br class=""><br class="">const __CLC_GENTYPE zero = (__CLC_GENTYPE)0.0f;<br class="">const __CLC_GENTYPE res = native_exp2(y * native_log2(x));<br class="">const __CLC_INTN condnan = isless(x, zero);<br class="">return select(res, (__CLC_GENTYPE)NAN, condnan);<br class=""><br class="">and with your comments in mind, can’t this be simplified to:<br class=""><br class="">return native_exp2(y * native_log2(x));<br class=""><br class="">?<br class=""><br class="">If x < 0, then native_log2 yields NaN, and the NaN propagates through the operations.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">yeah, that works as well. I guess the special cases were also crafted</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">for this optimization.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>I’m fine with it either way. I do think it would be good to add some comments</div><div>in the code that explain what is going on. Just x^y == 2^{log2 x^y} == 2^{y * log2 x}</div><div>plus a comment about x < 0 would work for me.</div><div><br class=""></div><div>Jeroen</div><br class=""><blockquote type="cite" class=""><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Jan</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><br class="">Jeroen<br class=""><br class=""><blockquote type="cite" class="">On 13 Nov 2017, at 21:09, Jan Vesely <<a href="mailto:jan.vesely@rutgers.edu" class="">jan.vesely@rutgers.edu</a>> wrote:<br class=""><br class="">On Mon, 2017-11-13 at 20:50 +0100, Jeroen Ketema wrote:<br class=""><blockquote type="cite" class="">This one is not immediately obvious to me. Maybe add some appropriate comment?<br class=""></blockquote><br class="">it exploits that x == 2^{log2 x} and log2 {x^y} == y * log2 x<br class="">thus x^y == 2^{log2 x^y} == 2^{y * log2 x}.<br class="">However, it only works for x > 0, which is OK since powr(<0, ...)<br class="">should return NaN anyway.<br class="">IMO powr was added to allow this kind of expansion instead of more<br class="">expensive full pow (which needs to handle negative x).<br class=""><br class="">Jan<br class=""><br class=""><blockquote type="cite" class=""><br class="">Jeroen<br class=""><br class=""><blockquote type="cite" class="">On 6 Nov 2017, at 23:15, Jan Vesely via Libclc-dev <<a href="mailto:libclc-dev@lists.llvm.org" class="">libclc-dev@lists.llvm.org</a>> wrote:<br class=""><br class="">Signed-off-by: Jan Vesely <<a href="mailto:jan.vesely@rutgers.edu" class="">jan.vesely@rutgers.edu</a>><br class="">---<br class="">sent wrong patch the first time. This one passes the CTS.<br class=""><br class="">Jan<br class=""><br class="">generic/include/clc/math/native_powr.h | 8 +++++++-<br class="">generic/lib/SOURCES | 1 +<br class="">generic/lib/math/native_powr.cl | 5 +++++<br class="">generic/lib/math/native_powr.inc | 6 ++++++<br class="">4 files changed, 19 insertions(+), 1 deletion(-)<br class="">create mode 100644 generic/lib/math/native_powr.cl<br class="">create mode 100644 generic/lib/math/native_powr.inc<br class=""><br class="">diff --git a/generic/include/clc/math/native_powr.h b/generic/include/clc/math/native_powr.h<br class="">index e8a37d9..c31161a 100644<br class="">--- a/generic/include/clc/math/native_powr.h<br class="">+++ b/generic/include/clc/math/native_powr.h<br class="">@@ -1 +1,7 @@<br class="">-#define native_powr pow<br class="">+#define __CLC_BODY <clc/math/binary_decl_tt.inc><br class="">+#define __CLC_FUNCTION native_powr<br class="">+<br class="">+#include <clc/math/gentype.inc><br class="">+<br class="">+#undef __CLC_BODY<br class="">+#undef __CLC_FUNCTION<br class="">diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES<br class="">index 355741c..ad5a743 100644<br class="">--- a/generic/lib/SOURCES<br class="">+++ b/generic/lib/SOURCES<br class="">@@ -127,6 +127,7 @@ math/native_exp2.cl<br class="">math/native_log.cl<br class="">math/native_log10.cl<br class="">math/native_log2.cl<br class="">+math/native_powr.cl<br class="">math/native_recip.cl<br class="">math/native_rsqrt.cl<br class="">math/native_sin.cl<br class="">diff --git a/generic/lib/math/native_powr.cl b/generic/lib/math/native_powr.cl<br class="">new file mode 100644<br class="">index 0000000..452bc6f<br class="">--- /dev/null<br class="">+++ b/generic/lib/math/native_powr.cl<br class="">@@ -0,0 +1,5 @@<br class="">+#include <clc/clc.h><br class="">+<br class="">+#define __CLC_BODY <native_powr.inc><br class="">+#define __FLOAT_ONLY<br class="">+#include <clc/math/gentype.inc><br class="">diff --git a/generic/lib/math/native_powr.inc b/generic/lib/math/native_powr.inc<br class="">new file mode 100644<br class="">index 0000000..841b1ff<br class="">--- /dev/null<br class="">+++ b/generic/lib/math/native_powr.inc<br class="">@@ -0,0 +1,6 @@<br class="">+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_powr(__CLC_GENTYPE x, __CLC_GENTYPE y) {<br class="">+ const __CLC_GENTYPE zero = (__CLC_GENTYPE)0.0f;<br class="">+ const __CLC_GENTYPE res = native_exp2(y * native_log2(x));<br class="">+ const __CLC_INTN condnan = isless(x, zero);<br class="">+ return select(res, (__CLC_GENTYPE)NAN, condnan);<br class="">+}<br class="">--<span class="Apple-converted-space"> </span><br class="">2.13.6<br class=""><br class="">_______________________________________________<br class="">Libclc-dev mailing list<br class=""><a href="mailto:Libclc-dev@lists.llvm.org" class="">Libclc-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev<br class=""></blockquote><br class=""><br class=""></blockquote></blockquote><br class="">_______________________________________________<br class="">Libclc-dev mailing list<br class=""><a href="mailto:Libclc-dev@lists.llvm.org" class="">Libclc-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev</a></blockquote></div></blockquote></div><br class=""></body></html>