From a0d367299fab5d7ce1a3b71aea176a500f9e7950 Mon Sep 17 00:00:00 2001 From: Daryl McDaniel Date: Thu, 21 Aug 2014 20:58:05 +0000 Subject: [PATCH] StdLib/LibC/gdtoa: Initialize variables before use, update the Kmax definition. gdtoaimp.h: update the Kmax definition. strtodg.c: initialize variables before use. general: Remove conditional sections for VAX and IBM mainframe. Remove conditional sections for pre-ANSI (K&R) function prototypes. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Daryl McDaniel Reviewed-by: Erik Bjorge Reviewed-by: Jaben carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15874 6f19259b-4bc3-4df7-8a09-765794883524 --- StdLib/LibC/gdtoa/gdtoaimp.h | 59 ++++++------------------ StdLib/LibC/gdtoa/strtodg.c | 87 +++++------------------------------- 2 files changed, 23 insertions(+), 123 deletions(-) diff --git a/StdLib/LibC/gdtoa/gdtoaimp.h b/StdLib/LibC/gdtoa/gdtoaimp.h index 593b492aa2..a5eaa72f41 100644 --- a/StdLib/LibC/gdtoa/gdtoaimp.h +++ b/StdLib/LibC/gdtoa/gdtoaimp.h @@ -3,11 +3,7 @@ floating-point formats to and from decimal notation. It uses double-precision arithmetic internally, so there are still various #ifdefs that adapt the calculations to the native - double-precision arithmetic (any of IEEE, VAX D_floating, - or IBM mainframe arithmetic). - - Please send bug reports to David M. Gay (dmg at acm dot org, - with " at " changed at "@" and " dot " changed to "."). + IEEE double-precision arithmetic. Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under @@ -18,6 +14,8 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + ***************************************************************** + The author of this software is David M. Gay. Copyright (C) 1998-2000 by Lucent Technologies @@ -42,7 +40,12 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -$NetBSD: gdtoaimp.h,v 1.5.4.1 2007/05/07 19:49:06 pavel Exp + Please send bug reports to David M. Gay (dmg at acm dot org, + with " at " changed at "@" and " dot " changed to "."). + + ***************************************************************** + + NetBSD: gdtoaimp.h,v 1.5.4.1 2007/05/07 19:49:06 pavel Exp **/ /* On a machine with IEEE extended-precision registers, it is @@ -94,8 +97,6 @@ $NetBSD: gdtoaimp.h,v 1.5.4.1 2007/05/07 19:49:06 pavel Exp * #define Long int on machines with 32-bit ints and 64-bit longs. * #define Sudden_Underflow for IEEE-format machines without gradual * underflow (i.e., that flush to zero on underflow). - * #define IBM for IBM mainframe-style floating-point arithmetic. - * #define VAX for VAX-style floating-point arithmetic (D_floating). * #define No_leftright to omit left-right logic in fast floating-point * computation of dtoa. * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3. @@ -114,7 +115,6 @@ $NetBSD: gdtoaimp.h,v 1.5.4.1 2007/05/07 19:49:06 pavel Exp * something other than "long long", #define Llong to be the name, * and if "unsigned Llong" does not work as an unsigned version of * Llong, #define #ULLong to be the corresponding unsigned type. - * #define KR_headers for old-style C function headers. * #define Bad_float_h if your system lacks a float.h or if it does not * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP, * FLT_RADIX, FLT_ROUNDS, and DBL_MAX. @@ -203,11 +203,7 @@ $NetBSD: gdtoaimp.h,v 1.5.4.1 2007/05/07 19:49:06 pavel Exp #include "stdlib.h" #include "string.h" -#ifdef KR_headers -#define Char char -#else #define Char void -#endif #ifdef MALLOC extern Char *MALLOC ANSI((size_t)); @@ -235,23 +231,6 @@ extern Char *MALLOC ANSI((size_t)); #define DBL_MAX 1.7976931348623157e+308 #endif -#ifdef IBM -#define DBL_DIG 16 -#define DBL_MAX_10_EXP 75 -#define DBL_MAX_EXP 63 -#define FLT_RADIX 16 -#define DBL_MAX 7.2370055773322621e+75 -#endif - -#ifdef VAX -#define DBL_DIG 16 -#define DBL_MAX_10_EXP 38 -#define DBL_MAX_EXP 127 -#define FLT_RADIX 2 -#define DBL_MAX 1.7014118346046923e+38 -#define n_bigtens 2 -#endif - #ifndef LONG_MAX #define LONG_MAX 2147483647 #endif @@ -265,22 +244,14 @@ extern Char *MALLOC ANSI((size_t)); #define n_bigtens 5 #endif -#ifdef IBM -#define n_bigtens 3 -#endif - -#ifdef VAX -#define n_bigtens 2 -#endif - #include "math.h" #ifdef __cplusplus extern "C" { #endif -#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + defined(IBM) != 1 -Exactly one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined. +#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) != 1 +Exactly one of IEEE_LITTLE_ENDIAN or IEEE_BIG_ENDIAN should be defined. #endif /* This union assumes that: @@ -316,7 +287,7 @@ typedef union { double d; UINT32 L[2]; } U; * An alternative that might be better on some machines is * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) */ -#if defined(IEEE_LITTLE_ENDIAN) + defined(VAX) +#if defined(IEEE_LITTLE_ENDIAN) #define Storeinc(a,b,c) \ (((unsigned short *)(void *)a)[1] = (unsigned short)b, \ ((unsigned short *)(void *)a)[0] = (unsigned short)c, \ @@ -433,11 +404,7 @@ typedef union { double d; UINT32 L[2]; } U; #ifdef RND_PRODQUOT #define rounded_product(a,b) a = rnd_prod(a, b) #define rounded_quotient(a,b) a = rnd_quot(a, b) -#ifdef KR_headers -extern double rnd_prod(), rnd_quot(); -#else extern double rnd_prod(double, double), rnd_quot(double, double); -#endif #else #define rounded_product(a,b) a *= b #define rounded_quotient(a,b) a /= b @@ -503,7 +470,7 @@ extern mutex_t __gdtoa_locks[2]; } while (/* CONSTCOND */ 0) #endif -#define Kmax 15 +#define Kmax (sizeof(size_t) << 3) struct Bigint { diff --git a/StdLib/LibC/gdtoa/strtodg.c b/StdLib/LibC/gdtoa/strtodg.c index a8c28cf091..fcb4360472 100644 --- a/StdLib/LibC/gdtoa/strtodg.c +++ b/StdLib/LibC/gdtoa/strtodg.c @@ -1,6 +1,6 @@ /** @file - Copyright (c) 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that accompanies this distribution. The full text of the license may be found at @@ -35,7 +35,6 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - Please send bug reports to David M. Gay (dmg at acm dot org, with " at " changed at "@" and " dot " changed to "."). @@ -66,11 +65,7 @@ fivesbits[] = { 0, 3, 5, 7, 10, 12, 14, 17, 19, 21, }; Bigint * -#ifdef KR_headers -increment(b) Bigint *b; -#else increment(Bigint *b) -#endif { ULong *x, *xe; Bigint *b1; @@ -113,11 +108,7 @@ increment(Bigint *b) } int -#ifdef KR_headers -decrement(b) Bigint *b; -#else decrement(Bigint *b) -#endif { ULong *x, *xe; #ifdef Pack_16 @@ -146,11 +137,7 @@ decrement(Bigint *b) } static int -#ifdef KR_headers -all_on(b, n) CONST Bigint *b; int n; -#else all_on(CONST Bigint *b, int n) -#endif { CONST ULong *x, *xe; @@ -165,11 +152,7 @@ all_on(CONST Bigint *b, int n) } Bigint * -#ifdef KR_headers -set_ones(b, n) Bigint *b; int n; -#else set_ones(Bigint *b, int n) -#endif { int k; ULong *x, *xe; @@ -195,13 +178,9 @@ set_ones(Bigint *b, int n) } static int -rvOK -#ifdef KR_headers - (d, fpi, expt, bits, exact, rd, irv) - double d; CONST FPI *fpi; Long *expt; ULong *bits; int exact, rd, *irv; -#else - (double d, CONST FPI *fpi, Long *expt, ULong *bits, int exact, int rd, int *irv) -#endif +rvOK ( + double d, CONST FPI *fpi, Long *expt, ULong *bits, int exact, int rd, int *irv +) { Bigint *b; ULong carry, inex, lostbits; @@ -314,41 +293,22 @@ rvOK return rv; } -#ifndef VAX static int -#ifdef KR_headers -mantbits(d) double d; -#else mantbits(double d) -#endif { ULong L; -#ifdef VAX - L = word1(d) << 16 | word1(d) >> 16; - if (L) -#else if ( (L = word1(d)) !=0) -#endif return P - lo0bits(&L); -#ifdef VAX - L = word0(d) << 16 | word0(d) >> 16 | Exp_msk11; -#else L = word0(d) | Exp_msk1; -#endif return P - 32 - lo0bits(&L); } -#endif /* !VAX */ int -strtodg -#ifdef KR_headers - (s00, se, fpi, expt, bits) - CONST char *s00; char **se; CONST FPI *fpi; Long *expt; ULong *bits; -#else - (CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits) -#endif +strtodg ( + CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits +) { - int abe, abits, asub; + int abe = 0, abits = 0, asub; int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm; int dsign, e, e1, e2, emin, esign, finished, i, inex, irv; int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign; @@ -563,16 +523,12 @@ strtodg } else if (e > 0) { if (e <= Ten_pmax) { -#ifdef VAX - goto vax_ovfl_check; -#else i = fivesbits[e] + mantbits(dval(rv)) <= P; /* rv = */ rounded_product(dval(rv), tens[e]); if (rvOK(dval(rv), fpi, expt, bits, i, rd, &irv)) goto ret; e1 -= e; goto rv_notOK; -#endif } i = DBL_DIG - nd; if (e <= Ten_pmax + i) { @@ -582,22 +538,7 @@ strtodg e2 = e - i; e1 -= i; dval(rv) *= tens[i]; -#ifdef VAX - /* VAX exponent range is so narrow we must - * worry about overflow here... - */ - vax_ovfl_check: - dval(adj) = dval(rv); - word0(adj) -= P*Exp_msk1; - /* adj = */ rounded_product(dval(adj), tens[e2]); - if ((word0(adj) & Exp_mask) - > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) - goto rv_notOK; - word0(adj) += P*Exp_msk1; - dval(rv) = dval(adj); -#else /* rv = */ rounded_product(dval(rv), tens[e2]); -#endif if (rvOK(dval(rv), fpi, expt, bits, 0, rd, &irv)) goto ret; e1 -= e2; @@ -661,14 +602,6 @@ strtodg dval(rv) *= tinytens[j]; } } -#ifdef IBM - /* e2 is a correction to the (base 2) exponent of the return - * value, reflecting adjustments above to avoid overflow in the - * native arithmetic. For native IBM (base 16) arithmetic, we - * must multiply e2 by 4 to change from base 16 to 2. - */ - e2 <<= 2; -#endif rvb = d2b(dval(rv), &rve, &rvbits); /* rv = rvb * 2^rve */ if (rvb == NULL) return STRTOG_NoMemory; @@ -924,7 +857,7 @@ strtodg inex = STRTOG_Inexlo; } if (dval(adj) < 2147483647.) { - L = (INT32)adj0; + L = (Long)adj0; adj0 -= L; switch(rd) { case 0: @@ -937,7 +870,7 @@ strtodg break; case 2: if (!asub && adj0 > 0.) { - inc_L: +inc_L: L++; inex = STRTOG_Inexact - inex; }