[PATCH v2 1/2] tan: Port from amd_builtins

v2: fixup constant precision
Passes piglit on turks and carrizo.
Passes CTS on carrizo
Fixes half_tan to pass CTS on carrizo

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>

Passes piglit on turks and carrizo.
Passes CTS on carrizo.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>

v2: fixup constant precision
Passes piglit on turks and carrizo.
Passes CTS on carrizo
Fixes half_tan to pass CTS on carrizo

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
---
generic/include/math/clc_tan.h | 5 +++
generic/lib/SOURCES | 1 +
generic/lib/math/clc_sw_unary.inc | 9 +++++
generic/lib/math/clc_tan.cl | 71 ++++++++++++++++++++++++++++++++++++++
generic/lib/math/sincosD_piby4.h | 55 +++++++++++++++++++++++++++++
generic/lib/math/sincos_helpers.cl | 17 +++++++++
generic/lib/math/sincos_helpers.h | 3 ++
generic/lib/math/tan.cl | 7 ++--
generic/lib/math/tan.inc | 17 ---------
9 files changed, 164 insertions(+), 21 deletions(-)
create mode 100644 generic/include/math/clc_tan.h
create mode 100644 generic/lib/math/clc_sw_unary.inc
create mode 100644 generic/lib/math/clc_tan.cl
delete mode 100644 generic/lib/math/tan.inc

diff --git a/generic/include/math/clc_tan.h b/generic/include/math/clc_tan.h
new file mode 100644
index 0000000..bc97902
--- /dev/null
+++ b/generic/include/math/clc_tan.h
@@ -0,0 +1,5 @@
+#define __CLC_FUNCTION __clc_tan
+#define __CLC_BODY <clc/math/unary_decl.inc>
+#include <clc/math/gentype.inc>
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 4c319a5..624180f 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -166,6 +166,7 @@ math/sinh.cl
math/sinpi.cl
math/clc_sqrt.cl
math/sqrt.cl
+math/clc_tan.cl
math/tan.cl
math/tanh.cl
math/tgamma.cl
diff --git a/generic/lib/math/clc_sw_unary.inc b/generic/lib/math/clc_sw_unary.inc
new file mode 100644
index 0000000..0f8467c
--- /dev/null
+++ b/generic/lib/math/clc_sw_unary.inc
@@ -0,0 +1,9 @@
+#include <utils.h>
+
+#define __CLC_SW_FUNC(x) __CLC_CONCAT(__clc_, x)
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNC(__CLC_GENTYPE x) {
+ return __CLC_SW_FUNC(__CLC_FUNC)(x);
+}
+
+#undef __CLC_SW_FUNC
diff --git a/generic/lib/math/clc_tan.cl b/generic/lib/math/clc_tan.cl
new file mode 100644
index 0000000..b7ad8f8
--- /dev/null
+++ b/generic/lib/math/clc_tan.cl
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include <clc/clc.h>
+
+#include "math.h"
+#include "sincos_helpers.h"
+#include "../clcmacro.h"
+#include "tables.h"
+
+_CLC_DEF _CLC_OVERLOAD float __clc_tan(float x)
+{
+ int ix = as_int(x);
+ int ax = ix & 0x7fffffff;
+ float dx = as_float(ax);
+
+ float r0, r1;
+ int regn = __clc_argReductionS(&r0, &r1, dx);
+
+ float t = __clc_tanf_piby4(r0 + r1, regn);
+ t = as_float(as_int(t) ^ (ix ^ ax));
+
+ t = ax >= PINFBITPATT_SP32 ? as_float(QNANBITPATT_SP32) : t;
+ //Take care of subnormals
+ t = (x == 0.0f) ? x : t;
+ return t;
+}
+_CLC_UNARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, float, __clc_tan, float);
+
+#ifdef cl_khr_fp64
+#include "sincosD_piby4.h"
+
+_CLC_DEF _CLC_OVERLOAD double __clc_tan(double x)
+{
+ double y = fabs(x);
+
+ double r, rr;
+ int regn;
+
+ if (y < 0x1.0p+30)
+ __clc_remainder_piby2_medium(y, &r, &rr, &regn);
+ else

Trailing whitespace here.

Otherwise:
Acked-By: Aaron Watry <awatry@gmail.com>
Tested-By: Aaron Watry <awatry@gmail.com>

(Tested on a Radeon RX 580)

I had confirmed some tan(x) wimpy-mode CTS failures before this patch
was applied, they're gone now.

Both tan and tanpi have passed a full CTS run on my system for float and double.

I don't feel sufficiently qualified to review the AMD tan/tanpi
implementations themselves, but given that CTS tests all possible
input values for the float implementation, I think we're ok here.

--Aaron