<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></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 17 Jan 2018, at 17:27, 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, 2018-01-16 at 20:32 +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="">This LGTM. Two small comments below.<br class=""><br class=""><blockquote type="cite" class="">On 16 Jan 2018, at 01:47, 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="">Passes piglit on turks and carrizo<br class="">fp64 passes CTS on carrizo<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="">fp32 cts failure on carrizo is denormal related<br class=""></blockquote><br class="">Could you clarify this? I see some ifdefs that give the impression that they should handle this.<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="">thanks for bringing this up. Those should be converted to runtime</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="">checks. I'll send v2.</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=""><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="">I see errors like this:</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="">ERROR: rootn: -2047.000000 ulp error at {-0x1.ffcp-139, 1}: *-0x1.ffcp-</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="">139 vs. -0x1.ffcp-138 (0x80000ffe) at index: 137</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=""><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="">ERROR: powr: 8106.990234 ulp error at {0x1.e70f2cp-18 (0x36f38796),</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="">0x1.fde54cp+2 (0x40fef2a6)}: *0x1.fabp-137 vs. 0x1.fabp-136</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="">(0x00003f56) at index: 64996</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=""><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="">ERROR: pown: -2047.000000 ulp error at {-0x1.ffcp-139, 1}: *-0x1.ffcp-</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="">139 vs. -0x1.ffcp-138 (0x80000ffe) at index: 137</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=""><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="">ERROR: pow: 8106.990234 ulp error at {0x1.e70f2cp-18 (0x36f38796),</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="">0x1.fde54cp+2 (0x40fef2a6)}: *0x1.fabp-137 vs. 0x1.fabp-136</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="">(0x00003f56) at index: 64996</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 class=""></div></blockquote><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="">rootn and pown should probably be specialcased (y = 1), although the</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="">specs do not require it, but there might be more similar errors.</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="">I'm not sure what to do about pow/powr it looks like off by one error</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="">in denormal path, but I think that would be better addressed in a</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="">separate patch.</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=""></div></blockquote><div><br class=""></div><div>Agreed that this is better addressed separately. I doubt if special-casing is</div><div>the solution here. It somehow seems like they all suffer from a similar</div><div>kind off-by-one error in the exponent.</div><div><br class=""></div><div>Jeroen</div><br class=""><blockquote type="cite" class=""><div 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=""><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=""><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="">PS: I'll fix the formatting in v2 as well.</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=""><br class="">generic/include/clc/math/pown.h   |  27 +--<br class="">generic/include/clc/math/pown.inc |   1 +<br class="">generic/include/math/clc_pown.h   |   3 +<br class="">generic/include/math/clc_pown.inc |   1 +<br class="">generic/lib/SOURCES               |   1 +<br class="">generic/lib/math/clc_pown.cl      | 378 ++++++++++++++++++++++++++++++++++++++<br class="">generic/lib/math/pown.cl          |  10 +-<br class="">generic/lib/math/pown.inc         |   3 +<br class="">8 files changed, 393 insertions(+), 31 deletions(-)<br class="">create mode 100644 generic/include/clc/math/pown.inc<br class="">create mode 100644 generic/include/math/clc_pown.h<br class="">create mode 100644 generic/include/math/clc_pown.inc<br class="">create mode 100644 generic/lib/math/clc_pown.cl<br class="">create mode 100644 generic/lib/math/pown.inc<br class=""><br class="">diff --git a/generic/include/clc/math/pown.h b/generic/include/clc/math/pown.h<br class="">index bdbf50c..2ed8a6e 100644<br class="">--- a/generic/include/clc/math/pown.h<br class="">+++ b/generic/include/clc/math/pown.h<br class="">@@ -1,24 +1,3 @@<br class="">-#define _CLC_POWN_INTRINSIC "llvm.powi"<br class="">-<br class="">-#define _CLC_POWN_DECL(GENTYPE, INTTYPE) \<br class="">-  _CLC_OVERLOAD _CLC_DECL GENTYPE pown(GENTYPE x, INTTYPE y);<br class="">-<br class="">-#define _CLC_VECTOR_POWN_DECL(GENTYPE, INTTYPE) \<br class="">-  _CLC_POWN_DECL(GENTYPE##2, INTTYPE##2)  \<br class="">-  _CLC_POWN_DECL(GENTYPE##3, INTTYPE##3)  \<br class="">-  _CLC_POWN_DECL(GENTYPE##4, INTTYPE##4)  \<br class="">-  _CLC_POWN_DECL(GENTYPE##8, INTTYPE##8)  \<br class="">-  _CLC_POWN_DECL(GENTYPE##16, INTTYPE##16)<br class="">-<br class="">-_CLC_OVERLOAD float pown(float x, int y) __asm(_CLC_POWN_INTRINSIC ".f32");<br class="">-<br class="">-_CLC_VECTOR_POWN_DECL(float, int)<br class="">-<br class="">-#ifdef cl_khr_fp64<br class="">-_CLC_OVERLOAD double pown(double x, int y) __asm(_CLC_POWN_INTRINSIC ".f64");<br class="">-_CLC_VECTOR_POWN_DECL(double, int)<br class="">-#endif<br class="">-<br class="">-#undef _CLC_POWN_INTRINSIC<br class="">-#undef _CLC_POWN_DECL<br class="">-#undef _CLC_VECTOR_POWN_DECL<br class="">+#define __CLC_BODY <clc/math/pown.inc><br class="">+#include <clc/math/gentype.inc><br class="">+#undef __CLC_BODY<br class="">diff --git a/generic/include/clc/math/pown.inc b/generic/include/clc/math/pown.inc<br class="">new file mode 100644<br class="">index 0000000..cf0be4c<br class="">--- /dev/null<br class="">+++ b/generic/include/clc/math/pown.inc<br class="">@@ -0,0 +1 @@<br class="">+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE pown(__CLC_GENTYPE a, __CLC_INTN b);<br class="">diff --git a/generic/include/math/clc_pown.h b/generic/include/math/clc_pown.h<br class="">new file mode 100644<br class="">index 0000000..222c1dd<br class="">--- /dev/null<br class="">+++ b/generic/include/math/clc_pown.h<br class="">@@ -0,0 +1,3 @@<br class="">+#define __CLC_BODY <math/clc_pown.inc><br class="">+#include <clc/math/gentype.inc><br class="">+#undef __CLC_BODY<br class="">diff --git a/generic/include/math/clc_pown.inc b/generic/include/math/clc_pown.inc<br class="">new file mode 100644<br class="">index 0000000..168cd8e<br class="">--- /dev/null<br class="">+++ b/generic/include/math/clc_pown.inc<br class="">@@ -0,0 +1 @@<br class="">+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_pown(__CLC_GENTYPE a, __CLC_INTN b);<br class="">diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES<br class="">index a2d8c70..e4bd381 100644<br class="">--- a/generic/lib/SOURCES<br class="">+++ b/generic/lib/SOURCES<br class="">@@ -153,6 +153,7 @@ math/clc_nextafter.cl<br class="">math/nextafter.cl<br class="">math/clc_pow.cl<br class="">math/pow.cl<br class="">+math/clc_pown.cl<br class="">math/pown.cl<br class="">math/sin.cl<br class="">math/sincos.cl<br class="">diff --git a/generic/lib/math/clc_pown.cl b/generic/lib/math/clc_pown.cl<br class="">new file mode 100644<br class="">index 0000000..12c77a2<br class="">--- /dev/null<br class="">+++ b/generic/lib/math/clc_pown.cl<br class="">@@ -0,0 +1,378 @@<br class="">+/*<br class="">+ * Copyright (c) 2014 Advanced Micro Devices, Inc.<br class="">+ *<br class="">+ * Permission is hereby granted, free of charge, to any person obtaining a copy<br class="">+ * of this software and associated documentation files (the "Software"), to deal<br class="">+ * in the Software without restriction, including without limitation the rights<br class="">+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br class="">+ * copies of the Software, and to permit persons to whom the Software is<br class="">+ * furnished to do so, subject to the following conditions:<br class="">+ *<br class="">+ * The above copyright notice and this permission notice shall be included in<br class="">+ * all copies or substantial portions of the Software.<br class="">+ *<br class="">+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br class="">+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br class="">+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br class="">+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br class="">+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br class="">+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br class="">+ * THE SOFTWARE.<br class="">+ */<br class="">+<br class="">+#include <clc/clc.h><br class="">+<br class="">+#include "math.h"<br class="">+#include "tables.h"<br class="">+#include "../clcmacro.h"<br class="">+<br class="">+// compute pow using log and exp<br class="">+// x^y = exp(y * log(x))<br class="">+//<br class="">+// we take care not to lose precision in the intermediate steps<br class="">+//<br class="">+// When computing log, calculate it in splits,<br class="">+//<br class="">+// r = f * (p_invead + p_inv_tail)<br class="">+// r = rh + rt<br class="">+//<br class="">+// calculate log polynomial using r, in end addition, do<br class="">+// poly = poly + ((rh-r) + rt)<br class="">+//<br class="">+// lth = -r<br class="">+// ltt = ((xexp * log2_t) - poly) + logT<br class="">+// lt = lth + ltt<br class="">+//<br class="">+// lh = (xexp * log2_h) + logH<br class="">+// l = lh + lt<br class="">+//<br class="">+// Calculate final log answer as gh and gt,<br class="">+// gh = l & higher-half bits<br class="">+// gt = (((ltt - (lt - lth)) + ((lh - l) + lt)) + (l - gh))<br class="">+//<br class="">+// yh = y & higher-half bits<br class="">+// yt = y - yh<br class="">+//<br class="">+// Before entering computation of exp,<br class="">+// vs = ((yt*gt + yt*gh) + yh*gt)<br class="">+// v = vs + yh*gh<br class="">+// vt = ((yh*gh - v) + vs)<br class="">+//<br class="">+// In calculation of exp, add vt to r that is used for poly<br class="">+// At the end of exp, do<br class="">+// ((((expT * poly) + expT) + expH*poly) + expH)<br class="">+<br class="">+_CLC_DEF _CLC_OVERLOAD float __clc_pown(float x, int ny)<br class="">+{<br class="">+    float y = (float)ny;<br class="">+<br class="">+    int ix = as_int(x);<br class="">+    int ax = ix & EXSIGNBIT_SP32;<br class="">+    int xpos = ix == ax;<br class="">+<br class="">+    int iy = as_int(y);<br class="">+    int ay = iy & EXSIGNBIT_SP32;<br class="">+    int ypos = iy == ay;<br class="">+<br class="">+    // Extra precise log calculation<br class="">+    // First handle case that x is close to 1<br class="">+    float r = 1.0f - as_float(ax);<br class="">+    int near1 = fabs(r) < 0x1.0p-4f;<br class="">+    float r2 = r*r;<br class="">+<br class="">+    // Coefficients are just 1/3, 1/4, 1/5 and 1/6<br class="">+    float poly = mad(r,<br class="">+                     mad(r,<br class="">+                         mad(r,<br class="">+                             mad(r, 0x1.24924ap-3f, 0x1.555556p-3f),<br class="">+                             0x1.99999ap-3f),<br class="">+                         0x1.000000p-2f),<br class="">+                     0x1.555556p-2f);<br class="">+<br class="">+    poly *= r2*r;<br class="">+<br class="">+    float lth_near1 = -r2 * 0.5f;<br class="">+    float ltt_near1 = -poly;<br class="">+    float lt_near1 = lth_near1 + ltt_near1;<br class="">+    float lh_near1 = -r;<br class="">+    float l_near1 = lh_near1 + lt_near1;<br class="">+<br class="">+    // Computations for x not near 1<br class="">+    int m = (int)(ax >> EXPSHIFTBITS_SP32) - EXPBIAS_SP32;<br class="">+    float mf = (float)m;<br class="">+    int ixs = as_int(as_float(ax | 0x3f800000) - 1.0f);<br class="">+    float mfs = (float)((ixs >> EXPSHIFTBITS_SP32) - 253);<br class="">+    int c = m == -127;<br class="">+    int ixn = c ? ixs : ax;<br class="">+    float mfn = c ? mfs : mf;<br class="">+<br class="">+    int indx = (ixn & 0x007f0000) + ((ixn & 0x00008000) << 1);<br class="">+<br class="">+    // F - Y<br class="">+    float f = as_float(0x3f000000 | indx) - as_float(0x3f000000 | (ixn & MANTBITS_SP32));<br class="">+<br class="">+    indx = indx >> 16;<br class="">+    float2 tv = USE_TABLE(log_inv_tbl_ep, indx);<br class="">+    float rh = f * tv.s0;<br class="">+    float rt = f * tv.s1;<br class="">+    r = rh + rt;<br class="">+<br class="">+    poly = mad(r, mad(r, 0x1.0p-2f, 0x1.555556p-2f), 0x1.0p-1f) * (r*r);<br class="">+    poly += (rh - r) + rt;<br class="">+<br class="">+    const float LOG2_HEAD = 0x1.62e000p-1f;  // 0.693115234<br class="">+    const float LOG2_TAIL = 0x1.0bfbe8p-15f; // 0.0000319461833<br class="">+    tv = USE_TABLE(loge_tbl, indx);<br class="">+    float lth = -r;<br class="">+    float ltt = mad(mfn, LOG2_TAIL, -poly) + tv.s1;<br class="">+    float lt = lth + ltt;<br class="">+    float lh = mad(mfn, LOG2_HEAD, tv.s0);<br class="">+    float l = lh + lt;<br class="">+<br class="">+    // Select near 1 or not<br class="">+    lth = near1 ? lth_near1 : lth;<br class="">+    ltt = near1 ? ltt_near1 : ltt;<br class="">+    lt = near1 ? lt_near1 : lt;<br class="">+    lh = near1 ? lh_near1 : lh;<br class="">+    l = near1 ? l_near1 : l;<br class="">+<br class="">+    float gh = as_float(as_int(l) & 0xfffff000);<br class="">+    float gt = ((ltt - (lt - lth)) + ((lh - l) + lt)) + (l - gh);<br class="">+<br class="">+    float yh = as_float(iy & 0xfffff000);<br class="">+<br class="">+    float yt = (float)(ny - (int)yh);<br class="">+<br class="">+    float ylogx_s = mad(gt, yh, mad(gh, yt, yt*gt));<br class="">+    float ylogx = mad(yh, gh, ylogx_s);<br class="">+    float ylogx_t = mad(yh, gh, -ylogx) + ylogx_s;<br class="">+<br class="">+    // Extra precise exp of ylogx<br class="">+    const float R_64_BY_LOG2 = 0x1.715476p+6f; // 64/log2 : 92.332482616893657<br class="">+    int n = convert_int(ylogx * R_64_BY_LOG2);<br class="">+    float nf = (float) n;<br class="">+<br class="">+    int j = n & 0x3f;<br class="">+    m = n >> 6;<br class="">+    int m2 = m << EXPSHIFTBITS_SP32;<br class="">+<br class="">+    const float R_LOG2_BY_64_LD = 0x1.620000p-7f;  // log2/64 lead: 0.0108032227<br class="">+    const float R_LOG2_BY_64_TL = 0x1.c85fdep-16f; // log2/64 tail: 0.0000272020388<br class="">+    r = mad(nf, -R_LOG2_BY_64_TL, mad(nf, -R_LOG2_BY_64_LD, ylogx)) + ylogx_t;<br class="">+<br class="">+    // Truncated Taylor series for e^r<br class="">+    poly = mad(mad(mad(r, 0x1.555556p-5f, 0x1.555556p-3f), r, 0x1.000000p-1f), r*r, r);<br class="">+<br class="">+    tv = USE_TABLE(exp_tbl_ep, j);<br class="">+<br class="">+    float expylogx = mad(tv.s0, poly, mad(tv.s1, poly, tv.s1)) + tv.s0;<br class="">+    #if !defined(SUBNORMALS_SUPPORTED)<br class="">+<span class="Apple-tab-span" style="white-space: pre;">     </span><span class="Apple-tab-span" style="white-space: pre;">  </span>int explg = ((as_uint(expylogx) & EXPBITS_SP32 >> 23) - 127);<br class="">+<span class="Apple-tab-span" style="white-space: pre;">     </span><span class="Apple-tab-span" style="white-space: pre;">  </span>m = (23-(m + 149)) == 0 ? 1: m;<br class="">+<span class="Apple-tab-span" style="white-space: pre;">     </span><span class="Apple-tab-span" style="white-space: pre;">  </span>uint mantissa =  ((as_uint(expylogx) & MANTBITS_SP32)|IMPBIT_SP32) >> (23-(m + 149));<br class="">+<span class="Apple-tab-span" style="white-space: pre;">        </span><span class="Apple-tab-span" style="white-space: pre;">  </span>float sexpylogx = as_float(mantissa);<br class="">+    #else<br class="">+<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;">  </span>float sexpylogx = expylogx * as_float(0x1 << (m + 149));<br class="">+    #endif<br class="">+<br class="">+<br class="">+    float texpylogx = as_float(as_int(expylogx) + m2);<br class="">+    expylogx = m < -125 ? sexpylogx : texpylogx;<br class="">+<br class="">+    // Result is +-Inf if (ylogx + ylogx_t) > 128*log2<br class="">+    expylogx = ((ylogx > 0x1.62e430p+6f) | (ylogx == 0x1.62e430p+6f & ylogx_t > -0x1.05c610p-22f)) ? as_float(PINFBITPATT_SP32) : expylogx;<br class="">+<br class="">+    // Result is 0 if ylogx < -149*log2<br class="">+    expylogx = ylogx <  -0x1.9d1da0p+6f ? 0.0f : expylogx;<br class="">+<br class="">+    // Classify y:<br class="">+    //   inty = 0 means not an integer.<br class="">+    //   inty = 1 means odd integer.<br class="">+    //   inty = 2 means even integer.<br class="">+<br class="">+    int inty = 2 - (ny & 1);<br class="">+<br class="">+    float signval = as_float((as_uint(expylogx) ^ SIGNBIT_SP32));<br class="">+    expylogx = ((inty == 1) & !xpos) ? signval : expylogx;<br class="">+    int ret = as_int(expylogx);<br class="">+<br class="">+    // Corner case handling<br class="">+    int xinf = xpos ? PINFBITPATT_SP32 : NINFBITPATT_SP32;<br class="">+    ret = ((ax == 0) & !ypos & (inty == 1)) ? xinf : ret;<br class="">+    ret = ((ax == 0) & !ypos & (inty == 2)) ? PINFBITPATT_SP32 : ret;<br class="">+    ret = ((ax == 0) & ypos & (inty == 2)) ? 0 : ret;<br class="">+    int xzero = !xpos ? 0x80000000 : 0L;<br class="">+    ret = ((ax == 0) & ypos & (inty == 1)) ? xzero : ret;<br class="">+    ret = ((ix == NINFBITPATT_SP32) & !ypos & (inty == 1)) ? 0x80000000 : ret;<br class="">+    ret = ((ix == NINFBITPATT_SP32) & !ypos & (inty != 1)) ? 0 : ret;<br class="">+    ret = ((ix == NINFBITPATT_SP32) & ypos & (inty == 1)) ? NINFBITPATT_SP32 : ret;<br class="">+    ret = ((ix == NINFBITPATT_SP32) & ypos & (inty != 1)) ? PINFBITPATT_SP32 : ret;<br class="">+    ret = ((ix == PINFBITPATT_SP32) & !ypos) ? 0 : ret;<br class="">+    ret = ((ix == PINFBITPATT_SP32) & ypos) ? PINFBITPATT_SP32 : ret;<br class="">+    ret = ax > PINFBITPATT_SP32 ? ix : ret;<br class="">+    ret = ny == 0 ? 0x3f800000 : ret;<br class="">+<br class="">+    return as_float(ret);<br class="">+}<br class="">+_CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, float, __clc_pown, float, int)<br class="">+<br class="">+#ifdef cl_khr_fp64<br class="">+_CLC_DEF _CLC_OVERLOAD double __clc_pown(double x, int ny)<br class="">+{<br class="">+    const double real_log2_tail = 5.76999904754328540596e-08;<br class="">+    const double real_log2_lead = 6.93147122859954833984e-01;<br class="">+<br class="">+    double y = (double) ny;<br class="">+<br class="">+    long ux = as_long(x);<br class="">+    long ax = ux & (~SIGNBIT_DP64);<br class="">+    int xpos = ax == ux;<br class="">+<br class="">+    long uy = as_long(y);<br class="">+    long ay = uy & (~SIGNBIT_DP64);<br class="">+    int ypos = ay == uy;<br class="">+<br class="">+    // Extended precision log<br class="">+    double v, vt;<br class="">+    {<br class="">+        int exp = (int)(ax >> 52) - 1023;<br class="">+        int mask_exp_1023 = exp == -1023;<br class="">+        double xexp = (double) exp;<br class="">+        long mantissa = ax & 0x000FFFFFFFFFFFFFL;<br class="">+<br class="">+        long temp_ux = as_long(as_double(0x3ff0000000000000L | mantissa) - 1.0);<br class="">+        exp = ((temp_ux & 0x7FF0000000000000L) >> 52) - 2045;<br class="">+        double xexp1 = (double) exp;<br class="">+        long mantissa1 = temp_ux & 0x000FFFFFFFFFFFFFL;<br class="">+<br class="">+        xexp = mask_exp_1023 ? xexp1 : xexp;<br class="">+        mantissa = mask_exp_1023 ? mantissa1 : mantissa;<br class="">+<br class="">+        long rax = (mantissa & 0x000ff00000000000) + ((mantissa & 0x0000080000000000) << 1);<br class="">+        int index = rax >> 44;<br class="">+<br class="">+        double F = as_double(rax | 0x3FE0000000000000L);<br class="">+        double Y = as_double(mantissa | 0x3FE0000000000000L);<br class="">+        double f = F - Y;<br class="">+        double2 tv = USE_TABLE(log_f_inv_tbl, index);<br class="">+        double log_h = tv.s0;<br class="">+        double log_t = tv.s1;<br class="">+        double f_inv = (log_h + log_t) * f;<br class="">+        double r1 = as_double(as_long(f_inv) & 0xfffffffff8000000L);<br class="">+        double r2 = fma(-F, r1, f) * (log_h + log_t);<br class="">+        double r = r1 + r2;<br class="">+<br class="">+        double poly = fma(r,<br class="">+                          fma(r,<br class="">+                              fma(r,<br class="">+                                  fma(r, 1.0/7.0, 1.0/6.0),<br class="">+                                  1.0/5.0),<br class="">+                              1.0/4.0),<br class="">+                          1.0/3.0);<br class="">+        poly = poly * r * r * r;<br class="">+<br class="">+        double hr1r1 = 0.5*r1*r1;<br class="">+        double poly0h = r1 + hr1r1;<br class="">+        double poly0t = r1 - poly0h + hr1r1;<br class="">+<span class="Apple-tab-span" style="white-space: pre;">     </span>poly = fma(r1, r2, fma(0.5*r2, r2, poly)) + r2 + poly0t;<br class=""></blockquote><br class="">There seems something wrong with the indentation here. The same holds for the other two patches.<br class=""><br class="">Jeroen<br class=""><br class=""><blockquote type="cite" class="">+<br class="">+        tv = USE_TABLE(powlog_tbl, index);<br class="">+        log_h = tv.s0;<br class="">+        log_t = tv.s1;<br class="">+<br class="">+        double resT_t = fma(xexp, real_log2_tail, + log_t) - poly;<br class="">+        double resT = resT_t - poly0h;<br class="">+        double resH = fma(xexp, real_log2_lead, log_h);<br class="">+        double resT_h = poly0h;<br class="">+<br class="">+        double H = resT + resH;<br class="">+        double H_h = as_double(as_long(H) & 0xfffffffff8000000L);<br class="">+        double T = (resH - H + resT) + (resT_t - (resT + resT_h)) + (H - H_h);<br class="">+        H = H_h;<br class="">+<br class="">+        double y_head = as_double(uy & 0xfffffffff8000000L);<br class="">+        double y_tail = y - y_head;<br class="">+<br class="">+        int mask_2_24 = ay > 0x4170000000000000; // 2^24<br class="">+        int nyh = convert_int(y_head);<br class="">+        int nyt = ny - nyh;<br class="">+        double y_tail1 = (double)nyt;<br class="">+        y_tail = mask_2_24 ? y_tail1 : y_tail;<br class="">+<br class="">+        double temp = fma(y_tail, H, fma(y_head, T, y_tail*T));<br class="">+        v = fma(y_head, H, temp);<br class="">+        vt = fma(y_head, H, -v) + temp;<br class="">+    }<br class="">+<br class="">+    // Now calculate exp of (v,vt)<br class="">+<br class="">+    double expv;<br class="">+    {<br class="">+        const double max_exp_arg = 709.782712893384;<br class="">+        const double min_exp_arg = -745.1332191019411;<br class="">+        const double sixtyfour_by_lnof2 = 92.33248261689366;<br class="">+        const double lnof2_by_64_head = 0.010830424260348081;<br class="">+        const double lnof2_by_64_tail = -4.359010638708991e-10;<br class="">+<br class="">+        double temp = v * sixtyfour_by_lnof2;<br class="">+        int n = (int)temp;<br class="">+        double dn = (double)n;<br class="">+        int j = n & 0x0000003f;<br class="">+        int m = n >> 6;<br class="">+<br class="">+        double2 tv = USE_TABLE(two_to_jby64_ep_tbl, j);<br class="">+        double f1 = tv.s0;<br class="">+        double f2 = tv.s1;<br class="">+        double f = f1 + f2;<br class="">+<br class="">+        double r1 = fma(dn, -lnof2_by_64_head, v);<br class="">+        double r2 = dn * lnof2_by_64_tail;<br class="">+        double r = (r1 + r2) + vt;<br class="">+<br class="">+        double q = fma(r,<br class="">+                       fma(r,<br class="">+                           fma(r,<br class="">+                               fma(r, 1.38889490863777199667e-03, 8.33336798434219616221e-03),<br class="">+                               4.16666666662260795726e-02),<br class="">+                           1.66666666665260878863e-01),<br class="">+                       5.00000000000000008883e-01);<br class="">+        q = fma(r*r, q, r);<br class="">+<br class="">+        expv = fma(f, q, f2) + f1;<br class="">+<span class="Apple-tab-span" style="white-space: pre;">       </span><span class="Apple-converted-space"> </span>     expv = ldexp(expv, m);<br class="">+<br class="">+        expv = v > max_exp_arg ? as_double(0x7FF0000000000000L) : expv;<br class="">+        expv = v < min_exp_arg ? 0.0 : expv;<br class="">+    }<br class="">+<br class="">+    // See whether y is an integer.<br class="">+    // inty = 0 means not an integer.<br class="">+    // inty = 1 means odd integer.<br class="">+    // inty = 2 means even integer.<br class="">+<br class="">+    int inty = 2 - (ny & 1);<br class="">+<br class="">+    expv *= ((inty == 1) & !xpos) ? -1.0 : 1.0;<br class="">+<br class="">+    long ret = as_long(expv);<br class="">+<br class="">+    // Now all the edge cases<br class="">+    long xinf = xpos ? PINFBITPATT_DP64 : NINFBITPATT_DP64;<br class="">+    ret = ((ax == 0L) & !ypos & (inty == 1)) ? xinf : ret;<br class="">+    ret = ((ax == 0L) & !ypos & (inty == 2)) ? PINFBITPATT_DP64 : ret;<br class="">+    ret = ((ax == 0L) & ypos & (inty == 2)) ? 0L : ret;<br class="">+    long xzero = !xpos ? 0x8000000000000000L : 0L;<br class="">+    ret = ((ax == 0L) & ypos & (inty == 1)) ? xzero : ret;<br class="">+    ret = ((ux == NINFBITPATT_DP64) & !ypos & (inty == 1)) ? 0x8000000000000000L : ret;<br class="">+    ret = ((ux == NINFBITPATT_DP64) & !ypos & (inty != 1)) ? 0L : ret;<br class="">+    ret = ((ux == NINFBITPATT_DP64) & ypos & (inty == 1)) ? NINFBITPATT_DP64 : ret;<br class="">+    ret = ((ux == NINFBITPATT_DP64) & ypos & (inty != 1)) ? PINFBITPATT_DP64 : ret;<br class="">+    ret = ((ux == PINFBITPATT_DP64) & !ypos) ? 0L : ret;<br class="">+    ret = ((ux == PINFBITPATT_DP64) & ypos) ? PINFBITPATT_DP64 : ret;<br class="">+    ret = ax > PINFBITPATT_DP64 ? ux : ret;<br class="">+    ret = ny == 0 ? 0x3ff0000000000000L : ret;<br class="">+<br class="">+    return as_double(ret);<br class="">+}<br class="">+_CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, double, __clc_pown, double, int)<br class="">+#endif<br class="">diff --git a/generic/lib/math/pown.cl b/generic/lib/math/pown.cl<br class="">index f3b27d4..7652cd5 100644<br class="">--- a/generic/lib/math/pown.cl<br class="">+++ b/generic/lib/math/pown.cl<br class="">@@ -1,10 +1,6 @@<br class="">#include <clc/clc.h><br class="">-#include "../clcmacro.h"<br class=""><br class="">-_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, pown, float, int)<br class="">+#include <math/clc_pown.h><br class=""><br class="">-#ifdef cl_khr_fp64<br class="">-#pragma OPENCL EXTENSION cl_khr_fp64 : enable<br class="">-<br class="">-_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, pown, double, int)<br class="">-#endif<br class="">+#define __CLC_BODY <pown.inc><br class="">+#include <clc/math/gentype.inc><br class="">diff --git a/generic/lib/math/pown.inc b/generic/lib/math/pown.inc<br class="">new file mode 100644<br class="">index 0000000..84729d9<br class="">--- /dev/null<br class="">+++ b/generic/lib/math/pown.inc<br class="">@@ -0,0 +1,3 @@<br class="">+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE pown(__CLC_GENTYPE x, __CLC_INTN y) {<br class="">+  return __clc_pown(x, y);<br class="">+}<br class="">--<span class="Apple-converted-space"> </span><br class="">2.14.3<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="">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>