src/share/vm/runtime/sharedRuntimeMath.hpp

changeset 7000
631c3a4ea10c
child 7002
a073be2ce5c2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/runtime/sharedRuntimeMath.hpp	Thu May 22 11:36:23 2014 -0400
     1.3 @@ -0,0 +1,97 @@
     1.4 +/*
     1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP
    1.29 +#define SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP
    1.30 +
    1.31 +#include <math.h>
    1.32 +
    1.33 +// VM_LITTLE_ENDIAN is #defined appropriately in the Makefiles
    1.34 +// [jk] this is not 100% correct because the float word order may different
    1.35 +// from the byte order (e.g. on ARM FPA)
    1.36 +#ifdef VM_LITTLE_ENDIAN
    1.37 +# define __HI(x) *(1+(int*)&x)
    1.38 +# define __LO(x) *(int*)&x
    1.39 +#else
    1.40 +# define __HI(x) *(int*)&x
    1.41 +# define __LO(x) *(1+(int*)&x)
    1.42 +#endif
    1.43 +
    1.44 +static double copysignA(double x, double y) {
    1.45 +  __HI(x) = (__HI(x)&0x7fffffff)|(__HI(y)&0x80000000);
    1.46 +  return x;
    1.47 +}
    1.48 +
    1.49 +/*
    1.50 + * ====================================================
    1.51 + * Copyright (c) 1998 Oracle and/or its affiliates. All rights reserved.
    1.52 + *
    1.53 + * Developed at SunSoft, a Sun Microsystems, Inc. business.
    1.54 + * Permission to use, copy, modify, and distribute this
    1.55 + * software is freely granted, provided that this notice
    1.56 + * is preserved.
    1.57 + * ====================================================
    1.58 + */
    1.59 +
    1.60 +/*
    1.61 + * scalbn (double x, int n)
    1.62 + * scalbn(x,n) returns x* 2**n  computed by  exponent
    1.63 + * manipulation rather than by actually performing an
    1.64 + * exponentiation or a multiplication.
    1.65 + */
    1.66 +
    1.67 +static const double
    1.68 +two54   =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
    1.69 +twom54  =  5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
    1.70 +hugeX  = 1.0e+300,
    1.71 +tiny   = 1.0e-300;
    1.72 +
    1.73 +static double scalbnA (double x, int n) {
    1.74 +  int  k,hx,lx;
    1.75 +  hx = __HI(x);
    1.76 +  lx = __LO(x);
    1.77 +  k = (hx&0x7ff00000)>>20;              /* extract exponent */
    1.78 +  if (k==0) {                           /* 0 or subnormal x */
    1.79 +    if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
    1.80 +    x *= two54;
    1.81 +    hx = __HI(x);
    1.82 +    k = ((hx&0x7ff00000)>>20) - 54;
    1.83 +    if (n< -50000) return tiny*x;       /*underflow*/
    1.84 +  }
    1.85 +  if (k==0x7ff) return x+x;             /* NaN or Inf */
    1.86 +  k = k+n;
    1.87 +  if (k >  0x7fe) return hugeX*copysignA(hugeX,x); /* overflow  */
    1.88 +  if (k > 0)                            /* normal result */
    1.89 +    {__HI(x) = (hx&0x800fffff)|(k<<20); return x;}
    1.90 +  if (k <= -54) {
    1.91 +    if (n > 50000)      /* in case integer overflow in n+k */
    1.92 +      return hugeX*copysignA(hugeX,x);  /*overflow*/
    1.93 +    else return tiny*copysignA(tiny,x); /*underflow*/
    1.94 +  }
    1.95 +  k += 54;                              /* subnormal result */
    1.96 +  __HI(x) = (hx&0x800fffff)|(k<<20);
    1.97 +  return x*twom54;
    1.98 +}
    1.99 +
   1.100 +#endif // SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP

mercurial