8049043: Load variable through a pointer of an incompatible type in hotspot/src/share/vm/runtime/sharedRuntimeMath.hpp

Tue, 29 Jul 2014 13:56:29 +0200

author
thartmann
date
Tue, 29 Jul 2014 13:56:29 +0200
changeset 7002
a073be2ce5c2
parent 7001
b6a8cc1e0d92
child 7003
69ea58782b1a

8049043: Load variable through a pointer of an incompatible type in hotspot/src/share/vm/runtime/sharedRuntimeMath.hpp
Summary: Fixed parfait warnings caused by __HI and __LO macros in sharedRuntimeMath.hpp by using a union.
Reviewed-by: kvn

src/share/vm/runtime/sharedRuntimeMath.hpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/sharedRuntimeTrans.cpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/sharedRuntimeTrig.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/runtime/sharedRuntimeMath.hpp	Tue Jul 29 13:54:16 2014 +0200
     1.2 +++ b/src/share/vm/runtime/sharedRuntimeMath.hpp	Tue Jul 29 13:56:29 2014 +0200
     1.3 @@ -27,20 +27,46 @@
     1.4  
     1.5  #include <math.h>
     1.6  
     1.7 -// VM_LITTLE_ENDIAN is #defined appropriately in the Makefiles
     1.8 -// [jk] this is not 100% correct because the float word order may different
     1.9 -// from the byte order (e.g. on ARM FPA)
    1.10 +// Used to access the lower/higher 32 bits of a double
    1.11 +typedef union {
    1.12 +    double d;
    1.13 +    struct {
    1.14  #ifdef VM_LITTLE_ENDIAN
    1.15 -# define __HI(x) *(1+(int*)&x)
    1.16 -# define __LO(x) *(int*)&x
    1.17 +      int lo;
    1.18 +      int hi;
    1.19  #else
    1.20 -# define __HI(x) *(int*)&x
    1.21 -# define __LO(x) *(1+(int*)&x)
    1.22 +      int hi;
    1.23 +      int lo;
    1.24  #endif
    1.25 +    } split;
    1.26 +} DoubleIntConv;
    1.27 +
    1.28 +static inline int high(double d) {
    1.29 +  DoubleIntConv x = { d };
    1.30 +  return x.split.hi;
    1.31 +}
    1.32 +
    1.33 +static inline int low(double d) {
    1.34 +  DoubleIntConv x = { d };
    1.35 +  return x.split.lo;
    1.36 +}
    1.37 +
    1.38 +static inline void set_high(double* d, int high) {
    1.39 +  DoubleIntConv conv = { *d };
    1.40 +  conv.split.hi = high;
    1.41 +  *d = conv.d;
    1.42 +}
    1.43 +
    1.44 +static inline void set_low(double* d, int low) {
    1.45 +  DoubleIntConv conv = { *d };
    1.46 +  conv.split.lo = low;
    1.47 +  *d = conv.d;
    1.48 +}
    1.49  
    1.50  static double copysignA(double x, double y) {
    1.51 -  __HI(x) = (__HI(x)&0x7fffffff)|(__HI(y)&0x80000000);
    1.52 -  return x;
    1.53 +  DoubleIntConv convX = { x };
    1.54 +  convX.split.hi = (convX.split.hi & 0x7fffffff) | (high(y) & 0x80000000);
    1.55 +  return convX.d;
    1.56  }
    1.57  
    1.58  /*
    1.59 @@ -67,30 +93,32 @@
    1.60  hugeX  = 1.0e+300,
    1.61  tiny   = 1.0e-300;
    1.62  
    1.63 -static double scalbnA (double x, int n) {
    1.64 +static double scalbnA(double x, int n) {
    1.65    int  k,hx,lx;
    1.66 -  hx = __HI(x);
    1.67 -  lx = __LO(x);
    1.68 +  hx = high(x);
    1.69 +  lx = low(x);
    1.70    k = (hx&0x7ff00000)>>20;              /* extract exponent */
    1.71    if (k==0) {                           /* 0 or subnormal x */
    1.72      if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
    1.73      x *= two54;
    1.74 -    hx = __HI(x);
    1.75 +    hx = high(x);
    1.76      k = ((hx&0x7ff00000)>>20) - 54;
    1.77      if (n< -50000) return tiny*x;       /*underflow*/
    1.78    }
    1.79    if (k==0x7ff) return x+x;             /* NaN or Inf */
    1.80    k = k+n;
    1.81 -  if (k >  0x7fe) return hugeX*copysignA(hugeX,x); /* overflow  */
    1.82 -  if (k > 0)                            /* normal result */
    1.83 -    {__HI(x) = (hx&0x800fffff)|(k<<20); return x;}
    1.84 +  if (k > 0x7fe) return hugeX*copysignA(hugeX,x); /* overflow  */
    1.85 +  if (k > 0) {                          /* normal result */
    1.86 +    set_high(&x, (hx&0x800fffff)|(k<<20));
    1.87 +    return x;
    1.88 +  }
    1.89    if (k <= -54) {
    1.90      if (n > 50000)      /* in case integer overflow in n+k */
    1.91        return hugeX*copysignA(hugeX,x);  /*overflow*/
    1.92      else return tiny*copysignA(tiny,x); /*underflow*/
    1.93    }
    1.94    k += 54;                              /* subnormal result */
    1.95 -  __HI(x) = (hx&0x800fffff)|(k<<20);
    1.96 +  set_high(&x, (hx&0x800fffff)|(k<<20));
    1.97    return x*twom54;
    1.98  }
    1.99  
     2.1 --- a/src/share/vm/runtime/sharedRuntimeTrans.cpp	Tue Jul 29 13:54:16 2014 +0200
     2.2 +++ b/src/share/vm/runtime/sharedRuntimeTrans.cpp	Tue Jul 29 13:56:29 2014 +0200
     2.3 @@ -40,6 +40,7 @@
     2.4  // generated; can not figure out how to turn down optimization for one
     2.5  // file in the IDE on Windows
     2.6  #ifdef WIN32
     2.7 +# pragma warning( disable: 4748 ) // /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function
     2.8  # pragma optimize ( "", off )
     2.9  #endif
    2.10  
    2.11 @@ -114,8 +115,8 @@
    2.12    int k,hx,i,j;
    2.13    unsigned lx;
    2.14  
    2.15 -  hx = __HI(x);               /* high word of x */
    2.16 -  lx = __LO(x);               /* low  word of x */
    2.17 +  hx = high(x);               /* high word of x */
    2.18 +  lx = low(x);                /* low  word of x */
    2.19  
    2.20    k=0;
    2.21    if (hx < 0x00100000) {                   /* x < 2**-1022  */
    2.22 @@ -123,13 +124,13 @@
    2.23        return -two54/zero;             /* log(+-0)=-inf */
    2.24      if (hx<0) return (x-x)/zero;   /* log(-#) = NaN */
    2.25      k -= 54; x *= two54; /* subnormal number, scale up x */
    2.26 -    hx = __HI(x);             /* high word of x */
    2.27 +    hx = high(x);             /* high word of x */
    2.28    }
    2.29    if (hx >= 0x7ff00000) return x+x;
    2.30    k += (hx>>20)-1023;
    2.31    hx &= 0x000fffff;
    2.32    i = (hx+0x95f64)&0x100000;
    2.33 -  __HI(x) = hx|(i^0x3ff00000);        /* normalize x or x/2 */
    2.34 +  set_high(&x, hx|(i^0x3ff00000)); /* normalize x or x/2 */
    2.35    k += (i>>20);
    2.36    f = x-1.0;
    2.37    if((0x000fffff&(2+hx))<3) {  /* |f| < 2**-20 */
    2.38 @@ -208,8 +209,8 @@
    2.39    int i,k,hx;
    2.40    unsigned lx;
    2.41  
    2.42 -  hx = __HI(x);       /* high word of x */
    2.43 -  lx = __LO(x);       /* low word of x */
    2.44 +  hx = high(x);       /* high word of x */
    2.45 +  lx = low(x);        /* low word of x */
    2.46  
    2.47    k=0;
    2.48    if (hx < 0x00100000) {                  /* x < 2**-1022  */
    2.49 @@ -217,14 +218,14 @@
    2.50        return -two54/zero;             /* log(+-0)=-inf */
    2.51      if (hx<0) return (x-x)/zero;        /* log(-#) = NaN */
    2.52      k -= 54; x *= two54; /* subnormal number, scale up x */
    2.53 -    hx = __HI(x);                /* high word of x */
    2.54 +    hx = high(x);                /* high word of x */
    2.55    }
    2.56    if (hx >= 0x7ff00000) return x+x;
    2.57    k += (hx>>20)-1023;
    2.58    i  = ((unsigned)k&0x80000000)>>31;
    2.59    hx = (hx&0x000fffff)|((0x3ff-i)<<20);
    2.60    y  = (double)(k+i);
    2.61 -  __HI(x) = hx;
    2.62 +  set_high(&x, hx);
    2.63    z  = y*log10_2lo + ivln10*__ieee754_log(x);
    2.64    return  z+y*log10_2hi;
    2.65  }
    2.66 @@ -319,14 +320,14 @@
    2.67    int k=0,xsb;
    2.68    unsigned hx;
    2.69  
    2.70 -  hx  = __HI(x);        /* high word of x */
    2.71 +  hx  = high(x);                /* high word of x */
    2.72    xsb = (hx>>31)&1;             /* sign bit of x */
    2.73    hx &= 0x7fffffff;             /* high word of |x| */
    2.74  
    2.75    /* filter out non-finite argument */
    2.76    if(hx >= 0x40862E42) {                        /* if |x|>=709.78... */
    2.77      if(hx>=0x7ff00000) {
    2.78 -      if(((hx&0xfffff)|__LO(x))!=0)
    2.79 +      if(((hx&0xfffff)|low(x))!=0)
    2.80          return x+x;             /* NaN */
    2.81        else return (xsb==0)? x:0.0;      /* exp(+-inf)={inf,0} */
    2.82      }
    2.83 @@ -357,10 +358,10 @@
    2.84    if(k==0)      return one-((x*c)/(c-2.0)-x);
    2.85    else          y = one-((lo-(x*c)/(2.0-c))-hi);
    2.86    if(k >= -1021) {
    2.87 -    __HI(y) += (k<<20); /* add k to y's exponent */
    2.88 +    set_high(&y, high(y) + (k<<20)); /* add k to y's exponent */
    2.89      return y;
    2.90    } else {
    2.91 -    __HI(y) += ((k+1000)<<20);/* add k to y's exponent */
    2.92 +    set_high(&y, high(y) + ((k+1000)<<20)); /* add k to y's exponent */
    2.93      return y*twom1000;
    2.94    }
    2.95  }
    2.96 @@ -447,8 +448,8 @@
    2.97    unsigned lx,ly;
    2.98  
    2.99    i0 = ((*(int*)&one)>>29)^1; i1=1-i0;
   2.100 -  hx = __HI(x); lx = __LO(x);
   2.101 -  hy = __HI(y); ly = __LO(y);
   2.102 +  hx = high(x); lx = low(x);
   2.103 +  hy = high(y); ly = low(y);
   2.104    ix = hx&0x7fffffff;  iy = hy&0x7fffffff;
   2.105  
   2.106    /* y==zero: x**0 = 1 */
   2.107 @@ -548,14 +549,14 @@
   2.108      u = ivln2_h*t;      /* ivln2_h has 21 sig. bits */
   2.109      v = t*ivln2_l-w*ivln2;
   2.110      t1 = u+v;
   2.111 -    __LO(t1) = 0;
   2.112 +    set_low(&t1, 0);
   2.113      t2 = v-(t1-u);
   2.114    } else {
   2.115      double ss,s2,s_h,s_l,t_h,t_l;
   2.116      n = 0;
   2.117      /* take care subnormal number */
   2.118      if(ix<0x00100000)
   2.119 -      {ax *= two53; n -= 53; ix = __HI(ax); }
   2.120 +      {ax *= two53; n -= 53; ix = high(ax); }
   2.121      n  += ((ix)>>20)-0x3ff;
   2.122      j  = ix&0x000fffff;
   2.123      /* determine interval */
   2.124 @@ -563,17 +564,17 @@
   2.125      if(j<=0x3988E) k=0;         /* |x|<sqrt(3/2) */
   2.126      else if(j<0xBB67A) k=1;     /* |x|<sqrt(3)   */
   2.127      else {k=0;n+=1;ix -= 0x00100000;}
   2.128 -    __HI(ax) = ix;
   2.129 +    set_high(&ax, ix);
   2.130  
   2.131      /* compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
   2.132      u = ax-bp[k];               /* bp[0]=1.0, bp[1]=1.5 */
   2.133      v = one/(ax+bp[k]);
   2.134      ss = u*v;
   2.135      s_h = ss;
   2.136 -    __LO(s_h) = 0;
   2.137 +    set_low(&s_h, 0);
   2.138      /* t_h=ax+bp[k] High */
   2.139      t_h = zeroX;
   2.140 -    __HI(t_h)=((ix>>1)|0x20000000)+0x00080000+(k<<18);
   2.141 +    set_high(&t_h, ((ix>>1)|0x20000000)+0x00080000+(k<<18));
   2.142      t_l = ax - (t_h-bp[k]);
   2.143      s_l = v*((u-s_h*t_h)-s_h*t_l);
   2.144      /* compute log(ax) */
   2.145 @@ -582,32 +583,32 @@
   2.146      r += s_l*(s_h+ss);
   2.147      s2  = s_h*s_h;
   2.148      t_h = 3.0+s2+r;
   2.149 -    __LO(t_h) = 0;
   2.150 +    set_low(&t_h, 0);
   2.151      t_l = r-((t_h-3.0)-s2);
   2.152      /* u+v = ss*(1+...) */
   2.153      u = s_h*t_h;
   2.154      v = s_l*t_h+t_l*ss;
   2.155      /* 2/(3log2)*(ss+...) */
   2.156      p_h = u+v;
   2.157 -    __LO(p_h) = 0;
   2.158 +    set_low(&p_h, 0);
   2.159      p_l = v-(p_h-u);
   2.160      z_h = cp_h*p_h;             /* cp_h+cp_l = 2/(3*log2) */
   2.161      z_l = cp_l*p_h+p_l*cp+dp_l[k];
   2.162      /* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */
   2.163      t = (double)n;
   2.164      t1 = (((z_h+z_l)+dp_h[k])+t);
   2.165 -    __LO(t1) = 0;
   2.166 +    set_low(&t1, 0);
   2.167      t2 = z_l-(((t1-t)-dp_h[k])-z_h);
   2.168    }
   2.169  
   2.170    /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
   2.171    y1  = y;
   2.172 -  __LO(y1) = 0;
   2.173 +  set_low(&y1, 0);
   2.174    p_l = (y-y1)*t1+y*t2;
   2.175    p_h = y1*t1;
   2.176    z = p_l+p_h;
   2.177 -  j = __HI(z);
   2.178 -  i = __LO(z);
   2.179 +  j = high(z);
   2.180 +  i = low(z);
   2.181    if (j>=0x40900000) {                          /* z >= 1024 */
   2.182      if(((j-0x40900000)|i)!=0)                   /* if z > 1024 */
   2.183        return s*hugeX*hugeX;                     /* overflow */
   2.184 @@ -631,13 +632,13 @@
   2.185      n = j+(0x00100000>>(k+1));
   2.186      k = ((n&0x7fffffff)>>20)-0x3ff;     /* new k for n */
   2.187      t = zeroX;
   2.188 -    __HI(t) = (n&~(0x000fffff>>k));
   2.189 +    set_high(&t, (n&~(0x000fffff>>k)));
   2.190      n = ((n&0x000fffff)|0x00100000)>>(20-k);
   2.191      if(j<0) n = -n;
   2.192      p_h -= t;
   2.193    }
   2.194    t = p_l+p_h;
   2.195 -  __LO(t) = 0;
   2.196 +  set_low(&t, 0);
   2.197    u = t*lg2_h;
   2.198    v = (p_l-(t-p_h))*lg2+t*lg2_l;
   2.199    z = u+v;
   2.200 @@ -646,10 +647,10 @@
   2.201    t1  = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
   2.202    r  = (z*t1)/(t1-two)-(w+z*w);
   2.203    z  = one-(r-z);
   2.204 -  j  = __HI(z);
   2.205 +  j  = high(z);
   2.206    j += (n<<20);
   2.207    if((j>>20)<=0) z = scalbnA(z,n);       /* subnormal output */
   2.208 -  else __HI(z) += (n<<20);
   2.209 +  else set_high(&z, high(z) + (n<<20));
   2.210    return s*z;
   2.211  }
   2.212  
     3.1 --- a/src/share/vm/runtime/sharedRuntimeTrig.cpp	Tue Jul 29 13:54:16 2014 +0200
     3.2 +++ b/src/share/vm/runtime/sharedRuntimeTrig.cpp	Tue Jul 29 13:56:29 2014 +0200
     3.3 @@ -547,7 +547,7 @@
     3.4  {
     3.5          double z,r,v;
     3.6          int ix;
     3.7 -        ix = __HI(x)&0x7fffffff;        /* high word of x */
     3.8 +        ix = high(x)&0x7fffffff;                /* high word of x */
     3.9          if(ix<0x3e400000)                       /* |x| < 2**-27 */
    3.10             {if((int)x==0) return x;}            /* generate inexact */
    3.11          z       =  x*x;
    3.12 @@ -602,9 +602,9 @@
    3.13  
    3.14  static double __kernel_cos(double x, double y)
    3.15  {
    3.16 -  double a,h,z,r,qx;
    3.17 +  double a,h,z,r,qx=0;
    3.18    int ix;
    3.19 -  ix = __HI(x)&0x7fffffff;      /* ix = |x|'s high word*/
    3.20 +  ix = high(x)&0x7fffffff;              /* ix = |x|'s high word*/
    3.21    if(ix<0x3e400000) {                   /* if x < 2**27 */
    3.22      if(((int)x)==0) return one;         /* generate inexact */
    3.23    }
    3.24 @@ -616,8 +616,8 @@
    3.25      if(ix > 0x3fe90000) {               /* x > 0.78125 */
    3.26        qx = 0.28125;
    3.27      } else {
    3.28 -      __HI(qx) = ix-0x00200000; /* x/4 */
    3.29 -      __LO(qx) = 0;
    3.30 +      set_high(&qx, ix-0x00200000); /* x/4 */
    3.31 +      set_low(&qx, 0);
    3.32      }
    3.33      h = 0.5*z-qx;
    3.34      a = one-qx;
    3.35 @@ -682,11 +682,11 @@
    3.36  {
    3.37    double z,r,v,w,s;
    3.38    int ix,hx;
    3.39 -  hx = __HI(x);   /* high word of x */
    3.40 +  hx = high(x);           /* high word of x */
    3.41    ix = hx&0x7fffffff;     /* high word of |x| */
    3.42    if(ix<0x3e300000) {                     /* x < 2**-28 */
    3.43      if((int)x==0) {                       /* generate inexact */
    3.44 -      if (((ix | __LO(x)) | (iy + 1)) == 0)
    3.45 +      if (((ix | low(x)) | (iy + 1)) == 0)
    3.46          return one / fabsd(x);
    3.47        else {
    3.48          if (iy == 1)
    3.49 @@ -695,10 +695,10 @@
    3.50            double a, t;
    3.51  
    3.52            z = w = x + y;
    3.53 -          __LO(z) = 0;
    3.54 +          set_low(&z, 0);
    3.55            v = y - (z - x);
    3.56            t = a = -one / w;
    3.57 -          __LO(t) = 0;
    3.58 +          set_low(&t, 0);
    3.59            s = one + t * z;
    3.60            return t + a * (s + t * v);
    3.61          }
    3.62 @@ -733,10 +733,10 @@
    3.63      /*  compute -1.0/(x+r) accurately */
    3.64      double a,t;
    3.65      z  = w;
    3.66 -    __LO(z) = 0;
    3.67 +    set_low(&z, 0);
    3.68      v  = r-(z - x);     /* z+v = r+x */
    3.69      t = a  = -1.0/w;    /* a = -1.0/w */
    3.70 -    __LO(t) = 0;
    3.71 +    set_low(&t, 0);
    3.72      s  = 1.0+t*z;
    3.73      return t+a*(s+t*v);
    3.74    }
    3.75 @@ -785,7 +785,7 @@
    3.76    int n, ix;
    3.77  
    3.78    /* High word of x. */
    3.79 -  ix = __HI(x);
    3.80 +  ix = high(x);
    3.81  
    3.82    /* |x| ~< pi/4 */
    3.83    ix &= 0x7fffffff;
    3.84 @@ -843,7 +843,7 @@
    3.85    int n, ix;
    3.86  
    3.87    /* High word of x. */
    3.88 -  ix = __HI(x);
    3.89 +  ix = high(x);
    3.90  
    3.91    /* |x| ~< pi/4 */
    3.92    ix &= 0x7fffffff;
    3.93 @@ -900,7 +900,7 @@
    3.94    int n, ix;
    3.95  
    3.96    /* High word of x. */
    3.97 -  ix = __HI(x);
    3.98 +  ix = high(x);
    3.99  
   3.100    /* |x| ~< pi/4 */
   3.101    ix &= 0x7fffffff;

mercurial