<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Feb 11, 2016 at 2:19 PM, Jan Vesely <span dir="ltr"><<a href="mailto:jan.vesely@rutgers.edu" target="_blank">jan.vesely@rutgers.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On Wed, 2016-02-10 at 21:08 -0600, Aaron Watry via Libclc-dev wrote:<br>
> The scalar float/double function bodies are a direct copy/paste<br>
> with usage of the CLC wrappers to vectorize them.<br>
><br>
> Signed-off-by: Aaron Watry <<a href="mailto:awatry@gmail.com">awatry@gmail.com</a>><br>
> ---<br>
> These have been tested using the tests I just sent to the piglit<br>
> list.<br>
><br>
> Those tests only handle float, and ignore the ilogb(0) and ilogb(nan)<br>
> cases due to<br>
> the fact that ilogb(0||nan) can return either MAX_INT or MIN_INT<br>
> depending on the<br>
> implementation's desires.<br>
<br>
</span>shouldn't we add FP_ILOGB0 FP_ILOGNAN macros that go with this<br>
implementation?<br>
<div><div class="h5"><br></div></div></blockquote><div><br>Yeah, I guess we can do that now as well.<br><br></div><div>--Aaron<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="h5">
><br>
> If you want more input values tested, and have good candidates, let<br>
> me know. Otherwise, I<br>
> wouldn't turn down a run through the CTS if someone has a few minutes<br>
> (since I don't have access).<br>
><br>
>  generic/include/clc/clc.h          |  1 +<br>
>  generic/include/clc/math/ilogb.h   |  5 ++++<br>
>  generic/include/clc/math/ilogb.inc |  1 +<br>
>  generic/lib/SOURCES                |  1 +<br>
>  generic/lib/math/<a href="http://ilogb.cl" rel="noreferrer" target="_blank">ilogb.cl</a>          | 57<br>
> ++++++++++++++++++++++++++++++++++++++<br>
>  5 files changed, 65 insertions(+)<br>
>  create mode 100644 generic/include/clc/math/ilogb.h<br>
>  create mode 100644 generic/include/clc/math/ilogb.inc<br>
>  create mode 100644 generic/lib/math/<a href="http://ilogb.cl" rel="noreferrer" target="_blank">ilogb.cl</a><br>
><br>
> diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h<br>
> index 4060ea1..b106923 100644<br>
> --- a/generic/include/clc/clc.h<br>
> +++ b/generic/include/clc/clc.h<br>
> @@ -62,6 +62,7 @@<br>
>  #include <clc/math/half_rsqrt.h><br>
>  #include <clc/math/half_sqrt.h><br>
>  #include <clc/math/hypot.h><br>
> +#include <clc/math/ilogb.h><br>
>  #include <clc/math/ldexp.h><br>
>  #include <clc/math/log.h><br>
>  #include <clc/math/log10.h><br>
> diff --git a/generic/include/clc/math/ilogb.h<br>
> b/generic/include/clc/math/ilogb.h<br>
> new file mode 100644<br>
> index 0000000..2bb9e9c<br>
> --- /dev/null<br>
> +++ b/generic/include/clc/math/ilogb.h<br>
> @@ -0,0 +1,5 @@<br>
> +#define __CLC_BODY <clc/math/ilogb.inc><br>
> +<br>
> +#include <clc/math/gentype.inc><br>
> +<br>
> +#undef __CLC_BODY<br>
> diff --git a/generic/include/clc/math/ilogb.inc<br>
> b/generic/include/clc/math/ilogb.inc<br>
> new file mode 100644<br>
> index 0000000..7f99fb4<br>
> --- /dev/null<br>
> +++ b/generic/include/clc/math/ilogb.inc<br>
> @@ -0,0 +1 @@<br>
> +_CLC_OVERLOAD _CLC_DECL __CLC_INTN ilogb(__CLC_GENTYPE x);<br>
> diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES<br>
> index c3a5a8a..facb58b 100644<br>
> --- a/generic/lib/SOURCES<br>
> +++ b/generic/lib/SOURCES<br>
> @@ -90,6 +90,7 @@ math/<a href="http://frexp.cl" rel="noreferrer" target="_blank">frexp.cl</a><br>
>  math/<a href="http://half_rsqrt.cl" rel="noreferrer" target="_blank">half_rsqrt.cl</a><br>
>  math/<a href="http://half_sqrt.cl" rel="noreferrer" target="_blank">half_sqrt.cl</a><br>
>  math/<a href="http://hypot.cl" rel="noreferrer" target="_blank">hypot.cl</a><br>
> +math/<a href="http://ilogb.cl" rel="noreferrer" target="_blank">ilogb.cl</a><br>
>  math/<a href="http://clc_ldexp.cl" rel="noreferrer" target="_blank">clc_ldexp.cl</a><br>
>  math/<a href="http://ldexp.cl" rel="noreferrer" target="_blank">ldexp.cl</a><br>
>  math/<a href="http://log.cl" rel="noreferrer" target="_blank">log.cl</a><br>
> diff --git a/generic/lib/math/<a href="http://ilogb.cl" rel="noreferrer" target="_blank">ilogb.cl</a> b/generic/lib/math/<a href="http://ilogb.cl" rel="noreferrer" target="_blank">ilogb.cl</a><br>
> new file mode 100644<br>
> index 0000000..b783b7e<br>
> --- /dev/null<br>
> +++ b/generic/lib/math/<a href="http://ilogb.cl" rel="noreferrer" target="_blank">ilogb.cl</a><br>
> @@ -0,0 +1,57 @@<br>
> +/*<br>
> + * Copyright (c) 2015 Advanced Micro Devices, Inc.<br>
> + * Copyright (c) 2016 Aaron Watry<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person<br>
> obtaining a copy<br>
> + * of this software and associated documentation files (the<br>
> "Software"), to deal<br>
> + * in the Software without restriction, including without limitation<br>
> the rights<br>
> + * to use, copy, modify, merge, publish, distribute, sublicense,<br>
> and/or sell<br>
> + * copies of the Software, and to permit persons to whom the<br>
> Software is<br>
> + * furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be<br>
> included in<br>
> + * all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br>
> EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
> MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT<br>
> SHALL THE<br>
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
> OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
> ARISING FROM,<br>
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
> DEALINGS IN<br>
> + * THE SOFTWARE.<br>
> + */<br>
> +<br>
> +#include <clc/clc.h><br>
> +#include "../clcmacro.h"<br>
> +#include "math.h"<br>
> +<br>
> +_CLC_OVERLOAD _CLC_DEF int ilogb(float x) {<br>
> +    uint ux = as_uint(x);<br>
> +    uint ax = ux & EXSIGNBIT_SP32;<br>
> +    int rs = -118 - (int) clz(ux & MANTBITS_SP32);<br>
> +    int r = (int) (ax >> EXPSHIFTBITS_SP32) - EXPBIAS_SP32;<br>
> +    r = ax < 0x00800000U ? rs : r;<br>
> +    r = ax > EXPBITS_SP32 | ax == 0 ? 0x80000000 : r;<br>
> +    r = ax == EXPBITS_SP32 ? 0x7fffffff : r;<br>
> +    return r;<br>
> +}<br>
> +<br>
> +_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, ilogb, float);<br>
> +<br>
> +#ifdef cl_khr_fp64<br>
> +#pragma OPENCL EXTENSION cl_khr_fp64 : enable<br>
> +<br>
> +_CLC_OVERLOAD _CLC_DEF ilogb(double x) {<br>
> +    ulong ux = as_ulong(x);<br>
> +    ulong ax = ux & ~SIGNBIT_DP64;<br>
> +    int r = (int) (ax >> EXPSHIFTBITS_DP64) - EXPBIAS_DP64;<br>
> +    int rs = -1011 - (int) clz(ax & MANTBITS_DP64);<br>
> +    r = ax < 0x0010000000000000UL ? rs : r;<br>
> +    r = ax > 0x7ff0000000000000UL | ax == 0UL ? 0x80000000 : r;<br>
> +    r = ax == 0x7ff0000000000000UL ? 0x7fffffff : r;<br>
> +    return r;<br>
> +}<br>
> +<br>
> +_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, ilogb, double);<br>
> +<br>
> +#endif // cl_khr_fp64<br>
--<br>
</div></div>Jan Vesely <<a href="mailto:jan.vesely@rutgers.edu">jan.vesely@rutgers.edu</a>><br>
</blockquote></div><br></div></div>