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
|
/*========================== 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;
} __dexp2_ha_Shifter = {0x43380000000003ffuL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_Shifter0 = {0x43380000000007feuL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c11 = {0x3dfea1c678ded0efuL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c10 = {0x3e3e6228be5a9ffduL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c9 = {0x3e7b524ca9ff39ccuL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c8 = {0x3eb62bfc2c7be078uL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c7 = {0x3eeffcbfc7e3f872uL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c6 = {0x3f2430913112cae8uL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c5 = {0x3f55d87fe78a0586uL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c4 = {0x3f83b2ab6fb9f1a3uL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c3 = {0x3fac6b08d704a0dbuL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c2 = {0x3fcebfbdff82c5aeuL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_c1 = {0x3fc8b90bfbe8e7bcuL};
static __constant union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} __dexp2_ha_thres = {0x408ff00000000000uL};
__attribute__((always_inline)) inline int
__ocl_svml_internal_dexp2_ha(double *a, double *r) {
int nRet = 0;
double x = *a;
union {
unsigned long w;
unsigned int w32[2];
int s32[2];
double f;
} dS, xin, res, T, T2, expon;
double dN, R, poly, High, Rh, Rl;
unsigned int xa32;
int sN, sN2;
dS.f = x + __dexp2_ha_Shifter.f;
dN = dS.f - __dexp2_ha_Shifter.f;
R = x - dN;
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(__dexp2_ha_c11.f, R,
__dexp2_ha_c10.f);
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dexp2_ha_c9.f);
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dexp2_ha_c8.f);
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dexp2_ha_c7.f);
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dexp2_ha_c6.f);
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dexp2_ha_c5.f);
// 1+0.5*R
High = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(R, 0.5, 1.0);
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dexp2_ha_c4.f);
// (0.5*R)_high
Rh = High - 1.0;
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dexp2_ha_c3.f);
// (0.5*R)_low
Rl = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(R, 0.5, (-Rh));
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dexp2_ha_c2.f);
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, __dexp2_ha_c1.f);
poly = SPIRV_OCL_BUILTIN(fma, _f64_f64_f64, )(poly, R, Rl);
res.f = High + poly;
if (SPIRV_OCL_BUILTIN(fabs, _f64, )(x) >= __dexp2_ha_thres.f)
goto EXP2_SPECIAL;
// final scaling
// res.w32[1] += (dS.w32[0] << 20);
expon.w = dS.w << 52;
res.f *= expon.f;
*r = res.f;
return nRet;
EXP2_SPECIAL:
xin.f = x;
xa32 = xin.w32[1] & 0x7fffffffuL;
if (xa32 >= 0x7ff00000u) {
if (xin.w == 0xfff0000000000000uL) {
*r = 0.0f;
return nRet;
} else // NaN or +Inf
{
*r = x + x;
return nRet;
}
}
x = SPIRV_OCL_BUILTIN(fmin, _f64_f64, )(x, 1536.0);
x = SPIRV_OCL_BUILTIN(fmax, _f64_f64, )(x, -1536.0);
dS.f = x + __dexp2_ha_Shifter0.f;
sN = dS.w32[0];
// fix res.f for very large |x|
res.f = SPIRV_OCL_BUILTIN(fmin, _f64_f64, )(res.f, 2.0);
res.f = SPIRV_OCL_BUILTIN(fmax, _f64_f64, )(res.f, 0.5);
// split the scaling coefficients
sN2 = sN >> 1;
sN -= sN2;
T.w = (sN /*+ 0x3ff*/);
T.w <<= 52;
T2.w = (sN2 /*+ 0x3ff*/);
T2.w <<= 52;
res.f *= T.f;
res.f *= T2.f;
nRet = (res.w < 0x0010000000000000uL) ? 4 : nRet;
nRet = (res.w == 0x7ff0000000000000uL) ? 3 : nRet;
*r = res.f;
return nRet;
}
double __ocl_svml_exp2_ha(double x) {
double r;
__ocl_svml_internal_dexp2_ha(&x, &r);
return r;
}
|