[Beignet] [PATCH] backend: add double support to fmax

Wang, Rander rander.wang at intel.com
Fri Mar 31 01:44:57 UTC 2017


Yes,  according to opencl spec, fmax behave as C99 and may not match the IEEE 754.


-----Original Message-----
From: Song, Ruiling 
Sent: Thursday, March 30, 2017 4:00 PM
To: Wang, Rander <rander.wang at intel.com>; beignet at freedesktop.org
Cc: Wang, Rander <rander.wang at intel.com>
Subject: RE: [Beignet] [PATCH] backend: add double support to fmax



> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf 
> Of rander
> Sent: Monday, March 27, 2017 5:40 PM
> To: beignet at freedesktop.org
> Cc: Wang, Rander <rander.wang at intel.com>
> Subject: [Beignet] [PATCH] backend: add double support to fmax
> 
> Signed-off-by: rander <rander.wang at intel.com>
> ---
>  backend/src/libocl/tmpl/ocl_math.tmpl.cl    | 15 +++++++++++++++
>  backend/src/libocl/tmpl/ocl_math.tmpl.h     |  2 ++
>  backend/src/libocl/tmpl/ocl_math_20.tmpl.cl | 11 +++++++++++  
> backend/src/libocl/tmpl/ocl_math_20.tmpl.h  |  2 ++
>  4 files changed, 30 insertions(+)
> 
> diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
> b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
> index d526d6c..6978c92 100644
> --- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
> +++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
> @@ -4333,3 +4333,18 @@ OVERLOADABLE double mad(double a, double b, 
> double c)
>  	return __gen_ocl_mad(a, b, c);
>  }
> 
> +OVERLOADABLE double fmax(double a, double b) {
> +	ulong ua = as_ulong(a);
> +	ulong ub =as_ulong(b);
> +
> +	if((ua & DF_ABS_MASK) > DF_MAX_NORMAL) return b;
> +	if((ub & DF_ABS_MASK) > DF_MAX_NORMAL) return a;
> +	if(ua == DF_POSITIVE_INF) return a;
> +	if(ub == DF_POSITIVE_INF) return b;
> +
Hardware cmp on double not conform to IEEE754?

> +	double c = a - b;
> +	return (c >= 0) ? a:b;
> +}
> +



More information about the Beignet mailing list