File: ln_d_ep.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 (167 lines) | stat: -rw-r--r-- 4,669 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
/*========================== 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;
} __dln_ep___c9 = {0xbfc11e70a5c9b8f8uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dln_ep___c8 = {0x3fc20827ee8835feuL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dln_ep___c7 = {0xbfbedf6494cc1f86uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dln_ep___c6 = {0x3fc1e531c40397e0uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dln_ep___c5 = {0xbfc55d72615e74d3uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dln_ep___c4 = {0x3fc99dac1eadbf8euL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dln_ep___c3 = {0xbfcfffcff3489b95uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dln_ep___c2 = {0x3fd5554dfa222c07uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dln_ep___c1 = {0xbfe00000145aea06uL};
static __constant union {
  unsigned long w;
  unsigned int w32[2];
  int s32[2];
  double f;
} __dln_ep___c0 = {0x3e30eba0cce2e0b0uL};
__attribute__((always_inline)) inline int
__ocl_svml_internal_dln_ep(double *a, double *r) {
  int nRet = 0;
  union {
    unsigned long w;
    unsigned int w32[2];
    int s32[2];
    double f;
  } x, expon, expon_r, one, l2;
  double R, d_expon;
  union {
    unsigned long w;
    unsigned int w32[2];
    int s32[2];
    double f;
  } denorm_scale;
  double poly, res;
  union {
    unsigned long w;
    unsigned int w32[2];
    int s32[2];
    double f;
  } _res;
  int denorm_scale_exp;
  x.f = *a;
  // special branch for +/-0, negatives, +INFs, +NaNs
  if ((x.w == 0x0uL) || (x.w >= 0x7ff0000000000000uL)) {
    // x = +/-0
    if ((x.w & 0x7fffffffffffffff) == 0x0uL) {
      nRet = 2;
      _res.w = 0xfff0000000000000uL;
      *r = _res.f;
      return nRet;
    }
    // x = any negative
    else if (x.w > 0x8000000000000000uL) {
      nRet = 1;
      _res.w = x.w | 0xfff8000000000000uL;
      *r = _res.f;
      return nRet;
    }
    // x = +NaN or +INF
    else {
      // x = +NaN
      if (x.w > 0x7ff0000000000000uL) {
        _res.f = x.f + x.f;
      }
      // x = +INF
      else {
        _res.w = x.w;
      }
      *r = _res.f;
      return nRet;
    } // x = +NaN or +INF
  }   // special branch for +/-0, negatives, +INFs, +NaNs
      // scale denormals
  denorm_scale.w = 0x43B0000000000000ull;
  denorm_scale_exp = (x.w <= 0x000fffffffffffffuL) ? (60 + 0x3FF) : 0x3FF;
  x.f = (x.w <= 0x000fffffffffffffuL) ? (x.f * denorm_scale.f) : x.f;
  // argument reduction to (-1/3, 1/3)
  // reduced exponent
  expon.w = x.w + 0x000AAAAAAAAAAAAAull;
  expon.w >>= 52;
  expon_r.w = expon.w << 52;
  // reduced mantissa
  one.w = 0x3FF0000000000000ull;
  x.w = (x.w + one.w) - expon_r.w;
  // reduced argument:  reduced_mantissa - 1.0
  R = x.f - one.f;
  // polynomial
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(__dln_ep___c9.f, R,
                                                __dln_ep___c8.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dln_ep___c7.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dln_ep___c6.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dln_ep___c5.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dln_ep___c4.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dln_ep___c3.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dln_ep___c2.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dln_ep___c1.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dln_ep___c0.f);
  // prepare exponent
  // scale back denormals
  expon.s32[0] -= denorm_scale_exp;
  // exponent
  d_expon = (double)expon.s32[0];
  // full polynomial = log(1+R)
  poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, R);
  // result:  reduced_exponent*log(2)+log(1+R)
  l2.w = 0x3FE62E42FEFA39EFull;
  res = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(d_expon, l2.f, poly);
  *r = res;
  return nRet;
}
double __ocl_svml_log_ep(double x) {
  double r;
  __ocl_svml_internal_dln_ep(&x, &r);
  return r;
}