[Libclc-dev] [PATCH 1/2] math: Add asin implementation
Jan Vesely
jan.vesely at rutgers.edu
Fri Sep 5 10:54:21 PDT 2014
On Thu, 2014-09-04 at 12:35 -0500, Aaron Watry wrote:
> asin(x) = PI/2 - acos(x)
LGTM.
just out of curiosity.
How does the precision compare to just using
atan2(x, ( sqrt(1-x^2) ) )
from 5) of your acos patch?
I assume (PI/2 -) does not shift the balance.
jan
>
> We already have an implementation of acos(x), so just use that.
>
> Signed-off-by: Aaron Watry <awatry at gmail.com>
> ---
> generic/include/clc/clc.h | 1 +
> generic/include/clc/math/asin.h | 2 ++
> generic/include/clc/math/asin.inc | 1 +
> generic/lib/SOURCES | 1 +
> generic/lib/math/asin.cl | 8 ++++++++
> generic/lib/math/asin.inc | 11 +++++++++++
> 6 files changed, 24 insertions(+)
> create mode 100644 generic/include/clc/math/asin.h
> create mode 100644 generic/include/clc/math/asin.inc
> create mode 100644 generic/lib/math/asin.cl
> create mode 100644 generic/lib/math/asin.inc
>
> diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
> index 490893b..079c674 100644
> --- a/generic/include/clc/clc.h
> +++ b/generic/include/clc/clc.h
> @@ -33,6 +33,7 @@
>
> /* 6.11.2 Math Functions */
> #include <clc/math/acos.h>
> +#include <clc/math/asin.h>
> #include <clc/math/atan.h>
> #include <clc/math/atan2.h>
> #include <clc/math/copysign.h>
> diff --git a/generic/include/clc/math/asin.h b/generic/include/clc/math/asin.h
> new file mode 100644
> index 0000000..2a85872
> --- /dev/null
> +++ b/generic/include/clc/math/asin.h
> @@ -0,0 +1,2 @@
> +#define __CLC_BODY <clc/math/asin.inc>
> +#include <clc/math/gentype.inc>
> diff --git a/generic/include/clc/math/asin.inc b/generic/include/clc/math/asin.inc
> new file mode 100644
> index 0000000..b4ad8ff
> --- /dev/null
> +++ b/generic/include/clc/math/asin.inc
> @@ -0,0 +1 @@
> +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE asin(__CLC_GENTYPE x);
> diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
> index 8eaaa61..30e182f 100644
> --- a/generic/lib/SOURCES
> +++ b/generic/lib/SOURCES
> @@ -30,6 +30,7 @@ integer/sub_sat_if.ll
> integer/sub_sat_impl.ll
> integer/upsample.cl
> math/acos.cl
> +math/asin.cl
> math/atan.cl
> math/atan2.cl
> math/copysign.cl
> diff --git a/generic/lib/math/asin.cl b/generic/lib/math/asin.cl
> new file mode 100644
> index 0000000..d56dbd7
> --- /dev/null
> +++ b/generic/lib/math/asin.cl
> @@ -0,0 +1,8 @@
> +#include <clc/clc.h>
> +
> +#ifdef cl_khr_fp64
> +#pragma OPENCL EXTENSION cl_khr_fp64 : enable
> +#endif
> +
> +#define __CLC_BODY <asin.inc>
> +#include <clc/math/gentype.inc>
> diff --git a/generic/lib/math/asin.inc b/generic/lib/math/asin.inc
> new file mode 100644
> index 0000000..f1a65b3
> --- /dev/null
> +++ b/generic/lib/math/asin.inc
> @@ -0,0 +1,11 @@
> +#if __CLC_SCALAR_GENTYPE == double
> +#define PI2 M_PI_2
> +#else
> +#define PI2 M_PI_2_F
> +#endif
> +
> +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE asin(__CLC_GENTYPE x) {
> + return ( (__CLC_GENTYPE)PI2 - acos(x));
> +}
> +
> +#undef PI2
--
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/libclc-dev/attachments/20140905/b8c70845/attachment.sig>
More information about the Libclc-dev
mailing list