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 7000
631c3a4ea10c
child 7003
69ea58782b1a
permissions
-rw-r--r--

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

lfoltan@7000 1 /*
lfoltan@7000 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
lfoltan@7000 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
lfoltan@7000 4 *
lfoltan@7000 5 * This code is free software; you can redistribute it and/or modify it
lfoltan@7000 6 * under the terms of the GNU General Public License version 2 only, as
lfoltan@7000 7 * published by the Free Software Foundation.
lfoltan@7000 8 *
lfoltan@7000 9 * This code is distributed in the hope that it will be useful, but WITHOUT
lfoltan@7000 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
lfoltan@7000 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
lfoltan@7000 12 * version 2 for more details (a copy is included in the LICENSE file that
lfoltan@7000 13 * accompanied this code).
lfoltan@7000 14 *
lfoltan@7000 15 * You should have received a copy of the GNU General Public License version
lfoltan@7000 16 * 2 along with this work; if not, write to the Free Software Foundation,
lfoltan@7000 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
lfoltan@7000 18 *
lfoltan@7000 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
lfoltan@7000 20 * or visit www.oracle.com if you need additional information or have any
lfoltan@7000 21 * questions.
lfoltan@7000 22 *
lfoltan@7000 23 */
lfoltan@7000 24
lfoltan@7000 25 #ifndef SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP
lfoltan@7000 26 #define SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP
lfoltan@7000 27
lfoltan@7000 28 #include <math.h>
lfoltan@7000 29
thartmann@7002 30 // Used to access the lower/higher 32 bits of a double
thartmann@7002 31 typedef union {
thartmann@7002 32 double d;
thartmann@7002 33 struct {
lfoltan@7000 34 #ifdef VM_LITTLE_ENDIAN
thartmann@7002 35 int lo;
thartmann@7002 36 int hi;
lfoltan@7000 37 #else
thartmann@7002 38 int hi;
thartmann@7002 39 int lo;
lfoltan@7000 40 #endif
thartmann@7002 41 } split;
thartmann@7002 42 } DoubleIntConv;
thartmann@7002 43
thartmann@7002 44 static inline int high(double d) {
thartmann@7002 45 DoubleIntConv x = { d };
thartmann@7002 46 return x.split.hi;
thartmann@7002 47 }
thartmann@7002 48
thartmann@7002 49 static inline int low(double d) {
thartmann@7002 50 DoubleIntConv x = { d };
thartmann@7002 51 return x.split.lo;
thartmann@7002 52 }
thartmann@7002 53
thartmann@7002 54 static inline void set_high(double* d, int high) {
thartmann@7002 55 DoubleIntConv conv = { *d };
thartmann@7002 56 conv.split.hi = high;
thartmann@7002 57 *d = conv.d;
thartmann@7002 58 }
thartmann@7002 59
thartmann@7002 60 static inline void set_low(double* d, int low) {
thartmann@7002 61 DoubleIntConv conv = { *d };
thartmann@7002 62 conv.split.lo = low;
thartmann@7002 63 *d = conv.d;
thartmann@7002 64 }
lfoltan@7000 65
lfoltan@7000 66 static double copysignA(double x, double y) {
thartmann@7002 67 DoubleIntConv convX = { x };
thartmann@7002 68 convX.split.hi = (convX.split.hi & 0x7fffffff) | (high(y) & 0x80000000);
thartmann@7002 69 return convX.d;
lfoltan@7000 70 }
lfoltan@7000 71
lfoltan@7000 72 /*
lfoltan@7000 73 * ====================================================
lfoltan@7000 74 * Copyright (c) 1998 Oracle and/or its affiliates. All rights reserved.
lfoltan@7000 75 *
lfoltan@7000 76 * Developed at SunSoft, a Sun Microsystems, Inc. business.
lfoltan@7000 77 * Permission to use, copy, modify, and distribute this
lfoltan@7000 78 * software is freely granted, provided that this notice
lfoltan@7000 79 * is preserved.
lfoltan@7000 80 * ====================================================
lfoltan@7000 81 */
lfoltan@7000 82
lfoltan@7000 83 /*
lfoltan@7000 84 * scalbn (double x, int n)
lfoltan@7000 85 * scalbn(x,n) returns x* 2**n computed by exponent
lfoltan@7000 86 * manipulation rather than by actually performing an
lfoltan@7000 87 * exponentiation or a multiplication.
lfoltan@7000 88 */
lfoltan@7000 89
lfoltan@7000 90 static const double
lfoltan@7000 91 two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
lfoltan@7000 92 twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
lfoltan@7000 93 hugeX = 1.0e+300,
lfoltan@7000 94 tiny = 1.0e-300;
lfoltan@7000 95
thartmann@7002 96 static double scalbnA(double x, int n) {
lfoltan@7000 97 int k,hx,lx;
thartmann@7002 98 hx = high(x);
thartmann@7002 99 lx = low(x);
lfoltan@7000 100 k = (hx&0x7ff00000)>>20; /* extract exponent */
lfoltan@7000 101 if (k==0) { /* 0 or subnormal x */
lfoltan@7000 102 if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
lfoltan@7000 103 x *= two54;
thartmann@7002 104 hx = high(x);
lfoltan@7000 105 k = ((hx&0x7ff00000)>>20) - 54;
lfoltan@7000 106 if (n< -50000) return tiny*x; /*underflow*/
lfoltan@7000 107 }
lfoltan@7000 108 if (k==0x7ff) return x+x; /* NaN or Inf */
lfoltan@7000 109 k = k+n;
thartmann@7002 110 if (k > 0x7fe) return hugeX*copysignA(hugeX,x); /* overflow */
thartmann@7002 111 if (k > 0) { /* normal result */
thartmann@7002 112 set_high(&x, (hx&0x800fffff)|(k<<20));
thartmann@7002 113 return x;
thartmann@7002 114 }
lfoltan@7000 115 if (k <= -54) {
lfoltan@7000 116 if (n > 50000) /* in case integer overflow in n+k */
lfoltan@7000 117 return hugeX*copysignA(hugeX,x); /*overflow*/
lfoltan@7000 118 else return tiny*copysignA(tiny,x); /*underflow*/
lfoltan@7000 119 }
lfoltan@7000 120 k += 54; /* subnormal result */
thartmann@7002 121 set_high(&x, (hx&0x800fffff)|(k<<20));
lfoltan@7000 122 return x*twom54;
lfoltan@7000 123 }
lfoltan@7000 124
lfoltan@7000 125 #endif // SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP

mercurial