svn commit: r269077 - head/lib/libstand
Sean Bruno
sbruno at FreeBSD.org
Thu Jul 24 19:06:16 UTC 2014
Author: sbruno
Date: Thu Jul 24 19:06:15 2014
New Revision: 269077
URL: http://svnweb.freebsd.org/changeset/base/269077
Log:
libstand's qdivrem.c assumes that sizeof(int) == sizeof(long), this is not
true on amd64 I'm not quite positive this is the "correct" solution for
this but it does seem to compile and shut up the spew of warnings when
compiling libstand for userboot.
Add two _Static_asserts() so that in the future somebody will get a compile
failure if an architecture develops that violates the assumptions of this
code. (strongly suggested by jmg)
Change commetns to indicate int types instead of long. (noted by ian in
phabric review)
Phabric: https://phabric.freebsd.org/D443
Modified:
head/lib/libstand/qdivrem.c
head/lib/libstand/quad.h
Modified: head/lib/libstand/qdivrem.c
==============================================================================
--- head/lib/libstand/qdivrem.c Thu Jul 24 18:39:08 2014 (r269076)
+++ head/lib/libstand/qdivrem.c Thu Jul 24 19:06:15 2014 (r269077)
@@ -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;
}
Modified: head/lib/libstand/quad.h
==============================================================================
--- head/lib/libstand/quad.h Thu Jul 24 18:39:08 2014 (r269076)
+++ head/lib/libstand/quad.h Thu Jul 24 19:06:15 2014 (r269077)
@@ -54,6 +54,9 @@
#include <sys/types.h>
#include <limits.h>
+_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
More information about the svn-src-all
mailing list