[libclc] r234324 - Implement atanh builtin

Tom Stellard thomas.stellard at amd.com
Tue Apr 7 09:20:22 PDT 2015


Author: tstellar
Date: Tue Apr  7 11:20:22 2015
New Revision: 234324

URL: http://llvm.org/viewvc/llvm-project?rev=234324&view=rev
Log:
Implement atanh builtin

This implementation was ported from the AMD builtin library
and has been tested with piglit, OpenCV, and the ocl conformance tests.

Added:
    libclc/trunk/generic/include/clc/math/atanh.h
    libclc/trunk/generic/include/clc/math/atanh.inc
    libclc/trunk/generic/lib/math/atanh.cl
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=234324&r1=234323&r2=234324&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Tue Apr  7 11:20:22 2015
@@ -40,6 +40,7 @@
 #include <clc/math/asinpi.h>
 #include <clc/math/atan.h>
 #include <clc/math/atan2.h>
+#include <clc/math/atanh.h>
 #include <clc/math/atanpi.h>
 #include <clc/math/copysign.h>
 #include <clc/math/cos.h>

Added: libclc/trunk/generic/include/clc/math/atanh.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/atanh.h?rev=234324&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/math/atanh.h (added)
+++ libclc/trunk/generic/include/clc/math/atanh.h Tue Apr  7 11:20:22 2015
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2014, 2015 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.
+ */
+
+#define __CLC_BODY <clc/math/atanh.inc>
+#include <clc/math/gentype.inc>

Added: libclc/trunk/generic/include/clc/math/atanh.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/atanh.inc?rev=234324&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/math/atanh.inc (added)
+++ libclc/trunk/generic/include/clc/math/atanh.inc Tue Apr  7 11:20:22 2015
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2014, 2015 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.
+ */
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE atanh(__CLC_GENTYPE x);

Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=234324&r1=234323&r2=234324&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Tue Apr  7 11:20:22 2015
@@ -67,6 +67,7 @@ math/asinh.cl
 math/asinpi.cl
 math/atan.cl
 math/atan2.cl
+math/atanh.cl
 math/atanpi.cl
 math/copysign.cl
 math/cos.cl

Added: libclc/trunk/generic/lib/math/atanh.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/atanh.cl?rev=234324&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/atanh.cl (added)
+++ libclc/trunk/generic/lib/math/atanh.cl Tue Apr  7 11:20:22 2015
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2014,2015 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 "../clcmacro.h"
+
+_CLC_OVERLOAD _CLC_DEF float atanh(float x) {
+    uint ux = as_uint(x);
+    uint ax = ux & EXSIGNBIT_SP32;
+    uint xs = ux ^ ax;
+
+    // |x| > 1 or NaN
+    float z = as_float(QNANBITPATT_SP32);
+
+    // |x| == 1
+    float t = as_float(xs | PINFBITPATT_SP32);
+    z = ax == 0x3f800000U ? t : z;
+
+    // 1/2 <= |x| < 1
+    t = as_float(ax);
+    t = MATH_DIVIDE(2.0f*t, 1.0f - t);
+    t = 0.5f * log1p(t);
+    t = as_float(xs | as_uint(t));
+    z = ax < 0x3f800000U ? t : z;
+
+    // |x| < 1/2
+    t = x * x;
+    float a = mad(mad(0.92834212715e-2f, t, -0.28120347286e0f), t, 0.39453629046e0f);
+    float b = mad(mad(0.45281890445e0f, t, -0.15537744551e1f), t, 0.11836088638e1f);
+    float p = MATH_DIVIDE(a, b);
+    t = mad(x*t, p, x);
+    z = ax < 0x3f000000 ? t : z;
+
+    // |x| < 2^-13
+    z = ax < 0x39000000U ? x : z;
+
+    return z;
+}
+
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, atanh, float)
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_OVERLOAD _CLC_DEF double atanh(double x) {
+    double absx = fabs(x);
+
+    double ret = absx == 1.0 ? as_double(PINFBITPATT_DP64) : as_double(QNANBITPATT_DP64);
+
+    // |x| >= 0.5
+    // Note that atanh(x) = 0.5 * ln((1+x)/(1-x))
+    // For greater accuracy we use
+    // ln((1+x)/(1-x)) = ln(1 + 2x/(1-x)) = log1p(2x/(1-x)).
+    double r = 0.5 * log1p(2.0 * absx / (1.0 - absx));
+    ret = absx < 1.0 ? r : ret;
+
+    r = -ret;
+    ret = x < 0.0 ? r : ret;
+
+    // Arguments up to 0.5 in magnitude are
+    // approximated by a [5,5] minimax polynomial
+    double t = x * x;
+
+    double pn = fma(t,
+                    fma(t,
+                        fma(t,
+                            fma(t,
+                                fma(t, -0.10468158892753136958e-3, 0.28728638600548514553e-1),
+                                -0.28180210961780814148e0),
+                            0.88468142536501647470e0),
+                        -0.11028356797846341457e1),
+                    0.47482573589747356373e0);
+
+    double pd = fma(t,
+                    fma(t,
+                        fma(t,
+                            fma(t,
+                                fma(t, -0.35861554370169537512e-1, 0.49561196555503101989e0),
+                                -0.22608883748988489342e1),
+                            0.45414700626084508355e1),
+                        -0.41631933639693546274e1),
+                    0.14244772076924206909e1);
+
+    r = fma(x*t, pn/pd, x);
+    ret = absx < 0.5 ? r : ret;
+
+    return ret;
+}
+
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, atanh, double)
+
+#endif





More information about the cfe-commits mailing list