src/share/vm/runtime/sharedRuntimeMath.hpp

Thu, 22 May 2014 11:36:23 -0400

author
lfoltan
date
Thu, 22 May 2014 11:36:23 -0400
changeset 7000
631c3a4ea10c
child 7002
a073be2ce5c2
permissions
-rw-r--r--

8043301: Duplicate definitions in vm/runtime/sharedRuntimeTrans.cpp versus math.h in VS2013
Summary: Factor out definitions of copysignA and scalbnA into new file sharedRuntimeMath.hpp
Reviewed-by: kvn

     1 /*
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP
    26 #define SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP
    28 #include <math.h>
    30 // VM_LITTLE_ENDIAN is #defined appropriately in the Makefiles
    31 // [jk] this is not 100% correct because the float word order may different
    32 // from the byte order (e.g. on ARM FPA)
    33 #ifdef VM_LITTLE_ENDIAN
    34 # define __HI(x) *(1+(int*)&x)
    35 # define __LO(x) *(int*)&x
    36 #else
    37 # define __HI(x) *(int*)&x
    38 # define __LO(x) *(1+(int*)&x)
    39 #endif
    41 static double copysignA(double x, double y) {
    42   __HI(x) = (__HI(x)&0x7fffffff)|(__HI(y)&0x80000000);
    43   return x;
    44 }
    46 /*
    47  * ====================================================
    48  * Copyright (c) 1998 Oracle and/or its affiliates. All rights reserved.
    49  *
    50  * Developed at SunSoft, a Sun Microsystems, Inc. business.
    51  * Permission to use, copy, modify, and distribute this
    52  * software is freely granted, provided that this notice
    53  * is preserved.
    54  * ====================================================
    55  */
    57 /*
    58  * scalbn (double x, int n)
    59  * scalbn(x,n) returns x* 2**n  computed by  exponent
    60  * manipulation rather than by actually performing an
    61  * exponentiation or a multiplication.
    62  */
    64 static const double
    65 two54   =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
    66 twom54  =  5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
    67 hugeX  = 1.0e+300,
    68 tiny   = 1.0e-300;
    70 static double scalbnA (double x, int n) {
    71   int  k,hx,lx;
    72   hx = __HI(x);
    73   lx = __LO(x);
    74   k = (hx&0x7ff00000)>>20;              /* extract exponent */
    75   if (k==0) {                           /* 0 or subnormal x */
    76     if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
    77     x *= two54;
    78     hx = __HI(x);
    79     k = ((hx&0x7ff00000)>>20) - 54;
    80     if (n< -50000) return tiny*x;       /*underflow*/
    81   }
    82   if (k==0x7ff) return x+x;             /* NaN or Inf */
    83   k = k+n;
    84   if (k >  0x7fe) return hugeX*copysignA(hugeX,x); /* overflow  */
    85   if (k > 0)                            /* normal result */
    86     {__HI(x) = (hx&0x800fffff)|(k<<20); return x;}
    87   if (k <= -54) {
    88     if (n > 50000)      /* in case integer overflow in n+k */
    89       return hugeX*copysignA(hugeX,x);  /*overflow*/
    90     else return tiny*copysignA(tiny,x); /*underflow*/
    91   }
    92   k += 54;                              /* subnormal result */
    93   __HI(x) = (hx&0x800fffff)|(k<<20);
    94   return x*twom54;
    95 }
    97 #endif // SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP

mercurial