[libclc] r217511 - math: Add tan implementation

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


Author: awatry
Date: Wed Sep 10 10:43:35 2014
New Revision: 217511

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

Uses the algorithm:
tan(x) = sin(x) / sqrt(1-sin^2(x))

An alternative is:
tan(x) = sin(x) / cos(x)

Which produces more verbose bitcode and longer assembly.

Either way, the generated bitcode seems pretty nasty and a more optimized
but still precise-enough solution is welcome.

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/tan.h
    libclc/trunk/generic/include/clc/math/tan.inc
    libclc/trunk/generic/lib/math/tan.cl
    libclc/trunk/generic/lib/math/tan.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=217511&r1=217510&r2=217511&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Wed Sep 10 10:43:35 2014
@@ -60,6 +60,7 @@
 #include <clc/math/sin.h>
 #include <clc/math/sincos.h>
 #include <clc/math/sqrt.h>
+#include <clc/math/tan.h>
 #include <clc/math/trunc.h>
 #include <clc/math/native_cos.h>
 #include <clc/math/native_divide.h>

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

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

Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=217511&r1=217510&r2=217511&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Wed Sep 10 10:43:35 2014
@@ -48,6 +48,7 @@ math/pown.cl
 math/sin.cl
 math/sincos.cl
 math/sincos_helpers.cl
+math/tan.cl
 relational/all.cl
 relational/any.cl
 relational/isequal.cl

Added: libclc/trunk/generic/lib/math/tan.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/tan.cl?rev=217511&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/tan.cl (added)
+++ libclc/trunk/generic/lib/math/tan.cl Wed Sep 10 10:43:35 2014
@@ -0,0 +1,8 @@
+#include <clc/clc.h>
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+#endif
+
+#define __CLC_BODY <tan.inc>
+#include <clc/math/gentype.inc>

Added: libclc/trunk/generic/lib/math/tan.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/tan.inc?rev=217511&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/tan.inc (added)
+++ libclc/trunk/generic/lib/math/tan.inc Wed Sep 10 10:43:35 2014
@@ -0,0 +1,8 @@
+/*
+ * Note: tan(x) = sin(x)/cos(x) also, but the final assembly ends up being
+ *       twice as long for R600 (maybe for others as well).
+ */
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE tan(__CLC_GENTYPE x) {
+  __CLC_GENTYPE sinx = sin(x);
+  return sinx / sqrt( (__CLC_GENTYPE) 1.0 - (sinx*sinx) );
+}





More information about the cfe-commits mailing list