As discussed (briefly) on tech-userlevel, fix our quad support to work

correctly on LP64 platforms. This is mostly just s/long/int/ where
appropriate.
This commit is contained in:
scw 2002-10-20 10:15:47 +00:00
parent 04a46ed198
commit 37b34d511d
16 changed files with 118 additions and 118 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: divrem.c,v 1.2 1995/02/27 17:31:30 cgd Exp $ */
/* $NetBSD: divrem.c,v 1.3 2002/10/20 10:15:48 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)divrem.c 8.1 (Berkeley) 6/4/93";
#else
static char rcsid[] = "$NetBSD: divrem.c,v 1.2 1995/02/27 17:31:30 cgd Exp $";
static char rcsid[] = "$NetBSD: divrem.c,v 1.3 2002/10/20 10:15:48 scw Exp $";
#endif
#endif /* not lint */
@ -55,7 +55,7 @@ static char rcsid[] = "$NetBSD: divrem.c,v 1.2 1995/02/27 17:31:30 cgd Exp $";
main()
{
union { long long q; unsigned long v[2]; } a, b, q, r;
union { long long q; unsigned int v[2]; } a, b, q, r;
char buf[300];
extern long long __qdivrem(unsigned long long, unsigned long long,
unsigned long long *);
@ -64,19 +64,19 @@ main()
printf("> ");
if (fgets(buf, sizeof buf, stdin) == NULL)
break;
if (sscanf(buf, "%lu:%lu %lu:%lu",
if (sscanf(buf, "%u:%u %u:%u",
&a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4 &&
sscanf(buf, "0x%lx:%lx 0x%lx:%lx",
sscanf(buf, "0x%x:%x 0x%x:%x",
&a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4) {
printf("eh?\n");
continue;
}
q.q = __qdivrem(a.q, b.q, &r.q);
printf("%lx:%lx /%% %lx:%lx => q=%lx:%lx r=%lx:%lx\n",
printf("%x:%x /%% %x:%x => q=%x:%x r=%x:%x\n",
a.v[0], a.v[1], b.v[0], b.v[1],
q.v[0], q.v[1], r.v[0], r.v[1]);
printf(" = %lX%08lX / %lX%08lX => %lX%08lX\n\
= %lX%08lX %% %lX%08lX => %lX%08lX\n",
printf(" = %X%08X / %X%08X => %X%08X\n\
= %X%08X %% %X%08X => %X%08X\n",
a.v[0], a.v[1], b.v[0], b.v[1], q.v[0], q.v[1],
a.v[0], a.v[1], b.v[0], b.v[1], r.v[0], r.v[1]);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mul.c,v 1.2 1995/02/27 17:31:34 cgd Exp $ */
/* $NetBSD: mul.c,v 1.3 2002/10/20 10:15:48 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)mul.c 8.1 (Berkeley) 6/4/93";
#else
static char rcsid[] = "$NetBSD: mul.c,v 1.2 1995/02/27 17:31:34 cgd Exp $";
static char rcsid[] = "$NetBSD: mul.c,v 1.3 2002/10/20 10:15:48 scw Exp $";
#endif
#endif /* not lint */
@ -55,7 +55,7 @@ static char rcsid[] = "$NetBSD: mul.c,v 1.2 1995/02/27 17:31:34 cgd Exp $";
main()
{
union { long long q; unsigned long v[2]; } a, b, m;
union { long long q; unsigned int v[2]; } a, b, m;
char buf[300];
extern long long __muldi3(long long, long long);
@ -63,17 +63,17 @@ main()
printf("> ");
if (fgets(buf, sizeof buf, stdin) == NULL)
break;
if (sscanf(buf, "%lu:%lu %lu:%lu",
if (sscanf(buf, "%u:%u %u:%u",
&a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4 &&
sscanf(buf, "0x%lx:%lx 0x%lx:%lx",
sscanf(buf, "0x%x:%x 0x%x:%x",
&a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4) {
printf("eh?\n");
continue;
}
m.q = __muldi3(a.q, b.q);
printf("%lx:%lx * %lx:%lx => %lx:%lx\n",
printf("%x:%x * %x:%x => %x:%x\n",
a.v[0], a.v[1], b.v[0], b.v[1], m.v[0], m.v[1]);
printf(" = %lX%08lX * %lX%08lX => %lX%08lX\n",
printf(" = %X%08X * %X%08X => %X%08X\n",
a.v[0], a.v[1], b.v[0], b.v[1], m.v[0], m.v[1]);
}
exit(0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: adddi3.c,v 1.3 1997/07/13 20:01:39 christos Exp $ */
/* $NetBSD: adddi3.c,v 1.4 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)adddi3.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: adddi3.c,v 1.3 1997/07/13 20:01:39 christos Exp $");
__RCSID("$NetBSD: adddi3.c,v 1.4 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -50,7 +50,7 @@ __RCSID("$NetBSD: adddi3.c,v 1.3 1997/07/13 20:01:39 christos Exp $");
/*
* Add two quads. This is trivial since a one-bit carry from a single
* u_long addition x+y occurs if and only if the sum x+y is less than
* u_int addition x+y occurs if and only if the sum x+y is less than
* either x or y (the choice to compare with x or y is arbitrary).
*/
quad_t

View File

@ -1,4 +1,4 @@
/* $NetBSD: ashldi3.c,v 1.5 1998/01/29 03:23:40 mouse Exp $ */
/* $NetBSD: ashldi3.c,v 1.6 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)ashldi3.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: ashldi3.c,v 1.5 1998/01/29 03:23:40 mouse Exp $");
__RCSID("$NetBSD: ashldi3.c,v 1.6 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -62,12 +62,12 @@ __ashldi3(a, shift)
if (shift == 0)
return(a);
aa.q = a;
if (shift >= LONG_BITS) {
aa.ul[H] = aa.ul[L] << (shift - LONG_BITS);
if (shift >= INT_BITS) {
aa.ul[H] = aa.ul[L] << (shift - INT_BITS);
aa.ul[L] = 0;
} else {
aa.ul[H] = (aa.ul[H] << shift) |
(aa.ul[L] >> (LONG_BITS - shift));
(aa.ul[L] >> (INT_BITS - shift));
aa.ul[L] <<= shift;
}
return (aa.q);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ashrdi3.c,v 1.7 1999/09/10 12:53:10 drochner Exp $ */
/* $NetBSD: ashrdi3.c,v 1.8 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)ashrdi3.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: ashrdi3.c,v 1.7 1999/09/10 12:53:10 drochner Exp $");
__RCSID("$NetBSD: ashrdi3.c,v 1.8 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -61,24 +61,24 @@ __ashrdi3(a, shift)
if (shift == 0)
return(a);
aa.q = a;
if (shift >= LONG_BITS) {
long s;
if (shift >= INT_BITS) {
int s;
/*
* Smear bits rightward using the machine's right-shift
* method, whether that is sign extension or zero fill,
* to get the `sign word' s. Note that shifting by
* LONG_BITS is undefined, so we shift (LONG_BITS-1),
* INT_BITS is undefined, so we shift (INT_BITS-1),
* then 1 more, to get our answer.
*/
/* LINTED inherits machine dependency */
s = (aa.sl[H] >> (LONG_BITS - 1)) >> 1;
s = (aa.sl[H] >> (INT_BITS - 1)) >> 1;
/* LINTED inherits machine dependency*/
aa.ul[L] = aa.sl[H] >> (shift - LONG_BITS);
aa.ul[L] = aa.sl[H] >> (shift - INT_BITS);
aa.ul[H] = s;
} else {
aa.ul[L] = (aa.ul[L] >> shift) |
(aa.ul[H] << (LONG_BITS - shift));
(aa.ul[H] << (INT_BITS - shift));
/* LINTED inherits machine dependency */
aa.sl[H] >>= shift;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fixunsdfdi.c,v 1.5 1999/03/26 21:04:24 kristerw Exp $ */
/* $NetBSD: fixunsdfdi.c,v 1.6 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,13 +42,13 @@
#if 0
static char sccsid[] = "@(#)fixunsdfdi.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: fixunsdfdi.c,v 1.5 1999/03/26 21:04:24 kristerw Exp $");
__RCSID("$NetBSD: fixunsdfdi.c,v 1.6 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "quad.h"
#define ONE_FOURTH ((long)1 << (LONG_BITS - 2))
#define ONE_FOURTH ((int)1 << (INT_BITS - 2))
#define ONE_HALF (ONE_FOURTH * 2.0)
#define ONE (ONE_FOURTH * 4.0)
@ -62,7 +62,7 @@ __fixunsdfdi(x)
double x;
{
union uu t;
unsigned long tmp;
unsigned int tmp;
if (x < 0)
return (UQUAD_MAX); /* ??? should be 0? ERANGE??? */
@ -81,7 +81,7 @@ __fixunsdfdi(x)
* Furthermore, the quotient will fit into a 32-bit integer.
*/
tmp = x / ONE;
t.ul[L] = (unsigned long) (x - tmp * ONE);
t.ul[L] = (unsigned int) (x - tmp * ONE);
t.ul[H] = tmp;
return (t.uq);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fixunssfdi.c,v 1.4 1997/07/13 20:01:45 christos Exp $ */
/* $NetBSD: fixunssfdi.c,v 1.5 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,13 +42,13 @@
#if 0
static char sccsid[] = "@(#)fixunssfdi.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: fixunssfdi.c,v 1.4 1997/07/13 20:01:45 christos Exp $");
__RCSID("$NetBSD: fixunssfdi.c,v 1.5 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include "quad.h"
#define ONE_FOURTH ((long)1 << (LONG_BITS - 2))
#define ONE_FOURTH ((int)1 << (INT_BITS - 2))
#define ONE_HALF (ONE_FOURTH * 2.0)
#define ONE (ONE_FOURTH * 4.0)
@ -88,20 +88,20 @@ __fixunssfdi(float f)
* between x and this is the bottom part (this may introduce
* a few fuzzy bits, but what the heck). With any luck this
* difference will be nonnegative: x should wind up in the
* range [0..ULONG_MAX]. For paranoia, we assume [LONG_MIN..
* 2*ULONG_MAX] instead.
* range [0..UINT_MAX]. For paranoia, we assume [INT_MIN..
* 2*UINT_MAX] instead.
*/
t.ul[H] = (unsigned long)toppart;
t.ul[H] = (unsigned int)toppart;
t.ul[L] = 0;
x -= (double)t.uq;
if (x < 0) {
t.ul[H]--;
x += ULONG_MAX;
x += UINT_MAX;
}
if (x > ULONG_MAX) {
if (x > UINT_MAX) {
t.ul[H]++;
x -= ULONG_MAX;
x -= UINT_MAX;
}
t.ul[L] = (u_long)x;
t.ul[L] = (u_int)x;
return (t.uq);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: floatdidf.c,v 1.4 1997/07/13 20:01:46 christos Exp $ */
/* $NetBSD: floatdidf.c,v 1.5 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)floatdidf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: floatdidf.c,v 1.4 1997/07/13 20:01:46 christos Exp $");
__RCSID("$NetBSD: floatdidf.c,v 1.5 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -69,12 +69,12 @@ __floatdidf(x)
/*
* Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L]
* has the units. Ideally we could just set d, add LONG_BITS to
* has the units. Ideally we could just set d, add INT_BITS to
* its exponent, and then add the units, but this is portable
* code and does not know how to get at an exponent. Machine-
* specific code may be able to do this more efficiently.
*/
d = (double)u.ul[H] * (((long)1 << (LONG_BITS - 2)) * 4.0);
d = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0);
d += u.ul[L];
return (neg ? -d : d);

View File

@ -1,4 +1,4 @@
/* $NetBSD: floatdisf.c,v 1.4 1997/07/13 20:01:47 christos Exp $ */
/* $NetBSD: floatdisf.c,v 1.5 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)floatdisf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: floatdisf.c,v 1.4 1997/07/13 20:01:47 christos Exp $");
__RCSID("$NetBSD: floatdisf.c,v 1.5 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -69,14 +69,14 @@ __floatdisf(x)
/*
* Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L]
* has the units. Ideally we could just set f, add LONG_BITS to
* has the units. Ideally we could just set f, add INT_BITS to
* its exponent, and then add the units, but this is portable
* code and does not know how to get at an exponent. Machine-
* specific code may be able to do this more efficiently.
*
* Using double here may be excessive paranoia.
*/
f = (double)u.ul[H] * (((long)1 << (LONG_BITS - 2)) * 4.0);
f = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0);
f += u.ul[L];
return (neg ? -f : f);

View File

@ -1,4 +1,4 @@
/* $NetBSD: floatunsdidf.c,v 1.4 1997/07/13 20:01:48 christos Exp $ */
/* $NetBSD: floatunsdidf.c,v 1.5 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)floatunsdidf.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: floatunsdidf.c,v 1.4 1997/07/13 20:01:48 christos Exp $");
__RCSID("$NetBSD: floatunsdidf.c,v 1.5 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -60,7 +60,7 @@ __floatunsdidf(x)
union uu u;
u.uq = x;
d = (double)u.ul[H] * (((long)1 << (LONG_BITS - 2)) * 4.0);
d = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0);
d += u.ul[L];
return (d);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: lshldi3.c,v 1.5 1998/01/29 03:23:41 mouse Exp $ */
/* $NetBSD: lshldi3.c,v 1.6 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)lshldi3.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: lshldi3.c,v 1.5 1998/01/29 03:23:41 mouse Exp $");
__RCSID("$NetBSD: lshldi3.c,v 1.6 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -62,12 +62,12 @@ __lshldi3(a, shift)
if (shift == 0)
return(a);
aa.q = a;
if (shift >= LONG_BITS) {
aa.ul[H] = aa.ul[L] << (shift - LONG_BITS);
if (shift >= INT_BITS) {
aa.ul[H] = aa.ul[L] << (shift - INT_BITS);
aa.ul[L] = 0;
} else {
aa.ul[H] = (aa.ul[H] << shift) |
(aa.ul[L] >> (LONG_BITS - shift));
(aa.ul[L] >> (INT_BITS - shift));
aa.ul[L] <<= shift;
}
return (aa.q);

View File

@ -1,4 +1,4 @@
/* $NetBSD: lshrdi3.c,v 1.5 1998/01/29 03:23:42 mouse Exp $ */
/* $NetBSD: lshrdi3.c,v 1.6 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)lshrdi3.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: lshrdi3.c,v 1.5 1998/01/29 03:23:42 mouse Exp $");
__RCSID("$NetBSD: lshrdi3.c,v 1.6 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -61,12 +61,12 @@ __lshrdi3(a, shift)
if (shift == 0)
return(a);
aa.q = a;
if (shift >= LONG_BITS) {
aa.ul[L] = aa.ul[H] >> (shift - LONG_BITS);
if (shift >= INT_BITS) {
aa.ul[L] = aa.ul[H] >> (shift - INT_BITS);
aa.ul[H] = 0;
} else {
aa.ul[L] = (aa.ul[L] >> shift) |
(aa.ul[H] << (LONG_BITS - shift));
(aa.ul[H] << (INT_BITS - shift));
aa.ul[H] >>= shift;
}
return (aa.q);

View File

@ -1,4 +1,4 @@
/* $NetBSD: muldi3.c,v 1.4 1998/02/03 18:31:39 perry Exp $ */
/* $NetBSD: muldi3.c,v 1.5 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)muldi3.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: muldi3.c,v 1.4 1998/02/03 18:31:39 perry Exp $");
__RCSID("$NetBSD: muldi3.c,v 1.5 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -54,7 +54,7 @@ __RCSID("$NetBSD: muldi3.c,v 1.4 1998/02/03 18:31:39 perry Exp $");
* Our algorithm is based on the following. Split incoming quad values
* u and v (where u,v >= 0) into
*
* u = 2^n u1 * u0 (n = number of bits in `u_long', usu. 32)
* u = 2^n u1 * u0 (n = number of bits in `u_int', usu. 32)
*
* and
*
@ -85,9 +85,9 @@ __RCSID("$NetBSD: muldi3.c,v 1.4 1998/02/03 18:31:39 perry Exp $");
*
* This algorithm is from Knuth vol. 2 (2nd ed), section 4.3.3, p. 278.
*
* Since C does not give us a `long * long = quad' operator, we split
* our input quads into two longs, then split the two longs into two
* shorts. We can then calculate `short * short = long' in native
* Since C does not give us a `int * int = quad' operator, we split
* our input quads into two ints, then split the two ints into two
* shorts. We can then calculate `short * short = int' in native
* arithmetic.
*
* Our product should, strictly speaking, be a `long quad', with 128
@ -105,14 +105,14 @@ __RCSID("$NetBSD: muldi3.c,v 1.4 1998/02/03 18:31:39 perry Exp $");
* of 2^n in either one will also vanish. Only `low' need be computed
* mod 2^2n, and only because of the final term above.
*/
static quad_t __lmulq(u_long, u_long);
static quad_t __lmulq(u_int, u_int);
quad_t
__muldi3(a, b)
quad_t a, b;
{
union uu u, v, low, prod;
u_long high, mid, udiff, vdiff;
u_int high, mid, udiff, vdiff;
int negall, negmid;
#define u1 u.ul[H]
#define u0 u.ul[L]
@ -122,7 +122,7 @@ __muldi3(a, b)
/*
* Get u and v such that u, v >= 0. When this is finished,
* u1, u0, v1, and v0 will be directly accessible through the
* longword fields.
* int fields.
*/
if (a >= 0)
u.q = a, negall = 0;
@ -145,7 +145,7 @@ __muldi3(a, b)
* Compute the three intermediate products, remembering
* whether the middle term is negative. We can discard
* any upper bits in high and mid, so we can use native
* u_long * u_long => u_long arithmetic.
* u_int * u_int => u_int arithmetic.
*/
low.q = __lmulq(u0, v0);
@ -176,27 +176,27 @@ __muldi3(a, b)
}
/*
* Multiply two 2N-bit longs to produce a 4N-bit quad, where N is half
* the number of bits in a long (whatever that is---the code below
* Multiply two 2N-bit ints to produce a 4N-bit quad, where N is half
* the number of bits in an int (whatever that is---the code below
* does not care as long as quad.h does its part of the bargain---but
* typically N==16).
*
* We use the same algorithm from Knuth, but this time the modulo refinement
* does not apply. On the other hand, since N is half the size of a long,
* does not apply. On the other hand, since N is half the size of an int,
* we can get away with native multiplication---none of our input terms
* exceeds (ULONG_MAX >> 1).
* exceeds (UINT_MAX >> 1).
*
* Note that, for u_long l, the quad-precision result
* Note that, for u_int l, the quad-precision result
*
* l << N
*
* splits into high and low longs as HHALF(l) and LHUP(l) respectively.
* splits into high and low ints as HHALF(l) and LHUP(l) respectively.
*/
static quad_t
__lmulq(u_long u, u_long v)
__lmulq(u_int u, u_int v)
{
u_long u1, u0, v1, v0, udiff, vdiff, high, mid, low;
u_long prodh, prodl, was;
u_int u1, u0, v1, v0, udiff, vdiff, high, mid, low;
u_int prodh, prodl, was;
union uu prod;
int neg;

View File

@ -1,4 +1,4 @@
/* $NetBSD: qdivrem.c,v 1.10 2000/01/22 23:02:19 mycroft Exp $ */
/* $NetBSD: qdivrem.c,v 1.11 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)qdivrem.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: qdivrem.c,v 1.10 2000/01/22 23:02:19 mycroft Exp $");
__RCSID("$NetBSD: qdivrem.c,v 1.11 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -53,16 +53,16 @@ __RCSID("$NetBSD: qdivrem.c,v 1.10 2000/01/22 23:02:19 mycroft Exp $");
#include "quad.h"
#define B ((long)1 << HALF_BITS) /* digit base */
#define B ((int)1 << HALF_BITS) /* digit base */
/* Combine two `digits' to make a single two-digit number. */
#define COMBINE(a, b) (((u_long)(a) << HALF_BITS) | (b))
#define COMBINE(a, b) (((u_int)(a) << HALF_BITS) | (b))
/* select a type for digits in base B: use unsigned short if they fit */
#if ULONG_MAX == 0xffffffff && USHRT_MAX >= 0xffff
#if UINT_MAX == 0xffffffffU && USHRT_MAX >= 0xffff
typedef unsigned short digit;
#else
typedef u_long digit;
typedef u_int digit;
#endif
static void shl __P((digit *p, int len, int sh));
@ -71,7 +71,7 @@ static void shl __P((digit *p, int len, int sh));
* __qdivrem(u, v, rem) returns u/v and, optionally, sets *rem to u%v.
*
* We do this in base 2-sup-HALF_BITS, so that all intermediate products
* fit within u_long. As a consequence, the maximum length dividend and
* fit within u_int. As a consequence, the maximum length dividend and
* divisor are 4 `digits' in this base (they are shorter if they have
* leading zeros).
*/
@ -82,7 +82,7 @@ __qdivrem(uq, vq, arq)
union uu tmp;
digit *u, *v, *q;
digit v1, v2;
u_long qhat, rhat, t;
u_int qhat, rhat, t;
int m, n, d, j, i;
digit uspace[5], vspace[5], qspace[5];
@ -133,7 +133,7 @@ __qdivrem(uq, vq, arq)
v[4] = (digit)LHALF(tmp.ul[L]);
for (n = 4; v[1] == 0; v++) {
if (--n == 1) {
u_long rbj; /* r*B+u[j] (not root boy jim) */
u_int rbj; /* r*B+u[j] (not root boy jim) */
digit q1, q2, q3, q4;
/*
@ -209,7 +209,7 @@ __qdivrem(uq, vq, arq)
rhat = uj1;
goto qhat_too_big;
} else {
u_long nn = COMBINE(uj0, uj1);
u_int nn = COMBINE(uj0, uj1);
qhat = nn / v1;
rhat = nn % v1;
}
@ -258,8 +258,8 @@ __qdivrem(uq, vq, arq)
if (arq) {
if (d) {
for (i = m + n; i > m; --i)
u[i] = (digit)(((u_long)u[i] >> d) |
LHALF((u_long)u[i - 1] << (HALF_BITS - d)));
u[i] = (digit)(((u_int)u[i] >> d) |
LHALF((u_int)u[i - 1] << (HALF_BITS - d)));
u[i] = 0;
}
tmp.ul[H] = COMBINE(uspace[1], uspace[2]);
@ -283,7 +283,7 @@ shl(digit *p, int len, int sh)
int i;
for (i = 0; i < len; i++)
p[i] = (digit)(LHALF((u_long)p[i] << sh) |
((u_long)p[i + 1] >> (HALF_BITS - sh)));
p[i] = (digit)(LHALF((u_long)p[i] << sh));
p[i] = (digit)(LHALF((u_int)p[i] << sh) |
((u_int)p[i + 1] >> (HALF_BITS - sh)));
p[i] = (digit)(LHALF((u_int)p[i] << sh));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: quad.h,v 1.9 2000/12/10 03:54:22 christos Exp $ */
/* $NetBSD: quad.h,v 1.10 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -46,13 +46,13 @@
*
* - The type long long (aka quad_t) exists.
*
* - A quad variable is exactly twice as long as `long'.
* - A quad variable is exactly twice as long as `int'.
*
* - The machine's arithmetic is two's complement.
*
* This library can provide 128-bit arithmetic on a machine with 128-bit
* quads and 64-bit longs, for instance, or 96-bit arithmetic on machines
* with 48-bit longs.
* quads and 64-bit ints, for instance, or 96-bit arithmetic on machines
* with 48-bit ints.
*/
#include <sys/types.h>
@ -69,12 +69,12 @@
union uu {
quad_t q; /* as a (signed) quad */
u_quad_t uq; /* as an unsigned quad */
long sl[2]; /* as two signed longs */
u_long ul[2]; /* as two unsigned longs */
int sl[2]; /* as two signed ints */
u_int ul[2]; /* as two unsigned ints */
};
/*
* Define high and low longwords.
* Define high and low parts of a quad_t.
*/
#define H _QUAD_HIGHWORD
#define L _QUAD_LOWWORD
@ -85,21 +85,21 @@ union uu {
* and assembly.
*/
#define QUAD_BITS (sizeof(quad_t) * CHAR_BIT)
#define LONG_BITS (sizeof(long) * CHAR_BIT)
#define HALF_BITS (sizeof(long) * CHAR_BIT / 2)
#define INT_BITS (sizeof(int) * CHAR_BIT)
#define HALF_BITS (sizeof(int) * CHAR_BIT / 2)
/*
* Extract high and low shortwords from longword, and move low shortword of
* longword to upper half of long, i.e., produce the upper longword of
* ((quad_t)(x) << (number_of_bits_in_long/2)). (`x' must actually be u_long.)
* ((quad_t)(x) << (number_of_bits_in_int/2)). (`x' must actually be u_int.)
*
* These are used in the multiply code, to split a longword into upper
* and lower halves, and to reassemble a product as a quad_t, shifted left
* (sizeof(long)*CHAR_BIT/2).
* (sizeof(int)*CHAR_BIT/2).
*/
#define HHALF(x) ((u_long)(x) >> HALF_BITS)
#define LHALF(x) ((u_long)(x) & (((long)1 << HALF_BITS) - 1))
#define LHUP(x) ((u_long)(x) << HALF_BITS)
#define HHALF(x) ((u_int)(x) >> HALF_BITS)
#define LHALF(x) ((u_int)(x) & (((int)1 << HALF_BITS) - 1))
#define LHUP(x) ((u_int)(x) << HALF_BITS)
/*
* XXX

View File

@ -1,4 +1,4 @@
/* $NetBSD: subdi3.c,v 1.3 1997/07/13 20:01:55 christos Exp $ */
/* $NetBSD: subdi3.c,v 1.4 2002/10/20 10:15:47 scw Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)subdi3.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: subdi3.c,v 1.3 1997/07/13 20:01:55 christos Exp $");
__RCSID("$NetBSD: subdi3.c,v 1.4 2002/10/20 10:15:47 scw Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -50,7 +50,7 @@ __RCSID("$NetBSD: subdi3.c,v 1.3 1997/07/13 20:01:55 christos Exp $");
/*
* Subtract two quad values. This is trivial since a one-bit carry
* from a single u_long difference x-y occurs if and only if (x-y) > x.
* from a single u_int difference x-y occurs if and only if (x-y) > x.
*/
quad_t
__subdi3(a, b)