comparison src/share/vm/runtime/sharedRuntimeTrig.cpp @ 20286:631c3a4ea10c

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
author lfoltan
date Thu, 22 May 2014 11:36:23 -0400
parents bdd155477289
children a073be2ce5c2
comparison
equal deleted inserted replaced
20285:cabe05c85665 20286:631c3a4ea10c
1 /* 1 /*
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 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. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
61 #define SAFEBUF __declspec(safebuffers) 61 #define SAFEBUF __declspec(safebuffers)
62 #else 62 #else
63 #define SAFEBUF 63 #define SAFEBUF
64 #endif 64 #endif
65 65
66 #include <math.h> 66 #include "runtime/sharedRuntimeMath.hpp"
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 67
124 /* 68 /*
125 * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2) 69 * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
126 * double x[],y[]; int e0,nx,prec; int ipio2[]; 70 * double x[],y[]; int e0,nx,prec; int ipio2[];
127 * 71 *