- 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 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 - 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 originally a counter, so if it started at 0, A_SpawnFly would effectively
never spawn anything. Fixes Dehacked patches that use A_SpawnSound to 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" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4554 /wd4102" )
endif( MSVC ) 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} ) include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
add_definitions( -DINFNAN_CHECK -DMULTIPLE_THREADS ) add_definitions( -DINFNAN_CHECK -DMULTIPLE_THREADS )

View file

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

View file

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

View file

@ -160,11 +160,6 @@ THIS SOFTWARE.
* #define NO_STRING_H to use private versions of memcpy. * #define NO_STRING_H to use private versions of memcpy.
* On some K&R systems, it may also be necessary to * On some K&R systems, it may also be necessary to
* #define DECLARE_SIZE_T in this case. * #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. * #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; typedef union { double d; ULong L[2]; } U;
#ifdef YES_ALIAS
#define dval(x) x
#ifdef IEEE_8087 #ifdef IEEE_8087
#define word0(x) ((ULong *)&x)[1] #define word0(x) x.L[1]
#define word1(x) ((ULong *)&x)[0] #define word1(x) x.L[0]
#else #else
#define word0(x) ((ULong *)&x)[0] #define word0(x) x.L[0]
#define word1(x) ((ULong *)&x)[1] #define word1(x) x.L[1]
#endif #endif
#else /* !YES_ALIAS */ #define dval(x) x.d
#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 */
/* The following definition of Storeinc is appropriate for MIPS processors. /* The following definition of Storeinc is appropriate for MIPS processors.
* An alternative that might be better on some machines is * An alternative that might be better on some machines is

View file

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

View file

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

View file

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

View file

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

View file

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