[Libclc-dev] [PATCH 1/2] math: Add asin implementation
Aaron Watry
awatry at gmail.com
Thu Sep 4 10:35:52 PDT 2014
asin(x) = PI/2 - acos(x)
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
--
1.9.1
More information about the Libclc-dev
mailing list