diff --git a/lib/libstand/qdivrem.c b/lib/libstand/qdivrem.c index 3a18eed8b31c..bde3b0d56e49 100644 --- a/lib/libstand/qdivrem.c +++ b/lib/libstand/qdivrem.c @@ -46,14 +46,13 @@ __FBSDID("$FreeBSD$"); #define B (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)) + +_Static_assert(sizeof(int) / 2 == sizeof(short), + "Bitwise functions in libstand are broken on this architecture\n"); /* select a type for digits in base B: use unsigned short if they fit */ -#if ULONG_MAX == 0xffffffff && USHRT_MAX >= 0xffff typedef unsigned short digit; -#else -typedef u_long digit; -#endif /* * Shift p[0]..p[len] left `sh' bits, ignoring any bits that @@ -74,7 +73,7 @@ shl(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). */ @@ -85,7 +84,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]; @@ -136,7 +135,7 @@ __qdivrem(uq, vq, arq) v[4] = 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; /* @@ -212,7 +211,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; } diff --git a/lib/libstand/quad.h b/lib/libstand/quad.h index 0ff27ff66356..349540a1e9fa 100644 --- a/lib/libstand/quad.h +++ b/lib/libstand/quad.h @@ -54,6 +54,9 @@ #include #include +_Static_assert(sizeof(quad_t) == sizeof(int) * 2, + "Bitwise function in libstand are broken on this architecture\n"); + /* * Depending on the desired operation, we view a `long long' (aka quad_t) in * one or more of the following formats. @@ -61,8 +64,8 @@ union uu { quad_t q; /* as a (signed) quad */ 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 */ }; /* @@ -77,8 +80,7 @@ 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 HALF_BITS (sizeof(int) * CHAR_BIT / 2) /* * Extract high and low shortwords from longword, and move low shortword of