File: log2_s_ha.cl

package info (click to toggle)
intel-graphics-compiler 1.0.17791.18-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 102,312 kB
  • sloc: cpp: 935,343; lisp: 286,143; ansic: 16,196; python: 3,279; yacc: 2,487; lex: 1,642; pascal: 300; sh: 174; makefile: 27
file content (167 lines) | stat: -rw-r--r-- 4,608 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 int w;
  float f;
  int i;
} __slog2_ha_two32 = {0x4f800000u};
static __constant union {
  unsigned int w;
  float f;
  int i;
} __slog2_ha_c10 = {0xbd8770dcu};
static __constant union {
  unsigned int w;
  float f;
  int i;
} __slog2_ha_c9 = {0x3e1c5827u};
static __constant union {
  unsigned int w;
  float f;
  int i;
} __slog2_ha_c8 = {0xbe434bdeu};
static __constant union {
  unsigned int w;
  float f;
  int i;
} __slog2_ha_c7 = {0x3e55e9b0u};
static __constant union {
  unsigned int w;
  float f;
  int i;
} __slog2_ha_c6 = {0xbe75d6cau};
static __constant union {
  unsigned int w;
  float f;
  int i;
} __slog2_ha_c5 = {0x3e93a7cbu};
static __constant union {
  unsigned int w;
  float f;
  int i;
} __slog2_ha_c4 = {0xbeb8aabcu};
static __constant union {
  unsigned int w;
  float f;
  int i;
} __slog2_ha_c3 = {0x3ef6389fu};
static __constant union {
  unsigned int w;
  float f;
  int i;
} __slog2_ha_c2h = {0xbf38aa3bu};
static __constant float __slog2_ha_c1h = 0x1.715476p+0;
static __constant float __slog2_ha_c1l = 0x1.4ae0cp-26;
__attribute__((always_inline)) inline int
__ocl_svml_internal_slog2_ha(float *a, float *r) {
  float xin = *a;
  union {
    unsigned int w;
    float f;
    int i;
  } x, mant, res;
  int iexpon;
  unsigned int xa;
  float R, poly, polyh, polyl, expon;
  int nRet = 0;
  x.f = xin;
  // normalize mantissa to [0.75, 1.5)
  // normalized, unbiased exponent
  iexpon = (x.w - 0x3f400000u) & 0xff800000u;
  // normalized mantissa
  mant.w = x.w - iexpon;
  // exponent
  iexpon >>= 23;
  // filter out denormals/zero/negative/Inf/NaN
  if ((unsigned int)(x.w - 0x00800000) >= 0x7f000000u)
    goto LOG2F_SPECIAL;
LOG2F_MAIN:
  // reduced argument
  R = mant.f - 1.0f;
  // polynomial
  poly = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(__slog2_ha_c10.f, R,
                                                __slog2_ha_c9.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(poly, R, __slog2_ha_c8.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(poly, R, __slog2_ha_c7.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(poly, R, __slog2_ha_c6.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(poly, R, __slog2_ha_c5.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(poly, R, __slog2_ha_c4.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(poly, R, __slog2_ha_c3.f);
  poly = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(poly, R, __slog2_ha_c2h.f);
  expon = (float)iexpon;
  polyh = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(poly, R, 0.0f);
  polyl = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(poly, R, -polyh);
  {
    float __ph, __ahl, __ahh;
    __ph = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(polyh, 1.0f, __slog2_ha_c1h);
    __ahh = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(__ph, 1.0f, -__slog2_ha_c1h);
    __ahl = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(polyh, 1.0f, -__ahh);
    polyl = (polyl + __slog2_ha_c1l) + __ahl;
    polyh = __ph;
  };
  {
    float __ph, __phl;
    __ph = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(polyh, R, 0.0f);
    __phl = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(polyh, R, -__ph);
    polyl = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(polyl, R, __phl);
    polyh = __ph;
  };
  {
    float __ph, __ahl, __ahh;
    __ph = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(polyh, 1.0f, expon);
    __ahh = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(__ph, 1.0f, -expon);
    __ahl = SPIRV_OCL_BUILTIN(fma, _f32_f32_f32, )(polyh, 1.0f, -__ahh);
    polyl = polyl + __ahl;
    polyh = __ph;
  };
  poly = polyh + polyl;
  *r = poly;
  return nRet;
LOG2F_SPECIAL:
  xa = x.w & 0x7fffffffu;
  // zero
  if (!xa) {
    nRet = 2;
    res.w = 0xff800000u;
    *r = res.f;
    return nRet;
  }
  // Inf/NaN or negative?
  if (x.w >= 0x7f800000u) {
    // +Inf?
    if (x.w == 0x7f800000u) {
      *r = x.f;
      return nRet;
    }
    // return QNaN
    nRet = 1;
    x.w |= 0x7fc00000u;
    *r = x.f;
    return nRet;
  }
  // positive denormal?
  if (!(xa & 0x7f800000)) {
    // scale x by 2^32
    x.f *= __slog2_ha_two32.f;
    // normalized, unbiased exponent
    iexpon = (x.w - 0x3f400000u) & 0xff800000u;
    // normalized mantissa
    mant.w = x.w - iexpon;
    // exponent
    iexpon >>= 23;
    iexpon -= 32;
  }
  goto LOG2F_MAIN;
}
float __ocl_svml_log2f_ha(float x) {
  float r;
  __ocl_svml_internal_slog2_ha(&x, &r);
  return r;
}