summaryrefslogtreecommitdiff
path: root/sys/lib/libkern/muldi3.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/lib/libkern/muldi3.c')
-rw-r--r--sys/lib/libkern/muldi3.c48
1 files changed, 20 insertions, 28 deletions
diff --git a/sys/lib/libkern/muldi3.c b/sys/lib/libkern/muldi3.c
index 7fafbc10da5..48f5e303cb2 100644
--- a/sys/lib/libkern/muldi3.c
+++ b/sys/lib/libkern/muldi3.c
@@ -1,6 +1,3 @@
-/* $OpenBSD: muldi3.c,v 1.6 2004/08/07 00:38:32 deraadt Exp $ */
-/* $NetBSD: muldi3.c,v 1.5 1995/10/07 09:26:33 mycroft Exp $ */
-
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -35,11 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)muldi3.c 8.1 (Berkeley) 6/4/93";
-#else
-static char rcsid[] = "$OpenBSD: muldi3.c,v 1.6 2004/08/07 00:38:32 deraadt Exp $";
-#endif
+static char rcsid[] = "$OpenBSD: muldi3.c,v 1.7 2004/11/28 07:23:41 mickey Exp $";
#endif /* LIBC_SCCS and not lint */
#include "quad.h"
@@ -50,7 +43,7 @@ static char rcsid[] = "$OpenBSD: muldi3.c,v 1.6 2004/08/07 00:38:32 deraadt 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
*
@@ -81,9 +74,9 @@ static char rcsid[] = "$OpenBSD: muldi3.c,v 1.6 2004/08/07 00:38:32 deraadt 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
@@ -101,13 +94,14 @@ static char rcsid[] = "$OpenBSD: muldi3.c,v 1.6 2004/08/07 00:38:32 deraadt 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(quad_t a, quad_t b)
+__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]
@@ -117,7 +111,7 @@ __muldi3(quad_t a, quad_t 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;
@@ -140,7 +134,7 @@ __muldi3(quad_t a, quad_t 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);
@@ -171,29 +165,27 @@ __muldi3(quad_t a, quad_t 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, v)
- 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;