mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-29 16:44:10 +02:00
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 <daryl.mcdaniel@intel.com> Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com> Reviewed-by: Jaben carsey <Jaben.carsey@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15874 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
78d42190ce
commit
a0d367299f
@ -3,11 +3,7 @@
|
|||||||
floating-point formats to and from decimal notation. It uses
|
floating-point formats to and from decimal notation. It uses
|
||||||
double-precision arithmetic internally, so there are still
|
double-precision arithmetic internally, so there are still
|
||||||
various #ifdefs that adapt the calculations to the native
|
various #ifdefs that adapt the calculations to the native
|
||||||
double-precision arithmetic (any of IEEE, VAX D_floating,
|
IEEE double-precision arithmetic.
|
||||||
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 ".").
|
|
||||||
|
|
||||||
Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials are licensed and made available under
|
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,
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
*****************************************************************
|
||||||
|
|
||||||
The author of this software is David M. Gay.
|
The author of this software is David M. Gay.
|
||||||
|
|
||||||
Copyright (C) 1998-2000 by Lucent Technologies
|
Copyright (C) 1998-2000 by Lucent Technologies
|
||||||
@ -42,7 +40,12 @@
|
|||||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||||
THIS SOFTWARE.
|
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
|
/* 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 Long int on machines with 32-bit ints and 64-bit longs.
|
||||||
* #define Sudden_Underflow for IEEE-format machines without gradual
|
* #define Sudden_Underflow for IEEE-format machines without gradual
|
||||||
* underflow (i.e., that flush to zero on underflow).
|
* 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
|
* #define No_leftright to omit left-right logic in fast floating-point
|
||||||
* computation of dtoa.
|
* computation of dtoa.
|
||||||
* #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3.
|
* #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,
|
* something other than "long long", #define Llong to be the name,
|
||||||
* and if "unsigned Llong" does not work as an unsigned version of
|
* and if "unsigned Llong" does not work as an unsigned version of
|
||||||
* Llong, #define #ULLong to be the corresponding unsigned type.
|
* 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 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,
|
* define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
|
||||||
* FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
|
* 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 "stdlib.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
#ifdef KR_headers
|
|
||||||
#define Char char
|
|
||||||
#else
|
|
||||||
#define Char void
|
#define Char void
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MALLOC
|
#ifdef MALLOC
|
||||||
extern Char *MALLOC ANSI((size_t));
|
extern Char *MALLOC ANSI((size_t));
|
||||||
@ -235,23 +231,6 @@ extern Char *MALLOC ANSI((size_t));
|
|||||||
#define DBL_MAX 1.7976931348623157e+308
|
#define DBL_MAX 1.7976931348623157e+308
|
||||||
#endif
|
#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
|
#ifndef LONG_MAX
|
||||||
#define LONG_MAX 2147483647
|
#define LONG_MAX 2147483647
|
||||||
#endif
|
#endif
|
||||||
@ -265,22 +244,14 @@ extern Char *MALLOC ANSI((size_t));
|
|||||||
#define n_bigtens 5
|
#define n_bigtens 5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef IBM
|
|
||||||
#define n_bigtens 3
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VAX
|
|
||||||
#define n_bigtens 2
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + defined(IBM) != 1
|
#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) != 1
|
||||||
Exactly one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined.
|
Exactly one of IEEE_LITTLE_ENDIAN or IEEE_BIG_ENDIAN should be defined.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This union assumes that:
|
/* 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
|
* An alternative that might be better on some machines is
|
||||||
* #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
|
* #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) \
|
#define Storeinc(a,b,c) \
|
||||||
(((unsigned short *)(void *)a)[1] = (unsigned short)b, \
|
(((unsigned short *)(void *)a)[1] = (unsigned short)b, \
|
||||||
((unsigned short *)(void *)a)[0] = (unsigned short)c, \
|
((unsigned short *)(void *)a)[0] = (unsigned short)c, \
|
||||||
@ -433,11 +404,7 @@ typedef union { double d; UINT32 L[2]; } U;
|
|||||||
#ifdef RND_PRODQUOT
|
#ifdef RND_PRODQUOT
|
||||||
#define rounded_product(a,b) a = rnd_prod(a, b)
|
#define rounded_product(a,b) a = rnd_prod(a, b)
|
||||||
#define rounded_quotient(a,b) a = rnd_quot(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);
|
extern double rnd_prod(double, double), rnd_quot(double, double);
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
#define rounded_product(a,b) a *= b
|
#define rounded_product(a,b) a *= b
|
||||||
#define rounded_quotient(a,b) a /= b
|
#define rounded_quotient(a,b) a /= b
|
||||||
@ -503,7 +470,7 @@ extern mutex_t __gdtoa_locks[2];
|
|||||||
} while (/* CONSTCOND */ 0)
|
} while (/* CONSTCOND */ 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define Kmax 15
|
#define Kmax (sizeof(size_t) << 3)
|
||||||
|
|
||||||
struct
|
struct
|
||||||
Bigint {
|
Bigint {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/** @file
|
/** @file
|
||||||
|
|
||||||
Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials are licensed and made available under
|
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 terms and conditions of the BSD License that accompanies this distribution.
|
||||||
The full text of the license may be found at
|
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
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||||
THIS SOFTWARE.
|
THIS SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
Please send bug reports to David M. Gay (dmg at acm dot org,
|
Please send bug reports to David M. Gay (dmg at acm dot org,
|
||||||
with " at " changed at "@" and " dot " changed to ".").
|
with " at " changed at "@" and " dot " changed to ".").
|
||||||
|
|
||||||
@ -66,11 +65,7 @@ fivesbits[] = { 0, 3, 5, 7, 10, 12, 14, 17, 19, 21,
|
|||||||
};
|
};
|
||||||
|
|
||||||
Bigint *
|
Bigint *
|
||||||
#ifdef KR_headers
|
|
||||||
increment(b) Bigint *b;
|
|
||||||
#else
|
|
||||||
increment(Bigint *b)
|
increment(Bigint *b)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
ULong *x, *xe;
|
ULong *x, *xe;
|
||||||
Bigint *b1;
|
Bigint *b1;
|
||||||
@ -113,11 +108,7 @@ increment(Bigint *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
#ifdef KR_headers
|
|
||||||
decrement(b) Bigint *b;
|
|
||||||
#else
|
|
||||||
decrement(Bigint *b)
|
decrement(Bigint *b)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
ULong *x, *xe;
|
ULong *x, *xe;
|
||||||
#ifdef Pack_16
|
#ifdef Pack_16
|
||||||
@ -146,11 +137,7 @@ decrement(Bigint *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
#ifdef KR_headers
|
|
||||||
all_on(b, n) CONST Bigint *b; int n;
|
|
||||||
#else
|
|
||||||
all_on(CONST Bigint *b, int n)
|
all_on(CONST Bigint *b, int n)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
CONST ULong *x, *xe;
|
CONST ULong *x, *xe;
|
||||||
|
|
||||||
@ -165,11 +152,7 @@ all_on(CONST Bigint *b, int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bigint *
|
Bigint *
|
||||||
#ifdef KR_headers
|
|
||||||
set_ones(b, n) Bigint *b; int n;
|
|
||||||
#else
|
|
||||||
set_ones(Bigint *b, int n)
|
set_ones(Bigint *b, int n)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
ULong *x, *xe;
|
ULong *x, *xe;
|
||||||
@ -195,13 +178,9 @@ set_ones(Bigint *b, int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rvOK
|
rvOK (
|
||||||
#ifdef KR_headers
|
double d, CONST FPI *fpi, Long *expt, ULong *bits, int exact, int rd, int *irv
|
||||||
(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
|
|
||||||
{
|
{
|
||||||
Bigint *b;
|
Bigint *b;
|
||||||
ULong carry, inex, lostbits;
|
ULong carry, inex, lostbits;
|
||||||
@ -314,41 +293,22 @@ rvOK
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef VAX
|
|
||||||
static int
|
static int
|
||||||
#ifdef KR_headers
|
|
||||||
mantbits(d) double d;
|
|
||||||
#else
|
|
||||||
mantbits(double d)
|
mantbits(double d)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
ULong L;
|
ULong L;
|
||||||
#ifdef VAX
|
|
||||||
L = word1(d) << 16 | word1(d) >> 16;
|
|
||||||
if (L)
|
|
||||||
#else
|
|
||||||
if ( (L = word1(d)) !=0)
|
if ( (L = word1(d)) !=0)
|
||||||
#endif
|
|
||||||
return P - lo0bits(&L);
|
return P - lo0bits(&L);
|
||||||
#ifdef VAX
|
|
||||||
L = word0(d) << 16 | word0(d) >> 16 | Exp_msk11;
|
|
||||||
#else
|
|
||||||
L = word0(d) | Exp_msk1;
|
L = word0(d) | Exp_msk1;
|
||||||
#endif
|
|
||||||
return P - 32 - lo0bits(&L);
|
return P - 32 - lo0bits(&L);
|
||||||
}
|
}
|
||||||
#endif /* !VAX */
|
|
||||||
|
|
||||||
int
|
int
|
||||||
strtodg
|
strtodg (
|
||||||
#ifdef KR_headers
|
CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits
|
||||||
(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
|
|
||||||
{
|
{
|
||||||
int abe, abits, asub;
|
int abe = 0, abits = 0, asub;
|
||||||
int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm;
|
int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm;
|
||||||
int dsign, e, e1, e2, emin, esign, finished, i, inex, irv;
|
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;
|
int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign;
|
||||||
@ -563,16 +523,12 @@ strtodg
|
|||||||
}
|
}
|
||||||
else if (e > 0) {
|
else if (e > 0) {
|
||||||
if (e <= Ten_pmax) {
|
if (e <= Ten_pmax) {
|
||||||
#ifdef VAX
|
|
||||||
goto vax_ovfl_check;
|
|
||||||
#else
|
|
||||||
i = fivesbits[e] + mantbits(dval(rv)) <= P;
|
i = fivesbits[e] + mantbits(dval(rv)) <= P;
|
||||||
/* rv = */ rounded_product(dval(rv), tens[e]);
|
/* rv = */ rounded_product(dval(rv), tens[e]);
|
||||||
if (rvOK(dval(rv), fpi, expt, bits, i, rd, &irv))
|
if (rvOK(dval(rv), fpi, expt, bits, i, rd, &irv))
|
||||||
goto ret;
|
goto ret;
|
||||||
e1 -= e;
|
e1 -= e;
|
||||||
goto rv_notOK;
|
goto rv_notOK;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
i = DBL_DIG - nd;
|
i = DBL_DIG - nd;
|
||||||
if (e <= Ten_pmax + i) {
|
if (e <= Ten_pmax + i) {
|
||||||
@ -582,22 +538,7 @@ strtodg
|
|||||||
e2 = e - i;
|
e2 = e - i;
|
||||||
e1 -= i;
|
e1 -= i;
|
||||||
dval(rv) *= tens[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]);
|
/* rv = */ rounded_product(dval(rv), tens[e2]);
|
||||||
#endif
|
|
||||||
if (rvOK(dval(rv), fpi, expt, bits, 0, rd, &irv))
|
if (rvOK(dval(rv), fpi, expt, bits, 0, rd, &irv))
|
||||||
goto ret;
|
goto ret;
|
||||||
e1 -= e2;
|
e1 -= e2;
|
||||||
@ -661,14 +602,6 @@ strtodg
|
|||||||
dval(rv) *= tinytens[j];
|
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 */
|
rvb = d2b(dval(rv), &rve, &rvbits); /* rv = rvb * 2^rve */
|
||||||
if (rvb == NULL)
|
if (rvb == NULL)
|
||||||
return STRTOG_NoMemory;
|
return STRTOG_NoMemory;
|
||||||
@ -924,7 +857,7 @@ strtodg
|
|||||||
inex = STRTOG_Inexlo;
|
inex = STRTOG_Inexlo;
|
||||||
}
|
}
|
||||||
if (dval(adj) < 2147483647.) {
|
if (dval(adj) < 2147483647.) {
|
||||||
L = (INT32)adj0;
|
L = (Long)adj0;
|
||||||
adj0 -= L;
|
adj0 -= L;
|
||||||
switch(rd) {
|
switch(rd) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -937,7 +870,7 @@ strtodg
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (!asub && adj0 > 0.) {
|
if (!asub && adj0 > 0.) {
|
||||||
inc_L:
|
inc_L:
|
||||||
L++;
|
L++;
|
||||||
inex = STRTOG_Inexact - inex;
|
inex = STRTOG_Inexact - inex;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user