[libclc] r217510 - math: Add asin implementation

Aaron Watry awatry at gmail.com
Wed Sep 10 08:43:32 PDT 2014


Author: awatry
Date: Wed Sep 10 10:43:32 2014
New Revision: 217510

URL: http://llvm.org/viewvc/llvm-project?rev=217510&view=rev
Log:
math: Add asin implementation

asin(x) = atan2(x, sqrt( 1-x^2 ))

alternatively:
asin(x) = PI/2 - acos(x)

Use the atan2 implementation since it produces slightly shorter bitcode and
R600 machine code.

Signed-off-by: Aaron Watry <awatry at gmail.com>
Reviewed-by: Jan Vesely <jan.vesely at rutgers.edu>

Added:
    libclc/trunk/generic/include/clc/math/asin.h
    libclc/trunk/generic/include/clc/math/asin.inc
    libclc/trunk/generic/lib/math/asin.cl
    libclc/trunk/generic/lib/math/asin.inc
Modified:
    libclc/trunk/generic/include/clc/clc.h
    libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=217510&r1=217509&r2=217510&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Wed Sep 10 10:43:32 2014
@@ -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>

Added: libclc/trunk/generic/include/clc/math/asin.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/asin.h?rev=217510&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/math/asin.h (added)
+++ libclc/trunk/generic/include/clc/math/asin.h Wed Sep 10 10:43:32 2014
@@ -0,0 +1,2 @@
+#define __CLC_BODY <clc/math/asin.inc>
+#include <clc/math/gentype.inc>

Added: libclc/trunk/generic/include/clc/math/asin.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/asin.inc?rev=217510&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/math/asin.inc (added)
+++ libclc/trunk/generic/include/clc/math/asin.inc Wed Sep 10 10:43:32 2014
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE asin(__CLC_GENTYPE x);

Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=217510&r1=217509&r2=217510&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Wed Sep 10 10:43:32 2014
@@ -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

Added: libclc/trunk/generic/lib/math/asin.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/asin.cl?rev=217510&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/asin.cl (added)
+++ libclc/trunk/generic/lib/math/asin.cl Wed Sep 10 10:43:32 2014
@@ -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>

Added: libclc/trunk/generic/lib/math/asin.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/asin.inc?rev=217510&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/asin.inc (added)
+++ libclc/trunk/generic/lib/math/asin.inc Wed Sep 10 10:43:32 2014
@@ -0,0 +1,3 @@
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE asin(__CLC_GENTYPE x) {
+  return atan2(x, sqrt( (__CLC_GENTYPE)1.0 -(x*x) ));
+}
\ No newline at end of file





More information about the cfe-commits mailing list