mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 19:14:38 +02:00
8049043: Load variable through a pointer of an incompatible type in hotspot/src/share/vm/runtime/sharedRuntimeMath.hpp
Fixed parfait warnings caused by __HI and __LO macros in sharedRuntimeMath.hpp by using a union. Reviewed-by: kvn, drchase
This commit is contained in:
parent
d2a5b70cdf
commit
c36b77bbfd
3 changed files with 89 additions and 60 deletions
|
@ -27,20 +27,46 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
// VM_LITTLE_ENDIAN is #defined appropriately in the Makefiles
|
||||
// [jk] this is not 100% correct because the float word order may different
|
||||
// from the byte order (e.g. on ARM FPA)
|
||||
// Used to access the lower/higher 32 bits of a double
|
||||
typedef union {
|
||||
double d;
|
||||
struct {
|
||||
#ifdef VM_LITTLE_ENDIAN
|
||||
# define __HI(x) *(1+(int*)&x)
|
||||
# define __LO(x) *(int*)&x
|
||||
int lo;
|
||||
int hi;
|
||||
#else
|
||||
# define __HI(x) *(int*)&x
|
||||
# define __LO(x) *(1+(int*)&x)
|
||||
int hi;
|
||||
int lo;
|
||||
#endif
|
||||
} split;
|
||||
} DoubleIntConv;
|
||||
|
||||
static inline int high(double d) {
|
||||
DoubleIntConv x = { d };
|
||||
return x.split.hi;
|
||||
}
|
||||
|
||||
static inline int low(double d) {
|
||||
DoubleIntConv x = { d };
|
||||
return x.split.lo;
|
||||
}
|
||||
|
||||
static inline void set_high(double* d, int high) {
|
||||
DoubleIntConv conv = { *d };
|
||||
conv.split.hi = high;
|
||||
*d = conv.d;
|
||||
}
|
||||
|
||||
static inline void set_low(double* d, int low) {
|
||||
DoubleIntConv conv = { *d };
|
||||
conv.split.lo = low;
|
||||
*d = conv.d;
|
||||
}
|
||||
|
||||
static double copysignA(double x, double y) {
|
||||
__HI(x) = (__HI(x)&0x7fffffff)|(__HI(y)&0x80000000);
|
||||
return x;
|
||||
DoubleIntConv convX = { x };
|
||||
convX.split.hi = (convX.split.hi & 0x7fffffff) | (high(y) & 0x80000000);
|
||||
return convX.d;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -69,28 +95,30 @@ tiny = 1.0e-300;
|
|||
|
||||
static double scalbnA(double x, int n) {
|
||||
int k,hx,lx;
|
||||
hx = __HI(x);
|
||||
lx = __LO(x);
|
||||
hx = high(x);
|
||||
lx = low(x);
|
||||
k = (hx&0x7ff00000)>>20; /* extract exponent */
|
||||
if (k==0) { /* 0 or subnormal x */
|
||||
if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
|
||||
x *= two54;
|
||||
hx = __HI(x);
|
||||
hx = high(x);
|
||||
k = ((hx&0x7ff00000)>>20) - 54;
|
||||
if (n< -50000) return tiny*x; /*underflow*/
|
||||
}
|
||||
if (k==0x7ff) return x+x; /* NaN or Inf */
|
||||
k = k+n;
|
||||
if (k > 0x7fe) return hugeX*copysignA(hugeX,x); /* overflow */
|
||||
if (k > 0) /* normal result */
|
||||
{__HI(x) = (hx&0x800fffff)|(k<<20); return x;}
|
||||
if (k > 0) { /* normal result */
|
||||
set_high(&x, (hx&0x800fffff)|(k<<20));
|
||||
return x;
|
||||
}
|
||||
if (k <= -54) {
|
||||
if (n > 50000) /* in case integer overflow in n+k */
|
||||
return hugeX*copysignA(hugeX,x); /*overflow*/
|
||||
else return tiny*copysignA(tiny,x); /*underflow*/
|
||||
}
|
||||
k += 54; /* subnormal result */
|
||||
__HI(x) = (hx&0x800fffff)|(k<<20);
|
||||
set_high(&x, (hx&0x800fffff)|(k<<20));
|
||||
return x*twom54;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
// generated; can not figure out how to turn down optimization for one
|
||||
// file in the IDE on Windows
|
||||
#ifdef WIN32
|
||||
# pragma warning( disable: 4748 ) // /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function
|
||||
# pragma optimize ( "", off )
|
||||
#endif
|
||||
|
||||
|
@ -114,8 +115,8 @@ static double __ieee754_log(double x) {
|
|||
int k,hx,i,j;
|
||||
unsigned lx;
|
||||
|
||||
hx = __HI(x); /* high word of x */
|
||||
lx = __LO(x); /* low word of x */
|
||||
hx = high(x); /* high word of x */
|
||||
lx = low(x); /* low word of x */
|
||||
|
||||
k=0;
|
||||
if (hx < 0x00100000) { /* x < 2**-1022 */
|
||||
|
@ -123,13 +124,13 @@ static double __ieee754_log(double x) {
|
|||
return -two54/zero; /* log(+-0)=-inf */
|
||||
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
|
||||
k -= 54; x *= two54; /* subnormal number, scale up x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
hx = high(x); /* high word of x */
|
||||
}
|
||||
if (hx >= 0x7ff00000) return x+x;
|
||||
k += (hx>>20)-1023;
|
||||
hx &= 0x000fffff;
|
||||
i = (hx+0x95f64)&0x100000;
|
||||
__HI(x) = hx|(i^0x3ff00000); /* normalize x or x/2 */
|
||||
set_high(&x, hx|(i^0x3ff00000)); /* normalize x or x/2 */
|
||||
k += (i>>20);
|
||||
f = x-1.0;
|
||||
if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
|
||||
|
@ -208,8 +209,8 @@ static double __ieee754_log10(double x) {
|
|||
int i,k,hx;
|
||||
unsigned lx;
|
||||
|
||||
hx = __HI(x); /* high word of x */
|
||||
lx = __LO(x); /* low word of x */
|
||||
hx = high(x); /* high word of x */
|
||||
lx = low(x); /* low word of x */
|
||||
|
||||
k=0;
|
||||
if (hx < 0x00100000) { /* x < 2**-1022 */
|
||||
|
@ -217,14 +218,14 @@ static double __ieee754_log10(double x) {
|
|||
return -two54/zero; /* log(+-0)=-inf */
|
||||
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
|
||||
k -= 54; x *= two54; /* subnormal number, scale up x */
|
||||
hx = __HI(x); /* high word of x */
|
||||
hx = high(x); /* high word of x */
|
||||
}
|
||||
if (hx >= 0x7ff00000) return x+x;
|
||||
k += (hx>>20)-1023;
|
||||
i = ((unsigned)k&0x80000000)>>31;
|
||||
hx = (hx&0x000fffff)|((0x3ff-i)<<20);
|
||||
y = (double)(k+i);
|
||||
__HI(x) = hx;
|
||||
set_high(&x, hx);
|
||||
z = y*log10_2lo + ivln10*__ieee754_log(x);
|
||||
return z+y*log10_2hi;
|
||||
}
|
||||
|
@ -319,14 +320,14 @@ static double __ieee754_exp(double x) {
|
|||
int k=0,xsb;
|
||||
unsigned hx;
|
||||
|
||||
hx = __HI(x); /* high word of x */
|
||||
hx = high(x); /* high word of x */
|
||||
xsb = (hx>>31)&1; /* sign bit of x */
|
||||
hx &= 0x7fffffff; /* high word of |x| */
|
||||
|
||||
/* filter out non-finite argument */
|
||||
if(hx >= 0x40862E42) { /* if |x|>=709.78... */
|
||||
if(hx>=0x7ff00000) {
|
||||
if(((hx&0xfffff)|__LO(x))!=0)
|
||||
if(((hx&0xfffff)|low(x))!=0)
|
||||
return x+x; /* NaN */
|
||||
else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
|
||||
}
|
||||
|
@ -357,10 +358,10 @@ static double __ieee754_exp(double x) {
|
|||
if(k==0) return one-((x*c)/(c-2.0)-x);
|
||||
else y = one-((lo-(x*c)/(2.0-c))-hi);
|
||||
if(k >= -1021) {
|
||||
__HI(y) += (k<<20); /* add k to y's exponent */
|
||||
set_high(&y, high(y) + (k<<20)); /* add k to y's exponent */
|
||||
return y;
|
||||
} else {
|
||||
__HI(y) += ((k+1000)<<20);/* add k to y's exponent */
|
||||
set_high(&y, high(y) + ((k+1000)<<20)); /* add k to y's exponent */
|
||||
return y*twom1000;
|
||||
}
|
||||
}
|
||||
|
@ -447,8 +448,8 @@ double __ieee754_pow(double x, double y) {
|
|||
unsigned lx,ly;
|
||||
|
||||
i0 = ((*(int*)&one)>>29)^1; i1=1-i0;
|
||||
hx = __HI(x); lx = __LO(x);
|
||||
hy = __HI(y); ly = __LO(y);
|
||||
hx = high(x); lx = low(x);
|
||||
hy = high(y); ly = low(y);
|
||||
ix = hx&0x7fffffff; iy = hy&0x7fffffff;
|
||||
|
||||
/* y==zero: x**0 = 1 */
|
||||
|
@ -548,14 +549,14 @@ double __ieee754_pow(double x, double y) {
|
|||
u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
|
||||
v = t*ivln2_l-w*ivln2;
|
||||
t1 = u+v;
|
||||
__LO(t1) = 0;
|
||||
set_low(&t1, 0);
|
||||
t2 = v-(t1-u);
|
||||
} else {
|
||||
double ss,s2,s_h,s_l,t_h,t_l;
|
||||
n = 0;
|
||||
/* take care subnormal number */
|
||||
if(ix<0x00100000)
|
||||
{ax *= two53; n -= 53; ix = __HI(ax); }
|
||||
{ax *= two53; n -= 53; ix = high(ax); }
|
||||
n += ((ix)>>20)-0x3ff;
|
||||
j = ix&0x000fffff;
|
||||
/* determine interval */
|
||||
|
@ -563,17 +564,17 @@ double __ieee754_pow(double x, double y) {
|
|||
if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
|
||||
else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
|
||||
else {k=0;n+=1;ix -= 0x00100000;}
|
||||
__HI(ax) = ix;
|
||||
set_high(&ax, ix);
|
||||
|
||||
/* compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
|
||||
u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
|
||||
v = one/(ax+bp[k]);
|
||||
ss = u*v;
|
||||
s_h = ss;
|
||||
__LO(s_h) = 0;
|
||||
set_low(&s_h, 0);
|
||||
/* t_h=ax+bp[k] High */
|
||||
t_h = zeroX;
|
||||
__HI(t_h)=((ix>>1)|0x20000000)+0x00080000+(k<<18);
|
||||
set_high(&t_h, ((ix>>1)|0x20000000)+0x00080000+(k<<18));
|
||||
t_l = ax - (t_h-bp[k]);
|
||||
s_l = v*((u-s_h*t_h)-s_h*t_l);
|
||||
/* compute log(ax) */
|
||||
|
@ -582,32 +583,32 @@ double __ieee754_pow(double x, double y) {
|
|||
r += s_l*(s_h+ss);
|
||||
s2 = s_h*s_h;
|
||||
t_h = 3.0+s2+r;
|
||||
__LO(t_h) = 0;
|
||||
set_low(&t_h, 0);
|
||||
t_l = r-((t_h-3.0)-s2);
|
||||
/* u+v = ss*(1+...) */
|
||||
u = s_h*t_h;
|
||||
v = s_l*t_h+t_l*ss;
|
||||
/* 2/(3log2)*(ss+...) */
|
||||
p_h = u+v;
|
||||
__LO(p_h) = 0;
|
||||
set_low(&p_h, 0);
|
||||
p_l = v-(p_h-u);
|
||||
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
|
||||
z_l = cp_l*p_h+p_l*cp+dp_l[k];
|
||||
/* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */
|
||||
t = (double)n;
|
||||
t1 = (((z_h+z_l)+dp_h[k])+t);
|
||||
__LO(t1) = 0;
|
||||
set_low(&t1, 0);
|
||||
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
|
||||
}
|
||||
|
||||
/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
|
||||
y1 = y;
|
||||
__LO(y1) = 0;
|
||||
set_low(&y1, 0);
|
||||
p_l = (y-y1)*t1+y*t2;
|
||||
p_h = y1*t1;
|
||||
z = p_l+p_h;
|
||||
j = __HI(z);
|
||||
i = __LO(z);
|
||||
j = high(z);
|
||||
i = low(z);
|
||||
if (j>=0x40900000) { /* z >= 1024 */
|
||||
if(((j-0x40900000)|i)!=0) /* if z > 1024 */
|
||||
return s*hugeX*hugeX; /* overflow */
|
||||
|
@ -631,13 +632,13 @@ double __ieee754_pow(double x, double y) {
|
|||
n = j+(0x00100000>>(k+1));
|
||||
k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
|
||||
t = zeroX;
|
||||
__HI(t) = (n&~(0x000fffff>>k));
|
||||
set_high(&t, (n&~(0x000fffff>>k)));
|
||||
n = ((n&0x000fffff)|0x00100000)>>(20-k);
|
||||
if(j<0) n = -n;
|
||||
p_h -= t;
|
||||
}
|
||||
t = p_l+p_h;
|
||||
__LO(t) = 0;
|
||||
set_low(&t, 0);
|
||||
u = t*lg2_h;
|
||||
v = (p_l-(t-p_h))*lg2+t*lg2_l;
|
||||
z = u+v;
|
||||
|
@ -646,10 +647,10 @@ double __ieee754_pow(double x, double y) {
|
|||
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
|
||||
r = (z*t1)/(t1-two)-(w+z*w);
|
||||
z = one-(r-z);
|
||||
j = __HI(z);
|
||||
j = high(z);
|
||||
j += (n<<20);
|
||||
if((j>>20)<=0) z = scalbnA(z,n); /* subnormal output */
|
||||
else __HI(z) += (n<<20);
|
||||
else set_high(&z, high(z) + (n<<20));
|
||||
return s*z;
|
||||
}
|
||||
|
||||
|
|
|
@ -519,7 +519,7 @@ static double __kernel_sin(double x, double y, int iy)
|
|||
{
|
||||
double z,r,v;
|
||||
int ix;
|
||||
ix = __HI(x)&0x7fffffff; /* high word of x */
|
||||
ix = high(x)&0x7fffffff; /* high word of x */
|
||||
if(ix<0x3e400000) /* |x| < 2**-27 */
|
||||
{if((int)x==0) return x;} /* generate inexact */
|
||||
z = x*x;
|
||||
|
@ -574,9 +574,9 @@ C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
|
|||
|
||||
static double __kernel_cos(double x, double y)
|
||||
{
|
||||
double a,h,z,r,qx;
|
||||
double a,h,z,r,qx=0;
|
||||
int ix;
|
||||
ix = __HI(x)&0x7fffffff; /* ix = |x|'s high word*/
|
||||
ix = high(x)&0x7fffffff; /* ix = |x|'s high word*/
|
||||
if(ix<0x3e400000) { /* if x < 2**27 */
|
||||
if(((int)x)==0) return one; /* generate inexact */
|
||||
}
|
||||
|
@ -588,8 +588,8 @@ static double __kernel_cos(double x, double y)
|
|||
if(ix > 0x3fe90000) { /* x > 0.78125 */
|
||||
qx = 0.28125;
|
||||
} else {
|
||||
__HI(qx) = ix-0x00200000; /* x/4 */
|
||||
__LO(qx) = 0;
|
||||
set_high(&qx, ix-0x00200000); /* x/4 */
|
||||
set_low(&qx, 0);
|
||||
}
|
||||
h = 0.5*z-qx;
|
||||
a = one-qx;
|
||||
|
@ -654,11 +654,11 @@ static double __kernel_tan(double x, double y, int iy)
|
|||
{
|
||||
double z,r,v,w,s;
|
||||
int ix,hx;
|
||||
hx = __HI(x); /* high word of x */
|
||||
hx = high(x); /* high word of x */
|
||||
ix = hx&0x7fffffff; /* high word of |x| */
|
||||
if(ix<0x3e300000) { /* x < 2**-28 */
|
||||
if((int)x==0) { /* generate inexact */
|
||||
if (((ix | __LO(x)) | (iy + 1)) == 0)
|
||||
if (((ix | low(x)) | (iy + 1)) == 0)
|
||||
return one / fabsd(x);
|
||||
else {
|
||||
if (iy == 1)
|
||||
|
@ -667,10 +667,10 @@ static double __kernel_tan(double x, double y, int iy)
|
|||
double a, t;
|
||||
|
||||
z = w = x + y;
|
||||
__LO(z) = 0;
|
||||
set_low(&z, 0);
|
||||
v = y - (z - x);
|
||||
t = a = -one / w;
|
||||
__LO(t) = 0;
|
||||
set_low(&t, 0);
|
||||
s = one + t * z;
|
||||
return t + a * (s + t * v);
|
||||
}
|
||||
|
@ -705,10 +705,10 @@ static double __kernel_tan(double x, double y, int iy)
|
|||
/* compute -1.0/(x+r) accurately */
|
||||
double a,t;
|
||||
z = w;
|
||||
__LO(z) = 0;
|
||||
set_low(&z, 0);
|
||||
v = r-(z - x); /* z+v = r+x */
|
||||
t = a = -1.0/w; /* a = -1.0/w */
|
||||
__LO(t) = 0;
|
||||
set_low(&t, 0);
|
||||
s = 1.0+t*z;
|
||||
return t+a*(s+t*v);
|
||||
}
|
||||
|
@ -757,7 +757,7 @@ JRT_LEAF(jdouble, SharedRuntime::dsin(jdouble x))
|
|||
int n, ix;
|
||||
|
||||
/* High word of x. */
|
||||
ix = __HI(x);
|
||||
ix = high(x);
|
||||
|
||||
/* |x| ~< pi/4 */
|
||||
ix &= 0x7fffffff;
|
||||
|
@ -815,7 +815,7 @@ JRT_LEAF(jdouble, SharedRuntime::dcos(jdouble x))
|
|||
int n, ix;
|
||||
|
||||
/* High word of x. */
|
||||
ix = __HI(x);
|
||||
ix = high(x);
|
||||
|
||||
/* |x| ~< pi/4 */
|
||||
ix &= 0x7fffffff;
|
||||
|
@ -872,7 +872,7 @@ JRT_LEAF(jdouble, SharedRuntime::dtan(jdouble x))
|
|||
int n, ix;
|
||||
|
||||
/* High word of x. */
|
||||
ix = __HI(x);
|
||||
ix = high(x);
|
||||
|
||||
/* |x| ~< pi/4 */
|
||||
ix &= 0x7fffffff;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue