[Beignet] [PATCH] libocl: refine length() implementation.

Zhigang Gong zhigang.gong at linux.intel.com
Thu Jan 29 18:32:14 PST 2015


LGTM, will push latter, thanks.

On Thu, Jan 29, 2015 at 02:25:39PM +0800, Ruiling Song wrote:
> Just try to reduce if-branching.
> And the (m<1) condition check seems no use, so I remove it.
> 
> Signed-off-by: Ruiling Song <ruiling.song at intel.com>
> ---
>  backend/src/libocl/src/ocl_geometric.cl |   10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/backend/src/libocl/src/ocl_geometric.cl b/backend/src/libocl/src/ocl_geometric.cl
> index cd09968..07f1419 100644
> --- a/backend/src/libocl/src/ocl_geometric.cl
> +++ b/backend/src/libocl/src/ocl_geometric.cl
> @@ -38,13 +38,9 @@ OVERLOADABLE float dot(float4 p0, float4 p1) {
>  OVERLOADABLE float length(float x) { return __gen_ocl_fabs(x); }
>  
>  #define BODY \
> -  if(m == 0) \
> -    return 0; \
> -  if(isinf(m)) \
> -    return INFINITY; \
> -  if(m < 1) \
> -    m = 1; \
> -  x /= m; \
> +  m = m==0.0f ? 1.0f : m; \
> +  m = isinf(m) ? 1.0f : m; \
> +  x = x/m; \
>    return m * sqrt(dot(x,x));
>  OVERLOADABLE float length(float2 x) {
>    float m = max(__gen_ocl_fabs(x.s0), __gen_ocl_fabs(x.s1));
> -- 
> 1.7.10.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list