[Beignet] [PATCH v2 1/2] add built-in function "frexp"
Zhigang Gong
zhigang.gong at linux.intel.com
Mon Jul 15 23:29:33 PDT 2013
On Tue, Jul 16, 2013 at 02:10:16PM +0800, Homer Hsing wrote:
>
> Signed-off-by: Homer Hsing <homer.xing at intel.com>
> ---
> backend/src/ocl_stdlib.h | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/backend/src/ocl_stdlib.h b/backend/src/ocl_stdlib.h
> index fbdc703..b548027 100644
> --- a/backend/src/ocl_stdlib.h
> +++ b/backend/src/ocl_stdlib.h
> @@ -5174,6 +5174,38 @@ DEF(16)
> #undef DEC8
> #undef DEC16
>
> +INLINE_OVERLOADABLE float frexp(float x, int *exp) {
> + uint u = as_uint(x);
> + if ((u & 0x7FFFFFFFu) == 0)
> + return x;
did you forget to add *exp = 0 before the above return x?
The reason why the unit test doesn't hit this bug is that the
case only check the mantissa for those special cases.
I suggest you to fix this bug here, and also refine your
unit test case to check both the mantissa and exponent for
the special cases.
> + int e = (u >> 23) & 255;
> + if (e == 255)
> + return x;
> + *exp = e - 126;
> + u = (u & (0x807FFFFFu)) | 0x3F000000;
> + return as_float(u);
> +}
> +
> +INLINE_OVERLOADABLE float2 frexp(float2 x, int2 *exp) {
> + return (float2)(frexp(x.s0, (int *)exp), frexp(x.s1, 1 + (int *)exp));
> +}
> +
> +INLINE_OVERLOADABLE float3 frexp(float3 x, int3 *exp) {
> + return (float3)(frexp(x.s0, (int *)exp), frexp(x.s1, 1 + (int *)exp), frexp(x.s2, 2 + (int *)exp));
> +}
> +
> +INLINE_OVERLOADABLE float4 frexp(float4 x, int4 *exp) {
> + return (float4)(frexp(x.s0, (int *)exp), frexp(x.s1, 1 + (int *)exp), frexp(x.s2, 2 + (int *)exp), frexp(x.s3, 3 + (int *)exp));
> +}
> +
> +INLINE_OVERLOADABLE float8 frexp(float8 x, int8 *exp) {
> + return (float8)(frexp(x.s0, (int *)exp), frexp(x.s1, 1 + (int *)exp), frexp(x.s2, 2 + (int *)exp), frexp(x.s3, 3 + (int *)exp), frexp(x.s4, 4 + (int *)exp), frexp(x.s5, 5 + (int *)exp), frexp(x.s6, 6 + (int *)exp), frexp(x.s7, 7 + (int *)exp));
> +}
> +
> +INLINE_OVERLOADABLE float16 frexp(float16 x, int16 *exp) {
> + return (float16)(frexp(x.s0, (int *)exp), frexp(x.s1, 1 + (int *)exp), frexp(x.s2, 2 + (int *)exp), frexp(x.s3, 3 + (int *)exp), frexp(x.s4, 4 + (int *)exp), frexp(x.s5, 5 + (int *)exp), frexp(x.s6, 6 + (int *)exp), frexp(x.s7, 7 + (int *)exp), frexp(x.s8, 8 + (int *)exp), frexp(x.s9, 9 + (int *)exp), frexp(x.sa, 10 + (int *)exp), frexp(x.sb, 11 + (int *)exp), frexp(x.sc, 12 + (int *)exp), frexp(x.sd, 13 + (int *)exp), frexp(x.se, 14 + (int *)exp), frexp(x.sf, 15 + (int *)exp));
> +}
> +
> INLINE_OVERLOADABLE float degrees(float radians) { return (180 / M_PI_F) * radians; }
> INLINE_OVERLOADABLE float2 degrees(float2 r) { return (float2)(degrees(r.s0), degrees(r.s1)); }
> INLINE_OVERLOADABLE float3 degrees(float3 r) { return (float3)(degrees(r.s0), degrees(r.s1), degrees(r.s2)); }
> --
> 1.8.1.2
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list