[Beignet] [PATCH] Improve the accuracy of built-in function asin.

Zhigang Gong zhigang.gong at gmail.com
Tue Aug 6 23:59:31 PDT 2013


Thanks for the patch. Pushed.

On Wed, Aug 07, 2013 at 02:32:41AM +0000, Xing, Homer wrote:
> Good idea. This patch looks good to me.
> 
> Homer
> 
> -----Original Message-----
> From: beignet-bounces+homer.xing=intel.com at lists.freedesktop.org [mailto:beignet-bounces+homer.xing=intel.com at lists.freedesktop.org] On Behalf Of Yi Sun
> Sent: Tuesday, August 6, 2013 10:03 PM
> To: beignet at lists.freedesktop.org
> Cc: Sun, Yi; Jin, Gordon
> Subject: [Beignet] [PATCH] Improve the accuracy of built-in function asin.
> 
> Method: asin(x) = x + (1 * x^3)/(2 * 3) + (1 * 3 * x^5)/(2*4 * 5) + \
> 	(1 * 3 * 5 * x^7)/(2*4*6 * 7) + ...
> Iterate this for 30 times.
> 
> Signed-off-by: Yi Sun <yi.sun at intel.com>
> ---
>  backend/src/ocl_stdlib.tmpl.h |   11 ++++++++++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
> 
> diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index c972a3e..8002a85 100644
> --- a/backend/src/ocl_stdlib.tmpl.h
> +++ b/backend/src/ocl_stdlib.tmpl.h
> @@ -562,7 +562,16 @@ INLINE_OVERLOADABLE float __gen_ocl_internal_tanh(float x) {
>    return (1 - y) / (1 + y);
>  }
>  INLINE_OVERLOADABLE float __gen_ocl_internal_asin(float x) {
> -  return x + __gen_ocl_pow(x, 3) / 6 + __gen_ocl_pow(x, 5) * 3 / 40 + __gen_ocl_pow(x, 7) * 5 / 112;
> +  float sum = x, c = x, m = 1.0;
> +  int n = 1;
> +  do
> +  {
> +    c *= (2 * n - 1) * x * x;
> +    m *= (2 * n);
> +    sum += ( c / m / (2 * n + 1));
> +    n++;
> +  }while( n < 30);
> +  return sum;
>  }
>  INLINE_OVERLOADABLE float __gen_ocl_internal_asinpi(float x) {
>    return __gen_ocl_internal_asin(x) / M_PI_F;
> --
> 1.7.6.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list