File: tanh_d_ha.cl

package info (click to toggle)
intel-graphics-compiler2 2.16.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 106,644 kB
  • sloc: cpp: 805,640; lisp: 287,672; ansic: 16,414; python: 3,952; yacc: 2,588; lex: 1,666; pascal: 313; sh: 186; makefile: 35
file content (205 lines) | stat: -rw-r--r-- 6,843 bytes parent folder | download | duplicates (2)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*========================== begin_copyright_notice ============================

Copyright (C) 2024 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/
#include "../imf.h"
#pragma OPENCL FP_CONTRACT OFF
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___Shifter = {0x43280000000003FFuL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___L2E = {0x3FF71547652B82FEuL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___mL2 = {0xBFE62E42FEFA39EFuL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___mL2L = {0xBC7ABC9E3B39803FuL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c12 = {0x3ee1eed87b4210b8uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c11 = {0x3f0af62ca32f0745uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c10 = {0x3f327e5343c0a3f2uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c9 = {0x3f571ddf5a65250fuL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c8 = {0x3f7a01a017bc38bduL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c7 = {0x3f9a01a01b12e962uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c6 = {0x3fb6c16c16c1f571uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c5 = {0x3fd111111110f25euL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c4 = {0x3fe555555555553cuL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c3 = {0x3ff555555555555auL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c2 = {0x4000000000000000uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c1 = {0x4000000000000000uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dtanh_ha___c0 = {0x0000000000000000uL};

__attribute__((always_inline)) inline int
__ocl_svml_internal_dtanh_ha(double *px, double *pres) {
  int nRet = 0;
  double xin = *px;
  union {
    unsigned long w;
    unsigned int w32[2];
    int s32[2];
    double f;
  } x, xa, S, SR, SRl, res;
  unsigned long sgn_x;
  double dN, Rh, Rl, R0, poly, AX, Ah, Al, R, eps, Qh, Ql;
  double BX, Bh, Bl, poly0, poly_l, poly_l2, poly_h;
  float bf;
  x.f = xin;
  // absolute value
  xa.w = x.w & 0x7fffffffffffffffuL;
  // sign
  sgn_x = x.w ^ xa.w;
  // clamp range
  xa.f = ((xa.f > 20.0) && (xa.w <= 0x7ff0000000000000uL)) ? 20.0 : xa.f;
  // exp(2*xa.f)
  // Shifter + xa*log2e
  S.f = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(xa.f, __dtanh_ha___L2E.f,
                                               __dtanh_ha___Shifter.f);
  dN =
      SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(S.f, 1.0, -__dtanh_ha___Shifter.f);
  // (Rh + Rl) = N*log(2) + xa
  R0 = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(dN, __dtanh_ha___mL2.f, xa.f);
  Rh = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(dN, __dtanh_ha___mL2L.f, R0);
  Rl = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(R0, 1.0, -Rh);
  Rl = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(dN, __dtanh_ha___mL2L.f, Rl);
  // T = 2^(rint(2*xa*log2e))
  S.w <<= 52;
  // e^(2*Rh)
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(Rh, __dtanh_ha___c12.f,
                                                __dtanh_ha___c11.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, Rh, __dtanh_ha___c10.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, Rh, __dtanh_ha___c9.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, Rh, __dtanh_ha___c8.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, Rh, __dtanh_ha___c7.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, Rh, __dtanh_ha___c6.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, Rh, __dtanh_ha___c5.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, Rh, __dtanh_ha___c4.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, Rh, __dtanh_ha___c3.f);
  poly0 = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, Rh, __dtanh_ha___c2.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly0, Rh, __dtanh_ha___c1.f);
  poly_l2 =
      SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, 1.0, -__dtanh_ha___c1.f);
  poly_l2 = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly0, Rh, -poly_l2);
  poly_l = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly0, Rl, poly_l2);
  SR.f = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(S.f, Rh, 0.0);
  SRl.f = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(S.f, Rl, 0.0);
  poly_h = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(SR.f, poly, 0.0);
  // dividend
  AX = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(S.f, 1.0, -1.0);
  Ah = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly_h, 1.0, AX);
  Al = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(Ah, 1.0, -AX);
  Al = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(SR.f, poly, -Al);
  Al = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(SR.f, poly_l, Al);
  Al = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(SRl.f, 2.0, Al);
  Al = (AX == S.f) ? (Al - 1.0) : Al;
  // divisor
  BX = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(S.f, 1.0, 1.0);
  Bh = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly_h, 1.0, BX);
  Bl = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(Bh, 1.0, -BX);
  Bl = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(SR.f, poly, -Bl);
  Bl = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(SR.f, poly_l, Bl);
  Bl = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(SRl.f, 2.0, Bl);
  Bl = (BX == S.f) ? (Bl + 1.0) : Bl;
  // R ~ 1/B
  bf = (float)Bh;
  R = (double)1.0f / (bf);
  eps = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(Bh, -R, 1.0);
  eps = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(Bl, -R, eps);
  // eps + eps^2
  eps = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(eps, eps, eps);
  // A*R high, low
  Qh = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(Ah, R, 0.0);
  Ql = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(Ah, R, -Qh);
  Ql = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(Al, R, Ql);
  // result
  Ql = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(Qh, eps, Ql);
  res.f = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(Qh, 1.0, Ql);
  res.w ^= sgn_x;
  *pres = res.f;
  return nRet;
}
double __ocl_svml_tanh_ha(double x) {
  double r;
  __ocl_svml_internal_dtanh_ha(&x, &r);
  return r;
}