Date: Tue, 27 Nov 2001 17:22:26 +0200 From: Alexey Zelkin <phantom@freebsd.org> To: Peter Wemm <peter@wemm.org> Cc: alpha@freebsd.org, dfr@freebsd.org Subject: Re: strtod cleanup (patch) Message-ID: <20011127172226.A972@ark.cris.net> In-Reply-To: <20011123054241.EA66838CC@overcee.netplex.com.au>; from peter@wemm.org on Thu, Nov 22, 2001 at 09:42:41PM -0800 References: <20011122184818.A44229@ark.cris.net> <20011123054241.EA66838CC@overcee.netplex.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
hi,
On Thu, Nov 22, 2001 at 09:42:41PM -0800, Peter Wemm wrote:
> > 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
>
> This isn't quite right.. The #define Long int32_t etc should be used in
> all cases, including i386. The ia64 and alpha ports are little endian,
> and work best with int32_t.
>
> Also, maybe use:
> typedef int32_t Long;
> typedef u_int32_t ULong;
> .. that way there is no chance of preprocessor side effects with the space
> in ULong.
Ok. Noted.
Updated patch included. Can someone who has alpha/ia64 hardware test this
patch ? It should not break anything, but want to be sure.
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 23 Nov 2001 14:48:46 -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,15 @@
#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
+#else
+#define IEEE_LITTLE_ENDIAN
#endif
+#endif /* defined(__i386__) ... */
+
+typedef int32_t Long;
+typedef u_int32_t ULong;
#ifdef DEBUG
#include "stdio.h"
@@ -153,6 +159,7 @@
#include "errno.h"
#include <ctype.h>
+
#ifdef Bad_float_h
#undef __STDC__
#ifdef IEEE_BIG_ENDIAN
@@ -222,11 +229,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 +356,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 +378,7 @@
Bigint {
struct Bigint *next;
int k, maxwds, sign, wds;
- unsigned long x[1];
+ ULong x[1];
};
typedef struct Bigint Bigint;
@@ -388,7 +395,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 +414,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 +425,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 +463,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 +501,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 +535,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 +606,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 +732,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 +789,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 +825,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 +902,7 @@
(double x)
#endif
{
- register long L;
+ Long L;
double a;
L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
@@ -931,11 +938,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 +1009,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 +1202,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 +1714,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 +1839,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 +1890,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;
Index: Makefile.inc
===================================================================
RCS file: /home/cvs/freebsd/src/lib/libc/stdlib/Makefile.inc,v
retrieving revision 1.33
diff -u -r1.33 Makefile.inc
--- Makefile.inc 15 Nov 2001 02:05:03 -0000 1.33
+++ Makefile.inc 27 Nov 2001 15:27:23 -0000
@@ -8,18 +8,9 @@
exit.c getenv.c getopt.c getsubopt.c hcreate.c heapsort.c \
imaxabs.c imaxdiv.c labs.c ldiv.c llabs.c lldiv.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)
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?20011127172226.A972>
