src/share/vm/runtime/sharedRuntimeTrig.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File bug_jdk8043301_2 Sdiff src/share/vm/runtime

src/share/vm/runtime/sharedRuntimeTrig.cpp

Print this page


   1 /*
   2  * Copyright (c) 2001, 2010, 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  *


  46 /* The above workaround now causes more problems with the latest MS compiler.
  47  * Visual Studio 2010's /GS option tries to guard against buffer overruns.
  48  * /GS is on by default if you specify optimizations, which we do globally
  49  * via /W3 /O2. However the above selective turning off of optimizations means
  50  * that /GS issues a warning "4748". And since we treat warnings as errors (/WX)
  51  * then the compilation fails. There are several possible solutions
  52  * (1) Remove that pragma above as obsolete with VS2010 - requires testing.
  53  * (2) Stop treating warnings as errors - would be a backward step
  54  * (3) Disable /GS - may help performance but you lose the security checks
  55  * (4) Disable the warning with "#pragma warning( disable : 4748 )"
  56  * (5) Disable planting the code with  __declspec(safebuffers)
  57  * I've opted for (5) although we should investigate the local performance
  58  * benefits of (1) and global performance benefit of (3).
  59  */
  60 #if defined(WIN32) && (defined(_MSC_VER) && (_MSC_VER >= 1600))
  61 #define SAFEBUF __declspec(safebuffers)
  62 #else
  63 #define SAFEBUF
  64 #endif
  65 
  66 #include <math.h>
  67 
  68 // VM_LITTLE_ENDIAN is #defined appropriately in the Makefiles
  69 // [jk] this is not 100% correct because the float word order may different
  70 // from the byte order (e.g. on ARM)
  71 #ifdef VM_LITTLE_ENDIAN
  72 # define __HI(x) *(1+(int*)&x)
  73 # define __LO(x) *(int*)&x
  74 #else
  75 # define __HI(x) *(int*)&x
  76 # define __LO(x) *(1+(int*)&x)
  77 #endif
  78 
  79 static double copysignA(double x, double y) {
  80   __HI(x) = (__HI(x)&0x7fffffff)|(__HI(y)&0x80000000);
  81   return x;
  82 }
  83 
  84 /*
  85  * scalbn (double x, int n)
  86  * scalbn(x,n) returns x* 2**n  computed by  exponent
  87  * manipulation rather than by actually performing an
  88  * exponentiation or a multiplication.
  89  */
  90 
  91 static const double
  92 two54   =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
  93 twom54  =  5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
  94 hugeX  = 1.0e+300,
  95 tiny   = 1.0e-300;
  96 
  97 static double scalbnA (double x, int n) {
  98   int  k,hx,lx;
  99   hx = __HI(x);
 100   lx = __LO(x);
 101   k = (hx&0x7ff00000)>>20;              /* extract exponent */
 102   if (k==0) {                           /* 0 or subnormal x */
 103     if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
 104     x *= two54;
 105     hx = __HI(x);
 106     k = ((hx&0x7ff00000)>>20) - 54;
 107     if (n< -50000) return tiny*x;       /*underflow*/
 108   }
 109   if (k==0x7ff) return x+x;             /* NaN or Inf */
 110   k = k+n;
 111   if (k >  0x7fe) return hugeX*copysignA(hugeX,x); /* overflow  */
 112   if (k > 0)                            /* normal result */
 113     {__HI(x) = (hx&0x800fffff)|(k<<20); return x;}
 114   if (k <= -54) {
 115     if (n > 50000)      /* in case integer overflow in n+k */
 116       return hugeX*copysignA(hugeX,x);  /*overflow*/
 117     else return tiny*copysignA(tiny,x); /*underflow*/
 118   }
 119   k += 54;                              /* subnormal result */
 120   __HI(x) = (hx&0x800fffff)|(k<<20);
 121   return x*twom54;
 122 }
 123 
 124 /*
 125  * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
 126  * double x[],y[]; int e0,nx,prec; int ipio2[];
 127  *
 128  * __kernel_rem_pio2 return the last three digits of N with
 129  *              y = x - N*pi/2
 130  * so that |y| < pi/2.
 131  *
 132  * The method is to compute the integer (mod 8) and fraction parts of
 133  * (2/pi)*x without doing the full multiplication. In general we
 134  * skip the part of the product that are known to be a huge integer (
 135  * more accurately, = 0 mod 8 ). Thus the number of operations are
 136  * independent of the exponent of the input.
 137  *
 138  * (2/pi) is represented by an array of 24-bit integers in ipio2[].
 139  *
 140  * Input parameters:
 141  *      x[]     The input value (must be positive) is broken into nx
 142  *              pieces of 24-bit integers in double precision format.


   1 /*
   2  * Copyright (c) 2001, 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  *


  46 /* The above workaround now causes more problems with the latest MS compiler.
  47  * Visual Studio 2010's /GS option tries to guard against buffer overruns.
  48  * /GS is on by default if you specify optimizations, which we do globally
  49  * via /W3 /O2. However the above selective turning off of optimizations means
  50  * that /GS issues a warning "4748". And since we treat warnings as errors (/WX)
  51  * then the compilation fails. There are several possible solutions
  52  * (1) Remove that pragma above as obsolete with VS2010 - requires testing.
  53  * (2) Stop treating warnings as errors - would be a backward step
  54  * (3) Disable /GS - may help performance but you lose the security checks
  55  * (4) Disable the warning with "#pragma warning( disable : 4748 )"
  56  * (5) Disable planting the code with  __declspec(safebuffers)
  57  * I've opted for (5) although we should investigate the local performance
  58  * benefits of (1) and global performance benefit of (3).
  59  */
  60 #if defined(WIN32) && (defined(_MSC_VER) && (_MSC_VER >= 1600))
  61 #define SAFEBUF __declspec(safebuffers)
  62 #else
  63 #define SAFEBUF
  64 #endif
  65 
  66 #include "runtime/sharedRuntimeMath.hpp"
























































  67 
  68 /*
  69  * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
  70  * double x[],y[]; int e0,nx,prec; int ipio2[];
  71  *
  72  * __kernel_rem_pio2 return the last three digits of N with
  73  *              y = x - N*pi/2
  74  * so that |y| < pi/2.
  75  *
  76  * The method is to compute the integer (mod 8) and fraction parts of
  77  * (2/pi)*x without doing the full multiplication. In general we
  78  * skip the part of the product that are known to be a huge integer (
  79  * more accurately, = 0 mod 8 ). Thus the number of operations are
  80  * independent of the exponent of the input.
  81  *
  82  * (2/pi) is represented by an array of 24-bit integers in ipio2[].
  83  *
  84  * Input parameters:
  85  *      x[]     The input value (must be positive) is broken into nx
  86  *              pieces of 24-bit integers in double precision format.


src/share/vm/runtime/sharedRuntimeTrig.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File