Cc<br><br><div class="gmail_quote"><div dir="ltr">On Mon, Mar 12, 2018, 5:15 PM Jan Vesely via Libclc-dev <<a href="mailto:libclc-dev@lists.llvm.org">libclc-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, 2018-03-11 at 22:28 -0400, Jan Vesely wrote:<br>
> Mostly ported form amd_builtins, uses only denormal path for fp32.<br>
> Passes piglit on turks<br>
<br>
this one actually passes CTS on turks as well (needs single-threaded<br>
invocation).<br></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br></blockquote></div><div><br></div><div>Speaking of, do you object to removing the compute memory pool in r600g since its the source of the threading issues?<br></div><div><br></div><div>--Aaron</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Jan<br>
<br>
> Passes CTS on carrizo<br>
><br>
> Signed-off-by: Jan Vesely <<a href="mailto:jan.vesely@rutgers.edu" target="_blank">jan.vesely@rutgers.edu</a>><br>
> ---<br>
><br>
> generic/include/clc/clc.h | 1 +<br>
> generic/include/clc/math/remainder.h | 4 +<br>
> generic/include/math/clc_remainder.h | 4 +<br>
> generic/lib/SOURCES | 2 +<br>
> generic/lib/math/<a href="http://clc_remainder.cl" rel="noreferrer" target="_blank">clc_remainder.cl</a> | 218 +++++++++++++++++++++++++++++++++++<br>
> generic/lib/math/<a href="http://remainder.cl" rel="noreferrer" target="_blank">remainder.cl</a> | 6 +<br>
> 6 files changed, 235 insertions(+)<br>
> create mode 100644 generic/include/clc/math/remainder.h<br>
> create mode 100644 generic/include/math/clc_remainder.h<br>
> create mode 100644 generic/lib/math/<a href="http://clc_remainder.cl" rel="noreferrer" target="_blank">clc_remainder.cl</a><br>
> create mode 100644 generic/lib/math/<a href="http://remainder.cl" rel="noreferrer" target="_blank">remainder.cl</a><br>
><br>
> diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h<br>
> index 36ab134..75ca7d0 100644<br>
> --- a/generic/include/clc/clc.h<br>
> +++ b/generic/include/clc/clc.h<br>
> @@ -103,6 +103,7 @@<br>
> #include <clc/math/pow.h><br>
> #include <clc/math/pown.h><br>
> #include <clc/math/powr.h><br>
> +#include <clc/math/remainder.h><br>
> #include <clc/math/rint.h><br>
> #include <clc/math/rootn.h><br>
> #include <clc/math/round.h><br>
> diff --git a/generic/include/clc/math/remainder.h b/generic/include/clc/math/remainder.h<br>
> new file mode 100644<br>
> index 0000000..5b5d78d<br>
> --- /dev/null<br>
> +++ b/generic/include/clc/math/remainder.h<br>
> @@ -0,0 +1,4 @@<br>
> +#define __CLC_FUNCTION remainder<br>
> +#define __CLC_BODY <clc/math/binary_decl_tt.inc><br>
> +#include <clc/math/gentype.inc><br>
> +#undef __CLC_FUNCTION<br>
> diff --git a/generic/include/math/clc_remainder.h b/generic/include/math/clc_remainder.h<br>
> new file mode 100644<br>
> index 0000000..db084cf<br>
> --- /dev/null<br>
> +++ b/generic/include/math/clc_remainder.h<br>
> @@ -0,0 +1,4 @@<br>
> +#define __CLC_FUNCTION __clc_remainder<br>
> +#define __CLC_BODY <clc/math/binary_decl_tt.inc><br>
> +#include <clc/math/gentype.inc><br>
> +#undef __CLC_FUNCTION<br>
> diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES<br>
> index 9c060ed..159950c 100644<br>
> --- a/generic/lib/SOURCES<br>
> +++ b/generic/lib/SOURCES<br>
> @@ -158,6 +158,8 @@ math/<a href="http://clc_pown.cl" rel="noreferrer" target="_blank">clc_pown.cl</a><br>
> math/<a href="http://pown.cl" rel="noreferrer" target="_blank">pown.cl</a><br>
> math/<a href="http://clc_powr.cl" rel="noreferrer" target="_blank">clc_powr.cl</a><br>
> math/<a href="http://powr.cl" rel="noreferrer" target="_blank">powr.cl</a><br>
> +math/<a href="http://clc_remainder.cl" rel="noreferrer" target="_blank">clc_remainder.cl</a><br>
> +math/<a href="http://remainder.cl" rel="noreferrer" target="_blank">remainder.cl</a><br>
> math/<a href="http://clc_rootn.cl" rel="noreferrer" target="_blank">clc_rootn.cl</a><br>
> math/<a href="http://rootn.cl" rel="noreferrer" target="_blank">rootn.cl</a><br>
> math/<a href="http://sin.cl" rel="noreferrer" target="_blank">sin.cl</a><br>
> diff --git a/generic/lib/math/<a href="http://clc_remainder.cl" rel="noreferrer" target="_blank">clc_remainder.cl</a> b/generic/lib/math/<a href="http://clc_remainder.cl" rel="noreferrer" target="_blank">clc_remainder.cl</a><br>
> new file mode 100644<br>
> index 0000000..ba50ee3<br>
> --- /dev/null<br>
> +++ b/generic/lib/math/<a href="http://clc_remainder.cl" rel="noreferrer" target="_blank">clc_remainder.cl</a><br>
> @@ -0,0 +1,218 @@<br>
> +/*<br>
> + * Copyright (c) 2014 Advanced Micro Devices, Inc.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a copy<br>
> + * of this software and associated documentation files (the "Software"), to deal<br>
> + * in the Software without restriction, including without limitation the rights<br>
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br>
> + * copies of the Software, and to permit persons to whom the Software is<br>
> + * furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be included in<br>
> + * all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br>
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br>
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br>
> + * THE SOFTWARE.<br>
> + */<br>
> +<br>
> +#include <clc/clc.h><br>
> +<br>
> +#include <math/clc_remainder.h><br>
> +#include "../clcmacro.h"<br>
> +#include "config.h"<br>
> +#include "math.h"<br>
> +<br>
> +_CLC_DEF _CLC_OVERLOAD float __clc_remainder(float x, float y)<br>
> +{<br>
> + int ux = as_int(x);<br>
> + int ax = ux & EXSIGNBIT_SP32;<br>
> + float xa = as_float(ax);<br>
> + int sx = ux ^ ax;<br>
> + int ex = ax >> EXPSHIFTBITS_SP32;<br>
> +<br>
> + int uy = as_int(y);<br>
> + int ay = uy & EXSIGNBIT_SP32;<br>
> + float ya = as_float(ay);<br>
> + int ey = ay >> EXPSHIFTBITS_SP32;<br>
> +<br>
> + float xr = as_float(0x3f800000 | (ax & 0x007fffff));<br>
> + float yr = as_float(0x3f800000 | (ay & 0x007fffff));<br>
> + int c;<br>
> + int k = ex - ey;<br>
> +<br>
> + uint q = 0;<br>
> +<br>
> + while (k > 0) {<br>
> + c = xr >= yr;<br>
> + q = (q << 1) | c;<br>
> + xr -= c ? yr : 0.0f;<br>
> + xr += xr;<br>
> + --k;<br>
> + }<br>
> +<br>
> + c = xr > yr;<br>
> + q = (q << 1) | c;<br>
> + xr -= c ? yr : 0.0f;<br>
> +<br>
> + int lt = ex < ey;<br>
> +<br>
> + q = lt ? 0 : q;<br>
> + xr = lt ? xa : xr;<br>
> + yr = lt ? ya : yr;<br>
> +<br>
> + c = (yr < 2.0f * xr) | ((yr == 2.0f * xr) & ((q & 0x1) == 0x1));<br>
> + xr -= c ? yr : 0.0f;<br>
> + q += c;<br>
> +<br>
> + float s = as_float(ey << EXPSHIFTBITS_SP32);<br>
> + xr *= lt ? 1.0f : s;<br>
> +<br>
> + c = ax == ay;<br>
> + xr = c ? 0.0f : xr;<br>
> +<br>
> + xr = as_float(sx ^ as_int(xr));<br>
> +<br>
> + c = ax > PINFBITPATT_SP32 | ay > PINFBITPATT_SP32 | ax == PINFBITPATT_SP32 | ay == 0;<br>
> + xr = c ? as_float(QNANBITPATT_SP32) : xr;<br>
> +<br>
> + return xr;<br>
> +<br>
> +}<br>
> +_CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, float, __clc_remainder, float, float);<br>
> +<br>
> +#ifdef cl_khr_fp64<br>
> +_CLC_DEF _CLC_OVERLOAD double __clc_remainder(double x, double y)<br>
> +{<br>
> + ulong ux = as_ulong(x);<br>
> + ulong ax = ux & ~SIGNBIT_DP64;<br>
> + ulong xsgn = ux ^ ax;<br>
> + double dx = as_double(ax);<br>
> + int xexp = convert_int(ax >> EXPSHIFTBITS_DP64);<br>
> + int xexp1 = 11 - (int) clz(ax & MANTBITS_DP64);<br>
> + xexp1 = xexp < 1 ? xexp1 : xexp;<br>
> +<br>
> + ulong uy = as_ulong(y);<br>
> + ulong ay = uy & ~SIGNBIT_DP64;<br>
> + double dy = as_double(ay);<br>
> + int yexp = convert_int(ay >> EXPSHIFTBITS_DP64);<br>
> + int yexp1 = 11 - (int) clz(ay & MANTBITS_DP64);<br>
> + yexp1 = yexp < 1 ? yexp1 : yexp;<br>
> +<br>
> + int qsgn = ((ux ^ uy) & SIGNBIT_DP64) == 0UL ? 1 : -1;<br>
> +<br>
> + // First assume |x| > |y|<br>
> +<br>
> + // Set ntimes to the number of times we need to do a<br>
> + // partial remainder. If the exponent of x is an exact multiple<br>
> + // of 53 larger than the exponent of y, and the mantissa of x is<br>
> + // less than the mantissa of y, ntimes will be one too large<br>
> + // but it doesn't matter - it just means that we'll go round<br>
> + // the loop below one extra time.<br>
> + int ntimes = max(0, (xexp1 - yexp1) / 53);<br>
> + double w = ldexp(dy, ntimes * 53);<br>
> + w = ntimes == 0 ? dy : w;<br>
> + double scale = ntimes == 0 ? 1.0 : 0x1.0p-53;<br>
> +<br>
> + // Each time round the loop we compute a partial remainder.<br>
> + // This is done by subtracting a large multiple of w<br>
> + // from x each time, where w is a scaled up version of y.<br>
> + // The subtraction must be performed exactly in quad<br>
> + // precision, though the result at each stage can<br>
> + // fit exactly in a double precision number.<br>
> + int i;<br>
> + double t, v, p, pp;<br>
> +<br>
> + for (i = 0; i < ntimes; i++) {<br>
> + // Compute integral multiplier<br>
> + t = trunc(dx / w);<br>
> +<br>
> + // Compute w * t in quad precision<br>
> + p = w * t;<br>
> + pp = fma(w, t, -p);<br>
> +<br>
> + // Subtract w * t from dx<br>
> + v = dx - p;<br>
> + dx = v + (((dx - v) - p) - pp);<br>
> +<br>
> + // If t was one too large, dx will be negative. Add back one w.<br>
> + dx += dx < 0.0 ? w : 0.0;<br>
> +<br>
> + // Scale w down by 2^(-53) for the next iteration<br>
> + w *= scale;<br>
> + }<br>
> +<br>
> + // One more time<br>
> + // Variable todd says whether the integer t is odd or not<br>
> + t = floor(dx / w);<br>
> + long lt = (long)t;<br>
> + int todd = lt & 1;<br>
> +<br>
> + p = w * t;<br>
> + pp = fma(w, t, -p);<br>
> + v = dx - p;<br>
> + dx = v + (((dx - v) - p) - pp);<br>
> + i = dx < 0.0;<br>
> + todd ^= i;<br>
> + dx += i ? w : 0.0;<br>
> +<br>
> + // At this point, dx lies in the range [0,dy)<br>
> +<br>
> + // For the fmod function, we're done apart from setting the correct sign.<br>
> + //<br>
> + // For the remainder function, we need to adjust dx<br>
> + // so that it lies in the range (-y/2, y/2] by carefully<br>
> + // subtracting w (== dy == y) if necessary. The rigmarole<br>
> + // with todd is to get the correct sign of the result<br>
> + // when x/y lies exactly half way between two integers,<br>
> + // when we need to choose the even integer.<br>
> +<br>
> + int al = (2.0*dx > w) | (todd & (2.0*dx == w));<br>
> + double dxl = dx - (al ? w : 0.0);<br>
> +<br>
> + int ag = (dx > 0.5*w) | (todd & (dx == 0.5*w));<br>
> + double dxg = dx - (ag ? w : 0.0);<br>
> +<br>
> + dx = dy < 0x1.0p+1022 ? dxl : dxg;<br>
> +<br>
> + double ret = as_double(xsgn ^ as_ulong(dx));<br>
> + dx = as_double(ax);<br>
> +<br>
> + // Now handle |x| == |y|<br>
> + int c = dx == dy;<br>
> + t = as_double(xsgn);<br>
> + ret = c ? t : ret;<br>
> +<br>
> + // Next, handle |x| < |y|<br>
> + c = dx < dy;<br>
> + ret = c ? x : ret;<br>
> +<br>
> + c &= (yexp < 1023 & 2.0*dx > dy) | (dx > 0.5*dy);<br>
> + // we could use a conversion here instead since qsgn = +-1<br>
> + p = qsgn == 1 ? -1.0 : 1.0;<br>
> + t = fma(y, p, x);<br>
> + ret = c ? t : ret;<br>
> +<br>
> + // We don't need anything special for |x| == 0<br>
> +<br>
> + // |y| is 0<br>
> + c = dy == 0.0;<br>
> + ret = c ? as_double(QNANBITPATT_DP64) : ret;<br>
> +<br>
> + // y is +-Inf, NaN<br>
> + c = yexp > BIASEDEMAX_DP64;<br>
> + t = y == y ? x : y;<br>
> + ret = c ? t : ret;<br>
> +<br>
> + // x is +=Inf, NaN<br>
> + c = xexp > BIASEDEMAX_DP64;<br>
> + ret = c ? as_double(QNANBITPATT_DP64) : ret;<br>
> +<br>
> + return ret;<br>
> +}<br>
> +_CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, double, __clc_remainder, double, double);<br>
> +#endif<br>
> diff --git a/generic/lib/math/<a href="http://remainder.cl" rel="noreferrer" target="_blank">remainder.cl</a> b/generic/lib/math/<a href="http://remainder.cl" rel="noreferrer" target="_blank">remainder.cl</a><br>
> new file mode 100644<br>
> index 0000000..0a22ee8<br>
> --- /dev/null<br>
> +++ b/generic/lib/math/<a href="http://remainder.cl" rel="noreferrer" target="_blank">remainder.cl</a><br>
> @@ -0,0 +1,6 @@<br>
> +#include <clc/clc.h><br>
> +#include <math/clc_remainder.h><br>
> +<br>
> +#define __CLC_FUNC remainder<br>
> +#define __CLC_BODY <clc_sw_binary.inc><br>
> +#include <clc/math/gentype.inc><br>
_______________________________________________<br>
Libclc-dev mailing list<br>
<a href="mailto:Libclc-dev@lists.llvm.org" target="_blank">Libclc-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev</a><br>
</blockquote></div>