- gdtoa now performs all type aliasing through unions. -Wall has been added

to the GCC flags for the library to help verify this.


SVN r1742 (trunk)
This commit is contained in:
Randy Heit 2009-08-01 02:45:02 +00:00
parent 99d99ce5e5
commit d3792c2291
10 changed files with 47 additions and 43 deletions

View file

@ -1,4 +1,6 @@
July 31, 2009
- gdtoa now performs all type aliasing through unions. -Wall has been added
to the GCC flags for the library to help verify this.
- Changed A_SpawnFly to do nothing if reactiontime is 0. Reactiontime was
originally a counter, so if it started at 0, A_SpawnFly would effectively
never spawn anything. Fixes Dehacked patches that use A_SpawnSound to

View file

@ -8,6 +8,10 @@ if( MSVC )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4554 /wd4102" )
endif( MSVC )
if( CMAKE_COMPILER_IS_GNUCXX )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" )
endif( CMAKE_COMPILER_IS_GNUCXX )
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
add_definitions( -DINFNAN_CHECK -DMULTIPLE_THREADS )

View file

@ -80,7 +80,7 @@ dtoa
(d, mode, ndigits, decpt, sign, rve)
double d; int mode, ndigits, *decpt, *sign; char **rve;
#else
(double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
(double _d, int mode, int ndigits, int *decpt, int *sign, char **rve)
#endif
{
/* Arguments ndigits, decpt, sign are similar to those
@ -126,7 +126,8 @@ dtoa
ULong x;
#endif
Bigint *b, *b1, *delta, *mlo, *mhi, *S;
double d2, ds, eps;
U d, d2, eps;
double ds;
char *s, *s0;
#ifdef Honor_FLT_ROUNDS
int rounding;
@ -142,6 +143,7 @@ dtoa
}
#endif
dval(d) = _d;
if (word0(d) & Sign_bit) {
/* set sign for everything, including 0's and NaNs */
*sign = 1;

View file

@ -158,7 +158,8 @@ gdtoa
int rdir, s2, s5, spec_case, try_quick;
Long L;
Bigint *b, *b1, *delta, *mlo, *mhi, *mhi1, *S;
double d, d2, ds, eps;
double d2, ds;
U d, eps;
char *s, *s0;
#ifndef MULTIPLE_THREADS

View file

@ -160,11 +160,6 @@ THIS SOFTWARE.
* #define NO_STRING_H to use private versions of memcpy.
* On some K&R systems, it may also be necessary to
* #define DECLARE_SIZE_T in this case.
* #define YES_ALIAS to permit aliasing certain double values with
* arrays of ULongs. This leads to slightly better code with
* some compilers and was always used prior to 19990916, but it
* is not strictly legal and can cause trouble with aggressively
* optimizing compilers (e.g., gcc 2.95.1 under -O2).
* #define USE_LOCALE to use the current locale's decimal_point value.
*/
@ -289,25 +284,14 @@ extern "C" {
typedef union { double d; ULong L[2]; } U;
#ifdef YES_ALIAS
#define dval(x) x
#ifdef IEEE_8087
#define word0(x) ((ULong *)&x)[1]
#define word1(x) ((ULong *)&x)[0]
#define word0(x) x.L[1]
#define word1(x) x.L[0]
#else
#define word0(x) ((ULong *)&x)[0]
#define word1(x) ((ULong *)&x)[1]
#define word0(x) x.L[0]
#define word1(x) x.L[1]
#endif
#else /* !YES_ALIAS */
#ifdef IEEE_8087
#define word0(x) ((U*)&x)->L[1]
#define word1(x) ((U*)&x)->L[0]
#else
#define word0(x) ((U*)&x)->L[0]
#define word1(x) ((U*)&x)->L[1]
#endif
#define dval(x) ((U*)&x)->d
#endif /* YES_ALIAS */
#define dval(x) x.d
/* The following definition of Storeinc is appropriate for MIPS processors.
* An alternative that might be better on some machines is

View file

@ -617,7 +617,7 @@ b2d
{
ULong *xa, *xa0, w, y, z;
int k;
double d;
U d;
#ifdef VAX
ULong d0, d1;
#else
@ -681,7 +681,7 @@ d2b
#ifdef KR_headers
(d, e, bits) double d; int *e, *bits;
#else
(double d, int *e, int *bits)
(double _d, int *e, int *bits)
#endif
{
Bigint *b;
@ -690,15 +690,20 @@ d2b
#endif
int de, k;
ULong *x, y, z;
U d;
#ifdef VAX
ULong d0, d1;
d0 = word0(d) >> 16 | word0(d) << 16;
d1 = word1(d) >> 16 | word1(d) << 16;
#else
#define d0 word0(d)
#define d1 word1(d)
#endif
dval(d) = _d;
#ifdef VAX
d0 = word0(d) >> 16 | word0(d) << 16;
d1 = word1(d) >> 16 | word1(d) << 16;
#endif
#ifdef Pack_32
b = Balloc(1);
#else

View file

@ -77,7 +77,7 @@ ratio
(Bigint *a, Bigint *b)
#endif
{
double da, db;
U da, db;
int k, ka, kb;
dval(da) = b2d(a, &ka);

View file

@ -74,7 +74,8 @@ strtod
int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, dsign,
e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
CONST char *s, *s0, *s1;
double aadj, aadj1, adj, rv, rv0;
double aadj, adj;
U rv, rv0, aadj1;
Long L;
ULong y, z;
Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
@ -802,14 +803,14 @@ strtod
}
if ((aadj = ratio(delta, bs)) <= 2.) {
if (dsign)
aadj = aadj1 = 1.;
aadj = dval(aadj1) = 1.;
else if (word1(rv) || word0(rv) & Bndry_mask) {
#ifndef Sudden_Underflow
if (word1(rv) == Tiny1 && !word0(rv))
goto undfl;
#endif
aadj = 1.;
aadj1 = -1.;
dval(aadj1) = -1.;
}
else {
/* special case -- power of FLT_RADIX to be */
@ -819,12 +820,12 @@ strtod
aadj = 1./FLT_RADIX;
else
aadj *= 0.5;
aadj1 = -aadj;
dval(aadj1) = -aadj;
}
}
else {
aadj *= 0.5;
aadj1 = dsign ? aadj : -aadj;
dval(aadj1) = dsign ? aadj : -aadj;
#ifdef Check_FLT_ROUNDS
switch(Rounding) {
case 2: /* towards +infinity */
@ -836,7 +837,7 @@ strtod
}
#else
if (Flt_Rounds == 0)
aadj1 += 0.5;
dval(aadj1) += 0.5;
#endif /*Check_FLT_ROUNDS*/
}
y = word0(rv) & Exp_mask;
@ -846,7 +847,7 @@ strtod
if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
dval(rv0) = dval(rv);
word0(rv) -= P*Exp_msk1;
adj = aadj1 * ulp(dval(rv));
adj = dval(aadj1) * ulp(dval(rv));
dval(rv) += adj;
if ((word0(rv) & Exp_mask) >=
Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
@ -866,11 +867,11 @@ strtod
if ((z = (ULong)aadj) <= 0)
z = 1;
aadj = z;
aadj1 = dsign ? aadj : -aadj;
dval(aadj1) = dsign ? aadj : -aadj;
}
word0(aadj1) += (2*P+1)*Exp_msk1 - y;
}
adj = aadj1 * ulp(dval(rv));
adj = dval(aadj1) * ulp(dval(rv));
dval(rv) += adj;
#else
#ifdef Sudden_Underflow

View file

@ -294,10 +294,13 @@ rvOK
#ifdef KR_headers
mantbits(d) double d;
#else
mantbits(double d)
mantbits(double _d)
#endif
{
ULong L;
U d;
dval(d) = _d;
#ifdef VAX
L = word1(d) << 16 | word1(d) >> 16;
if (L)
@ -328,7 +331,8 @@ strtodg
int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign;
int sudden_underflow;
CONST char *s, *s0, *s1;
double adj, adj0, rv, tol;
double adj0, tol;
U adj, rv;
Long L;
ULong y, z;
Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0;

View file

@ -36,12 +36,13 @@ ulp
#ifdef KR_headers
(x) double x;
#else
(double x)
(double _x)
#endif
{
Long L;
double a;
U x, a;
dval(x) = _x;
L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
#ifndef Sudden_Underflow
if (L > 0) {
@ -66,5 +67,5 @@ ulp
}
}
#endif
return a;
return dval(a);
}