]> git.proxmox.com Git - mirror_edk2.git/commitdiff
StdLib/LibC/gdtoa: Initialize variables before use, update the Kmax definition.
authorDaryl McDaniel <daryl.mcdaniel@intel.com>
Thu, 21 Aug 2014 20:58:05 +0000 (20:58 +0000)
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 21 Aug 2014 20:58:05 +0000 (20:58 +0000)
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

StdLib/LibC/gdtoa/gdtoaimp.h
StdLib/LibC/gdtoa/strtodg.c

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