File: sinh_fp64.cl

package info (click to toggle)
pocl 7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 29,768 kB
  • sloc: lisp: 151,669; ansic: 135,425; cpp: 65,801; python: 1,846; sh: 1,084; ruby: 255; pascal: 231; tcl: 180; makefile: 174; asm: 81; java: 72; xml: 49
file content (121 lines) | stat: -rw-r--r-- 4,420 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (c) 2014 Advanced Micro Devices, Inc.
 *
 * Copyright (c) 2017 Michal Babej / Tampere University of Technology
 *
 * 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.
 */



_CL_OVERLOADABLE vtype sinh(vtype x)
{
    // After dealing with special cases the computation is split into
    // regions as follows:
    //
    // abs(x) >= max_sinh_arg:
    // sinh(x) = sign(x)*Inf
    //
    // abs(x) >= small_threshold:
    // sinh(x) = sign(x)*exp(abs(x))/2 computed using the
    // splitexp and scaleDouble functions as for exp_amd().
    //
    // abs(x) < small_threshold:
    // compute p = exp(y) - 1 and then z = 0.5*(p+(p/(p+1.0)))
    // sinh(x) is then sign(x)*z.

    const vtype max_sinh_arg = 7.10475860073943977113e+02; // 0x408633ce8fb9f87e

    // This is where exp(-x) is insignificant compared to exp(x) = ln(2^27)
    const vtype small_threshold = 0x1.2b708872320e2p+4;

    vtype y = fabs(x);

    // In this range we find the integer part y0 of y
    // and the increment dy = y - y0. We then compute
    // z = sinh(y) = sinh(y0)cosh(dy) + cosh(y0)sinh(dy)
    // where sinh(y0) and cosh(y0) are obtained from tables

    vtype indv = trunc(y);
    itype indi = convert_itype(indv);
    indi = min((itype)indi, (itype)36U);

    vtype dy = y - indv;
    vtype dy2 = dy * dy;

    vtype sdy = dy * dy2 *
            pocl_fma(dy2,
              pocl_fma(dy2,
                pocl_fma(dy2,
                  pocl_fma(dy2,
                    pocl_fma(dy2,
                      pocl_fma(dy2,
                 (vtype)0.7746188980094184251527126e-12,
                 (vtype)0.160576793121939886190847e-9),
               (vtype)0.250521176994133472333666e-7),
             (vtype)0.275573191913636406057211e-5),
           (vtype)0.198412698413242405162014e-3),
         (vtype)0.833333333333329931873097e-2),
       (vtype)0.166666666666666667013899e0);

    vtype cdy = dy2 *
            pocl_fma(dy2,
              pocl_fma(dy2,
                pocl_fma(dy2,
                  pocl_fma(dy2,
                    pocl_fma(dy2,
                      pocl_fma(dy2,
                 (vtype)0.1163921388172173692062032e-10,
                 (vtype)0.208744349831471353536305e-8),
               (vtype)0.275573350756016588011357e-6),
             (vtype)0.248015872460622433115785e-4),
           (vtype)0.138888888889814854814536e-2),
         (vtype)0.416666666666660876512776e-1),
       (vtype)0.500000000000000005911074e0);

    // At this point sinh(dy) is approximated by dy + sdy.
    // Shift some significant bits from dy to sdy.
    vtype sdy1 = as_vtype(as_utype(dy) & 0xfffffffff8000000UL);
    vtype sdy2 = sdy + (dy - sdy1);

    v2type tv = USE_VTABLE(cosh_tbl, convert_uinttype(indi));
    vtype cl = tv.lo;
    vtype ct = tv.hi;

    tv = USE_VTABLE(sinh_tbl, convert_uinttype(indi));
    vtype sl = tv.lo;
    vtype st = tv.hi;


    vtype z = pocl_fma(cl, sdy1,
                pocl_fma(sl, cdy,
                  pocl_fma(cl, sdy2,
                    pocl_fma(ct, sdy1,
                      pocl_fma(st, cdy, ct*sdy2)) + st))) + sl;

    // Other cases
    z = (y < 0x1.0p-28) | isnan(x) | isinf(x) ? y : z;

    vtype t = exp(y - 0x1.62e42fefa3800p-1);
    t = pocl_fma(t, (vtype)-0x1.ef35793c76641p-45, t);
    z = (y >= small_threshold) ? t : z;
    z = (y >= max_sinh_arg) ? as_vtype((utype)PINFBITPATT_DP64) : z;

    return copysign(z, x);
}