Date: Thu, 22 Nov 2001 18:48:18 +0200 From: Alexey Zelkin <phantom@freebsd.org> To: alpha@freebsd.org, dfr@freebsd.org, peter@freebsd.org Subject: strtod cleanup (patch) Message-ID: <20011122184818.A44229@ark.cris.net>
next in thread | raw e-mail | index | archive | help
hi, Few months ago I've tried to get rid of duplicated version of strtod() in our tree (libc/stdlib/netbsd_strtod.c). I.e. remove NetBSD's version in favour of our own more features strtod() for alpha machines. As result I got attached patch. Most of this patch is mechanical merge, but I not sure on types usage correctness (long/int/int32_t) in this chunk: #if BYTE_ORDER == BIG_ENDIAN #define IEEE_BIG_ENDIAN #define Long int32_t #define ULong u_int32_t #else #define IEEE_LITTLE_ENDIAN #define Long long #define ULong unsigned long #endif It was tested against i386 and was working fine, but since it's more related to non-i386 arches I would like to ask you to review and test it. PS: As result of this patch libc/strlib/netbsd_strtod.c will be removed. Index: Makefile.inc =================================================================== RCS file: /home/cvs/freebsd/src/lib/libc/stdlib/Makefile.inc,v retrieving revision 1.32 diff -u -r1.32 Makefile.inc --- Makefile.inc 7 Sep 2001 13:03:16 -0000 1.32 +++ Makefile.inc 22 Nov 2001 16:42:06 -0000 @@ -7,18 +7,9 @@ MISRCS+=abort.c abs.c atexit.c atof.c atoi.c atol.c bsearch.c calloc.c div.c \ exit.c getenv.c getopt.c getsubopt.c hcreate.c heapsort.c labs.c \ ldiv.c malloc.c merge.c putenv.c qsort.c radixsort.c rand.c random.c \ - reallocf.c realpath.c setenv.c strfmon.c strhash.c strtol.c \ + reallocf.c realpath.c setenv.c strfmon.c strhash.c strtod.c strtol.c \ strtoll.c strtoq.c strtoul.c strtoull.c strtouq.c system.c \ tdelete.c tfind.c tsearch.c twalk.c - -.if ${MACHINE_ARCH} == "alpha" -# XXX Temporary until the assumption that a long is 32-bits is resolved -# XXX FreeBSD's code. NetBSD kludged this with Long = int32_t and -# XXX ULong = u_int32_t -SRCS+= netbsd_strtod.c -.else -SRCS+= strtod.c -.endif # machine-dependent stdlib sources .if exists(${.CURDIR}/../libc/${MACHINE_ARCH}/stdlib/Makefile.inc) Index: strtod.c =================================================================== RCS file: /home/cvs/freebsd/src/lib/libc/stdlib/strtod.c,v retrieving revision 1.11 diff -u -r1.11 strtod.c --- strtod.c 4 Nov 2001 21:30:12 -0000 1.11 +++ strtod.c 22 Nov 2001 16:28:44 -0000 @@ -100,6 +100,7 @@ * significant byte has the lowest address. * #define IEEE_BIG_ENDIAN for IEEE-arithmetic machines where the most * significant byte has the lowest address. + * #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. @@ -114,7 +115,7 @@ * #define ROUND_BIASED for IEEE-format with biased rounding. * #define Inaccurate_Divide for IEEE-format with correctly rounded * products but inaccurate quotients, e.g., for Intel i860. - * #define Just_16 to store 16 bits per 32-bit long when doing high-precision + * #define Just_16 to store 16 bits per 32-bit Long when doing high-precision * integer arithmetic. Whether this speeds things up or slows things * down depends on the machine and the number being converted. * #define KR_headers for old-style C function headers. @@ -127,10 +128,16 @@ #if defined(i386) || (defined(mips) && defined(MIPSEL)) || \ defined(__ia64__) || defined(__alpha__) -#define IEEE_LITTLE_ENDIAN -#else +#if BYTE_ORDER == BIG_ENDIAN #define IEEE_BIG_ENDIAN +#define Long int32_t +#define ULong u_int32_t +#else +#define IEEE_LITTLE_ENDIAN +#define Long long +#define ULong unsigned long #endif +#endif /* defined(__i386__) ... */ #ifdef DEBUG #include "stdio.h" @@ -153,6 +160,7 @@ #include "errno.h" #include <ctype.h> + #ifdef Bad_float_h #undef __STDC__ #ifdef IEEE_BIG_ENDIAN @@ -222,11 +230,11 @@ #endif #ifdef IEEE_LITTLE_ENDIAN -#define word0(x) ((u_int32_t *)&x)[1] -#define word1(x) ((u_int32_t *)&x)[0] +#define word0(x) ((ULong *)&x)[1] +#define word1(x) ((ULong *)&x)[0] #else -#define word0(x) ((u_int32_t *)&x)[0] -#define word1(x) ((u_int32_t *)&x)[1] +#define word0(x) ((ULong *)&x)[0] +#define word1(x) ((ULong *)&x)[1] #endif /* The following definition of Storeinc is appropriate for MIPS processors. @@ -349,10 +357,10 @@ #define Big1 0xffffffff #ifndef Just_16 -/* When Pack_32 is not defined, we store 16 bits per 32-bit long. +/* When Pack_32 is not defined, we store 16 bits per 32-bit Long. * This makes some inner loops simpler and sometimes saves work * during multiplications, but it often seems to make things slightly - * slower. Hence the default is now to store 32 bits per long. + * slower. Hence the default is now to store 32 bits per Long. */ #ifndef Pack_32 #define Pack_32 @@ -371,7 +379,7 @@ Bigint { struct Bigint *next; int k, maxwds, sign, wds; - unsigned long x[1]; + ULong x[1]; }; typedef struct Bigint Bigint; @@ -388,7 +396,7 @@ Bigint *rv; x = 1 << k; - rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(long)); + rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(Long)); rv->k = k; rv->maxwds = x; rv->sign = rv->wds = 0; @@ -407,7 +415,7 @@ } #define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ -y->wds*sizeof(long) + 2*sizeof(int)) +y->wds*sizeof(Long) + 2*sizeof(int)) static Bigint * multadd @@ -418,9 +426,9 @@ #endif { int i, wds; - unsigned long *x, y; + ULong *x, y; #ifdef Pack_32 - unsigned long xi, z; + ULong xi, z; #endif Bigint *b1; @@ -456,14 +464,14 @@ static Bigint * s2b #ifdef KR_headers - (s, nd0, nd, y9) CONST char *s; int nd0, nd; unsigned long y9; + (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9; #else - (CONST char *s, int nd0, int nd, unsigned long y9) + (CONST char *s, int nd0, int nd, ULong y9) #endif { Bigint *b; int i, k; - long x, y; + Long x, y; x = (nd + 8) / 9; for (k = 0, y = 1; x > y; y <<= 1, k++) ; @@ -494,12 +502,12 @@ static int hi0bits #ifdef KR_headers - (x) register unsigned long x; + (x) ULong x; #else - (register unsigned long x) + (ULong x) #endif { - register int k = 0; + int k = 0; if (!(x & 0xffff0000)) { k = 16; @@ -528,13 +536,13 @@ static int lo0bits #ifdef KR_headers - (y) unsigned long *y; + (y) ULong *y; #else - (unsigned long *y) + (ULong *y) #endif { - register int k; - register unsigned long x = *y; + int k; + ULong x = *y; if (x & 7) { if (x & 1) @@ -599,10 +607,10 @@ { Bigint *c; int k, wa, wb, wc; - unsigned long carry, y, z; - unsigned long *x, *xa, *xae, *xb, *xbe, *xc, *xc0; + ULong carry, y, z; + ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; #ifdef Pack_32 - unsigned long z2; + ULong z2; #endif if (a->wds < b->wds) { @@ -725,7 +733,7 @@ { int i, k1, n, n1; Bigint *b1; - unsigned long *x, *x1, *xe, z; + ULong *x, *x1, *xe, z; #ifdef Pack_32 n = k >> 5; @@ -782,7 +790,7 @@ (Bigint *a, Bigint *b) #endif { - unsigned long *xa, *xa0, *xb, *xb0; + ULong *xa, *xa0, *xb, *xb0; int i, j; i = a->wds; @@ -818,10 +826,10 @@ { Bigint *c; int i, wa, wb; - long borrow, y; /* We need signed shifts here. */ - unsigned long *xa, *xae, *xb, *xbe, *xc; + Long borrow, y; /* We need signed shifts here. */ + ULong *xa, *xae, *xb, *xbe, *xc; #ifdef Pack_32 - long z; + Long z; #endif i = cmp(a,b); @@ -895,7 +903,7 @@ (double x) #endif { - register long L; + Long L; double a; L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; @@ -931,11 +939,11 @@ (Bigint *a, int *e) #endif { - unsigned long *xa, *xa0, w, y, z; + ULong *xa, *xa0, w, y, z; int k; double d; #ifdef VAX - unsigned long d0, d1; + ULong d0, d1; #else #define d0 word0(d) #define d1 word1(d) @@ -1002,9 +1010,9 @@ { Bigint *b; int de, i, k; - unsigned long *x, y, z; + ULong *x, y, z; #ifdef VAX - unsigned long d0, d1; + ULong d0, d1; d0 = word0(d) >> 16 | word0(d) << 16; d1 = word1(d) >> 16 | word1(d) << 16; #else @@ -1195,8 +1203,8 @@ e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; CONST char *s, *s0, *s1; double aadj, aadj1, adj, rv, rv0; - long L; - unsigned long y, z; + Long L; + ULong y, z; Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; char decimal_point = localeconv()->decimal_point[0]; @@ -1707,12 +1715,12 @@ #endif { int n; - long borrow, y; - unsigned long carry, q, ys; - unsigned long *bx, *bxe, *sx, *sxe; + Long borrow, y; + ULong carry, q, ys; + ULong *bx, *bxe, *sx, *sxe; #ifdef Pack_32 - long z; - unsigned long si, zs; + Long z; + ULong si, zs; #endif n = S->wds; @@ -1832,7 +1840,7 @@ * guarantee that the floating-point calculation has given * the correctly rounded result. For k requested digits and * "uniformly" distributed input, the probability is - * something like 10^(k-15) that we must resort to the long + * something like 10^(k-15) that we must resort to the Long * calculation. */ @@ -1883,10 +1891,10 @@ int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1, j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, spec_case, try_quick; - long L; + Long L; #ifndef Sudden_Underflow int denorm; - unsigned long x; + ULong x; #endif Bigint *b, *b1, *delta, *mlo, *mhi, *S; double d2, ds, eps; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-alpha" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011122184818.A44229>