clang-format
This commit is contained in:
@@ -43,14 +43,12 @@
|
||||
* is less than either x or y (the choice to compare with x or y is
|
||||
* arbitrary).
|
||||
*/
|
||||
long long
|
||||
__adddi3(long long a, long long b)
|
||||
{
|
||||
union uu aa, bb, sum;
|
||||
long long __adddi3(long long a, long long b) {
|
||||
union uu aa, bb, sum;
|
||||
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
sum.ui[L] = aa.ui[L] + bb.ui[L];
|
||||
sum.ui[H] = aa.ui[H] + bb.ui[H] + (sum.ui[L] < bb.ui[L]);
|
||||
return (sum.ll);
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
sum.ui[L] = aa.ui[L] + bb.ui[L];
|
||||
sum.ui[H] = aa.ui[H] + bb.ui[H] + (sum.ui[L] < bb.ui[L]);
|
||||
return (sum.ll);
|
||||
}
|
||||
|
||||
@@ -40,14 +40,12 @@
|
||||
/*
|
||||
* Return a & b, in long long.
|
||||
*/
|
||||
long long
|
||||
__anddi3(long long a, long long b)
|
||||
{
|
||||
union uu aa, bb;
|
||||
long long __anddi3(long long a, long long b) {
|
||||
union uu aa, bb;
|
||||
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
aa.ui[0] &= bb.ui[0];
|
||||
aa.ui[1] &= bb.ui[1];
|
||||
return (aa.ll);
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
aa.ui[0] &= bb.ui[0];
|
||||
aa.ui[1] &= bb.ui[1];
|
||||
return (aa.ll);
|
||||
}
|
||||
|
||||
@@ -41,21 +41,18 @@
|
||||
* Shift a (signed) long long value left (arithmetic shift left).
|
||||
* This is the same as logical shift left!
|
||||
*/
|
||||
long long
|
||||
__ashldi3(long long a, unsigned int shift)
|
||||
{
|
||||
union uu aa;
|
||||
long long __ashldi3(long long a, unsigned int shift) {
|
||||
union uu aa;
|
||||
|
||||
if (shift == 0)
|
||||
return(a);
|
||||
aa.ll = a;
|
||||
if (shift >= INT_BITS) {
|
||||
aa.ui[H] = aa.ui[L] << (shift - INT_BITS);
|
||||
aa.ui[L] = 0;
|
||||
} else {
|
||||
aa.ui[H] = (aa.ui[H] << shift) |
|
||||
(aa.ui[L] >> (INT_BITS - shift));
|
||||
aa.ui[L] <<= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
if (shift == 0)
|
||||
return (a);
|
||||
aa.ll = a;
|
||||
if (shift >= INT_BITS) {
|
||||
aa.ui[H] = aa.ui[L] << (shift - INT_BITS);
|
||||
aa.ui[L] = 0;
|
||||
} else {
|
||||
aa.ui[H] = (aa.ui[H] << shift) | (aa.ui[L] >> (INT_BITS - shift));
|
||||
aa.ui[L] <<= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
}
|
||||
|
||||
@@ -40,34 +40,31 @@
|
||||
/*
|
||||
* Shift a (signed) long long value right (arithmetic shift right).
|
||||
*/
|
||||
long long
|
||||
__ashrdi3(long long a, unsigned int shift)
|
||||
{
|
||||
union uu aa;
|
||||
long long __ashrdi3(long long a, unsigned int shift) {
|
||||
union uu aa;
|
||||
|
||||
if (shift == 0)
|
||||
return(a);
|
||||
aa.ll = a;
|
||||
if (shift >= INT_BITS) {
|
||||
int s;
|
||||
if (shift == 0)
|
||||
return (a);
|
||||
aa.ll = a;
|
||||
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
|
||||
* INT_BITS is undefined, so we shift (INT_BITS-1),
|
||||
* then 1 more, to get our answer.
|
||||
*/
|
||||
/* LINTED inherits machine dependency */
|
||||
s = (aa.si[H] >> (INT_BITS - 1)) >> 1;
|
||||
/* LINTED inherits machine dependency*/
|
||||
aa.ui[L] = aa.si[H] >> (shift - INT_BITS);
|
||||
aa.ui[H] = s;
|
||||
} else {
|
||||
aa.ui[L] = (aa.ui[L] >> shift) |
|
||||
(aa.ui[H] << (INT_BITS - shift));
|
||||
/* LINTED inherits machine dependency */
|
||||
aa.si[H] >>= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
/*
|
||||
* 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
|
||||
* INT_BITS is undefined, so we shift (INT_BITS-1),
|
||||
* then 1 more, to get our answer.
|
||||
*/
|
||||
/* LINTED inherits machine dependency */
|
||||
s = (aa.si[H] >> (INT_BITS - 1)) >> 1;
|
||||
/* LINTED inherits machine dependency*/
|
||||
aa.ui[L] = aa.si[H] >> (shift - INT_BITS);
|
||||
aa.ui[H] = s;
|
||||
} else {
|
||||
aa.ui[L] = (aa.ui[L] >> shift) | (aa.ui[H] << (INT_BITS - shift));
|
||||
/* LINTED inherits machine dependency */
|
||||
aa.si[H] >>= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
}
|
||||
|
||||
@@ -42,13 +42,14 @@
|
||||
* Both a and b are considered signed---which means only the high word is
|
||||
* signed.
|
||||
*/
|
||||
int
|
||||
__cmpdi2(long long a, long long b)
|
||||
{
|
||||
union uu aa, bb;
|
||||
int __cmpdi2(long long a, long long b) {
|
||||
union uu aa, bb;
|
||||
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
return (aa.si[H] < bb.si[H] ? 0 : aa.si[H] > bb.si[H] ? 2 :
|
||||
aa.ui[L] < bb.ui[L] ? 0 : aa.ui[L] > bb.ui[L] ? 2 : 1);
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
return (aa.si[H] < bb.si[H] ? 0
|
||||
: aa.si[H] > bb.si[H] ? 2
|
||||
: aa.ui[L] < bb.ui[L] ? 0
|
||||
: aa.ui[L] > bb.ui[L] ? 2
|
||||
: 1);
|
||||
}
|
||||
|
||||
@@ -41,22 +41,20 @@
|
||||
* Divide two signed long longs.
|
||||
* ??? if -1/2 should produce -1 on this machine, this code is wrong
|
||||
*/
|
||||
long long
|
||||
__divdi3(long long a, long long b)
|
||||
{
|
||||
unsigned long long ua, ub, uq;
|
||||
int neg = 0;
|
||||
long long __divdi3(long long a, long long b) {
|
||||
unsigned long long ua, ub, uq;
|
||||
int neg = 0;
|
||||
|
||||
ua = a;
|
||||
ub = b;
|
||||
ua = a;
|
||||
ub = b;
|
||||
|
||||
if (a < 0)
|
||||
ua = -ua, neg ^= 1;
|
||||
if (b < 0)
|
||||
ub = -ub, neg ^= 1;
|
||||
if (a < 0)
|
||||
ua = -ua, neg ^= 1;
|
||||
if (b < 0)
|
||||
ub = -ub, neg ^= 1;
|
||||
|
||||
uq = __qdivrem(ua, ub, NULL);
|
||||
if (neg)
|
||||
uq = - uq;
|
||||
return uq;
|
||||
uq = __qdivrem(ua, ub, NULL);
|
||||
if (neg)
|
||||
uq = -uq;
|
||||
return uq;
|
||||
}
|
||||
|
||||
@@ -40,14 +40,12 @@
|
||||
/*
|
||||
* Return a | b, in long long.
|
||||
*/
|
||||
long long
|
||||
__iordi3(long long a, long long b)
|
||||
{
|
||||
union uu aa, bb;
|
||||
long long __iordi3(long long a, long long b) {
|
||||
union uu aa, bb;
|
||||
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
aa.ui[0] |= bb.ui[0];
|
||||
aa.ui[1] |= bb.ui[1];
|
||||
return (aa.ll);
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
aa.ui[0] |= bb.ui[0];
|
||||
aa.ui[1] |= bb.ui[1];
|
||||
return (aa.ll);
|
||||
}
|
||||
|
||||
@@ -68,10 +68,10 @@
|
||||
* one or more of the following formats.
|
||||
*/
|
||||
union uu {
|
||||
long long ll; /* as a (signed) long long */
|
||||
unsigned long long ull; /* as an unsigned long long */
|
||||
int si[2]; /* as two (signed) ints */
|
||||
unsigned int ui[2]; /* as two unsigned ints */
|
||||
long long ll; /* as a (signed) long long */
|
||||
unsigned long long ull; /* as an unsigned long long */
|
||||
int si[2]; /* as two (signed) ints */
|
||||
unsigned int ui[2]; /* as two unsigned ints */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -87,15 +87,14 @@ union uu {
|
||||
#define L 1
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Total number of bits in a long long and in the pieces that make it up.
|
||||
* These are used for shifting, and also below for halfword extraction
|
||||
* and assembly.
|
||||
*/
|
||||
#define LONGLONG_BITS (sizeof(long long) * CHAR_BIT)
|
||||
#define INT_BITS (sizeof(int) * CHAR_BIT)
|
||||
#define HALF_BITS (sizeof(int) * CHAR_BIT / 2)
|
||||
#define LONGLONG_BITS (sizeof(long long) * CHAR_BIT)
|
||||
#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
|
||||
@@ -107,38 +106,38 @@ union uu {
|
||||
* and lower halves, and to reassemble a product as a long long, shifted
|
||||
* left (sizeof(int)*CHAR_BIT/2).
|
||||
*/
|
||||
#define HHALF(x) ((unsigned int)(x) >> HALF_BITS)
|
||||
#define LHALF(x) ((unsigned int)(x) & (((int)1 << HALF_BITS) - 1))
|
||||
#define LHUP(x) ((unsigned int)(x) << HALF_BITS)
|
||||
#define HHALF(x) ((unsigned int)(x) >> HALF_BITS)
|
||||
#define LHALF(x) ((unsigned int)(x) & (((int)1 << HALF_BITS) - 1))
|
||||
#define LHUP(x) ((unsigned int)(x) << HALF_BITS)
|
||||
|
||||
long long __adddi3 ( long long, long long);
|
||||
long long __anddi3 ( long long, long long);
|
||||
long long __ashldi3 ( long long, unsigned int);
|
||||
long long __ashrdi3 ( long long, unsigned int);
|
||||
int __cmpdi2 ( long long, long long);
|
||||
long long __divdi3 ( long long, long long);
|
||||
long long __iordi3 ( long long, long long);
|
||||
long long __lshldi3 ( long long, unsigned int);
|
||||
long long __lshrdi3 ( long long, unsigned int);
|
||||
long long __moddi3 ( long long, long long);
|
||||
long long __muldi3 ( long long, long long);
|
||||
long long __negdi2 ( long long);
|
||||
long long __one_cmpldi2 ( long long);
|
||||
long long __subdi3 ( long long, long long);
|
||||
int __ucmpdi2 (unsigned long long, unsigned long long);
|
||||
unsigned long long __udivdi3 (unsigned long long, unsigned long long);
|
||||
unsigned long long __umoddi3 (unsigned long long, unsigned long long);
|
||||
long long __xordi3 ( long long, long long);
|
||||
long long __adddi3(long long, long long);
|
||||
long long __anddi3(long long, long long);
|
||||
long long __ashldi3(long long, unsigned int);
|
||||
long long __ashrdi3(long long, unsigned int);
|
||||
int __cmpdi2(long long, long long);
|
||||
long long __divdi3(long long, long long);
|
||||
long long __iordi3(long long, long long);
|
||||
long long __lshldi3(long long, unsigned int);
|
||||
long long __lshrdi3(long long, unsigned int);
|
||||
long long __moddi3(long long, long long);
|
||||
long long __muldi3(long long, long long);
|
||||
long long __negdi2(long long);
|
||||
long long __one_cmpldi2(long long);
|
||||
long long __subdi3(long long, long long);
|
||||
int __ucmpdi2(unsigned long long, unsigned long long);
|
||||
unsigned long long __udivdi3(unsigned long long, unsigned long long);
|
||||
unsigned long long __umoddi3(unsigned long long, unsigned long long);
|
||||
long long __xordi3(long long, long long);
|
||||
|
||||
#ifndef _KERNEL
|
||||
long long __fixdfdi (double);
|
||||
long long __fixsfdi (float);
|
||||
unsigned long long __fixunsdfdi (double);
|
||||
unsigned long long __fixunssfdi (float);
|
||||
double __floatdidf (long long);
|
||||
float __floatdisf (long long);
|
||||
double __floatunsdidf(unsigned long long);
|
||||
long long __fixdfdi(double);
|
||||
long long __fixsfdi(float);
|
||||
unsigned long long __fixunsdfdi(double);
|
||||
unsigned long long __fixunssfdi(float);
|
||||
double __floatdidf(long long);
|
||||
float __floatdisf(long long);
|
||||
double __floatunsdidf(unsigned long long);
|
||||
#endif
|
||||
|
||||
unsigned long long __qdivrem (unsigned long long, unsigned long long,
|
||||
unsigned long long *);
|
||||
unsigned long long __qdivrem(unsigned long long, unsigned long long,
|
||||
unsigned long long *);
|
||||
|
||||
@@ -41,21 +41,18 @@
|
||||
* Shift an (unsigned) long long value left (logical shift left).
|
||||
* This is the same as arithmetic shift left!
|
||||
*/
|
||||
long long
|
||||
__lshldi3(long long a, unsigned int shift)
|
||||
{
|
||||
union uu aa;
|
||||
long long __lshldi3(long long a, unsigned int shift) {
|
||||
union uu aa;
|
||||
|
||||
if (shift == 0)
|
||||
return(a);
|
||||
aa.ll = a;
|
||||
if (shift >= INT_BITS) {
|
||||
aa.ui[H] = aa.ui[L] << (shift - INT_BITS);
|
||||
aa.ui[L] = 0;
|
||||
} else {
|
||||
aa.ui[H] = (aa.ui[H] << shift) |
|
||||
(aa.ui[L] >> (INT_BITS - shift));
|
||||
aa.ui[L] <<= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
if (shift == 0)
|
||||
return (a);
|
||||
aa.ll = a;
|
||||
if (shift >= INT_BITS) {
|
||||
aa.ui[H] = aa.ui[L] << (shift - INT_BITS);
|
||||
aa.ui[L] = 0;
|
||||
} else {
|
||||
aa.ui[H] = (aa.ui[H] << shift) | (aa.ui[L] >> (INT_BITS - shift));
|
||||
aa.ui[L] <<= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
}
|
||||
|
||||
@@ -40,21 +40,18 @@
|
||||
/*
|
||||
* Shift an (unsigned) long long value right (logical shift right).
|
||||
*/
|
||||
long long
|
||||
__lshrdi3(long long a, unsigned int shift)
|
||||
{
|
||||
union uu aa;
|
||||
long long __lshrdi3(long long a, unsigned int shift) {
|
||||
union uu aa;
|
||||
|
||||
if (shift == 0)
|
||||
return(a);
|
||||
aa.ll = a;
|
||||
if (shift >= INT_BITS) {
|
||||
aa.ui[L] = aa.ui[H] >> (shift - INT_BITS);
|
||||
aa.ui[H] = 0;
|
||||
} else {
|
||||
aa.ui[L] = (aa.ui[L] >> shift) |
|
||||
(aa.ui[H] << (INT_BITS - shift));
|
||||
aa.ui[H] >>= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
if (shift == 0)
|
||||
return (a);
|
||||
aa.ll = a;
|
||||
if (shift >= INT_BITS) {
|
||||
aa.ui[L] = aa.ui[H] >> (shift - INT_BITS);
|
||||
aa.ui[H] = 0;
|
||||
} else {
|
||||
aa.ui[L] = (aa.ui[L] >> shift) | (aa.ui[H] << (INT_BITS - shift));
|
||||
aa.ui[H] >>= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
}
|
||||
|
||||
@@ -42,21 +42,19 @@
|
||||
*
|
||||
* XXX we assume a % b < 0 iff a < 0, but this is actually machine-dependent.
|
||||
*/
|
||||
long long
|
||||
__moddi3(long long a, long long b)
|
||||
{
|
||||
unsigned long long ua, ub, ur;
|
||||
int neg = 0;
|
||||
long long __moddi3(long long a, long long b) {
|
||||
unsigned long long ua, ub, ur;
|
||||
int neg = 0;
|
||||
|
||||
ua = a;
|
||||
ub = b;
|
||||
ua = a;
|
||||
ub = b;
|
||||
|
||||
if (a < 0)
|
||||
ua = -ua, neg ^= 1;
|
||||
if (b < 0)
|
||||
ub = -ub;
|
||||
(void)__qdivrem(ua, ub, &ur);
|
||||
if (neg)
|
||||
ur = -ur;
|
||||
return (ur);
|
||||
if (a < 0)
|
||||
ua = -ua, neg ^= 1;
|
||||
if (b < 0)
|
||||
ub = -ub;
|
||||
(void)__qdivrem(ua, ub, &ur);
|
||||
if (neg)
|
||||
ur = -ur;
|
||||
return (ur);
|
||||
}
|
||||
|
||||
@@ -96,67 +96,64 @@
|
||||
*/
|
||||
static long long __lmulq(unsigned int, unsigned int);
|
||||
|
||||
long long
|
||||
__muldi3(long long a, long long b)
|
||||
{
|
||||
union uu u, v, low, prod;
|
||||
unsigned int high, mid, udiff, vdiff;
|
||||
int negall, negmid;
|
||||
#define u1 u.ui[H]
|
||||
#define u0 u.ui[L]
|
||||
#define v1 v.ui[H]
|
||||
#define v0 v.ui[L]
|
||||
long long __muldi3(long long a, long long b) {
|
||||
union uu u, v, low, prod;
|
||||
unsigned int high, mid, udiff, vdiff;
|
||||
int negall, negmid;
|
||||
#define u1 u.ui[H]
|
||||
#define u0 u.ui[L]
|
||||
#define v1 v.ui[H]
|
||||
#define v0 v.ui[L]
|
||||
|
||||
/*
|
||||
* Get u and v such that u, v >= 0. When this is finished,
|
||||
* u1, u0, v1, and v0 will be directly accessible through the
|
||||
* int fields.
|
||||
*/
|
||||
if (a >= 0)
|
||||
u.ll = a, negall = 0;
|
||||
else
|
||||
u.ll = -a, negall = 1;
|
||||
if (b >= 0)
|
||||
v.ll = b;
|
||||
else
|
||||
v.ll = -b, negall ^= 1;
|
||||
/*
|
||||
* Get u and v such that u, v >= 0. When this is finished,
|
||||
* u1, u0, v1, and v0 will be directly accessible through the
|
||||
* int fields.
|
||||
*/
|
||||
if (a >= 0)
|
||||
u.ll = a, negall = 0;
|
||||
else
|
||||
u.ll = -a, negall = 1;
|
||||
if (b >= 0)
|
||||
v.ll = b;
|
||||
else
|
||||
v.ll = -b, negall ^= 1;
|
||||
|
||||
if (u1 == 0 && v1 == 0) {
|
||||
/*
|
||||
* An (I hope) important optimization occurs when u1 and v1
|
||||
* are both 0. This should be common since most numbers
|
||||
* are small. Here the product is just u0*v0.
|
||||
*/
|
||||
prod.ll = __lmulq(u0, v0);
|
||||
} else {
|
||||
/*
|
||||
* 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
|
||||
* unsigned int * unsigned int => unsigned int arithmetic.
|
||||
*/
|
||||
low.ll = __lmulq(u0, v0);
|
||||
if (u1 == 0 && v1 == 0) {
|
||||
/*
|
||||
* An (I hope) important optimization occurs when u1 and v1
|
||||
* are both 0. This should be common since most numbers
|
||||
* are small. Here the product is just u0*v0.
|
||||
*/
|
||||
prod.ll = __lmulq(u0, v0);
|
||||
} else {
|
||||
/*
|
||||
* 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
|
||||
* unsigned int * unsigned int => unsigned int arithmetic.
|
||||
*/
|
||||
low.ll = __lmulq(u0, v0);
|
||||
|
||||
if (u1 >= u0)
|
||||
negmid = 0, udiff = u1 - u0;
|
||||
else
|
||||
negmid = 1, udiff = u0 - u1;
|
||||
if (v0 >= v1)
|
||||
vdiff = v0 - v1;
|
||||
else
|
||||
vdiff = v1 - v0, negmid ^= 1;
|
||||
mid = udiff * vdiff;
|
||||
if (u1 >= u0)
|
||||
negmid = 0, udiff = u1 - u0;
|
||||
else
|
||||
negmid = 1, udiff = u0 - u1;
|
||||
if (v0 >= v1)
|
||||
vdiff = v0 - v1;
|
||||
else
|
||||
vdiff = v1 - v0, negmid ^= 1;
|
||||
mid = udiff * vdiff;
|
||||
|
||||
high = u1 * v1;
|
||||
high = u1 * v1;
|
||||
|
||||
/*
|
||||
* Assemble the final product.
|
||||
*/
|
||||
prod.ui[H] = high + (negmid ? -mid : mid) + low.ui[L] +
|
||||
low.ui[H];
|
||||
prod.ui[L] = low.ui[L];
|
||||
}
|
||||
return (negall ? -prod.ll : prod.ll);
|
||||
/*
|
||||
* Assemble the final product.
|
||||
*/
|
||||
prod.ui[H] = high + (negmid ? -mid : mid) + low.ui[L] + low.ui[H];
|
||||
prod.ui[L] = low.ui[L];
|
||||
}
|
||||
return (negall ? -prod.ll : prod.ll);
|
||||
#undef u1
|
||||
#undef u0
|
||||
#undef v1
|
||||
@@ -180,62 +177,60 @@ __muldi3(long long a, long long b)
|
||||
*
|
||||
* splits into high and low ints as HHALF(l) and LHUP(l) respectively.
|
||||
*/
|
||||
static long long
|
||||
__lmulq(unsigned int u, unsigned int v)
|
||||
{
|
||||
unsigned int u1, u0, v1, v0, udiff, vdiff, high, mid, low;
|
||||
unsigned int prodh, prodl, was;
|
||||
union uu prod;
|
||||
int neg;
|
||||
static long long __lmulq(unsigned int u, unsigned int v) {
|
||||
unsigned int u1, u0, v1, v0, udiff, vdiff, high, mid, low;
|
||||
unsigned int prodh, prodl, was;
|
||||
union uu prod;
|
||||
int neg;
|
||||
|
||||
u1 = HHALF(u);
|
||||
u0 = LHALF(u);
|
||||
v1 = HHALF(v);
|
||||
v0 = LHALF(v);
|
||||
u1 = HHALF(u);
|
||||
u0 = LHALF(u);
|
||||
v1 = HHALF(v);
|
||||
v0 = LHALF(v);
|
||||
|
||||
low = u0 * v0;
|
||||
low = u0 * v0;
|
||||
|
||||
/* This is the same small-number optimization as before. */
|
||||
if (u1 == 0 && v1 == 0)
|
||||
return (low);
|
||||
/* This is the same small-number optimization as before. */
|
||||
if (u1 == 0 && v1 == 0)
|
||||
return (low);
|
||||
|
||||
if (u1 >= u0)
|
||||
udiff = u1 - u0, neg = 0;
|
||||
else
|
||||
udiff = u0 - u1, neg = 1;
|
||||
if (v0 >= v1)
|
||||
vdiff = v0 - v1;
|
||||
else
|
||||
vdiff = v1 - v0, neg ^= 1;
|
||||
mid = udiff * vdiff;
|
||||
if (u1 >= u0)
|
||||
udiff = u1 - u0, neg = 0;
|
||||
else
|
||||
udiff = u0 - u1, neg = 1;
|
||||
if (v0 >= v1)
|
||||
vdiff = v0 - v1;
|
||||
else
|
||||
vdiff = v1 - v0, neg ^= 1;
|
||||
mid = udiff * vdiff;
|
||||
|
||||
high = u1 * v1;
|
||||
high = u1 * v1;
|
||||
|
||||
/* prod = (high << 2N) + (high << N); */
|
||||
prodh = high + HHALF(high);
|
||||
prodl = LHUP(high);
|
||||
/* prod = (high << 2N) + (high << N); */
|
||||
prodh = high + HHALF(high);
|
||||
prodl = LHUP(high);
|
||||
|
||||
/* if (neg) prod -= mid << N; else prod += mid << N; */
|
||||
if (neg) {
|
||||
was = prodl;
|
||||
prodl -= LHUP(mid);
|
||||
prodh -= HHALF(mid) + (prodl > was);
|
||||
} else {
|
||||
was = prodl;
|
||||
prodl += LHUP(mid);
|
||||
prodh += HHALF(mid) + (prodl < was);
|
||||
}
|
||||
/* if (neg) prod -= mid << N; else prod += mid << N; */
|
||||
if (neg) {
|
||||
was = prodl;
|
||||
prodl -= LHUP(mid);
|
||||
prodh -= HHALF(mid) + (prodl > was);
|
||||
} else {
|
||||
was = prodl;
|
||||
prodl += LHUP(mid);
|
||||
prodh += HHALF(mid) + (prodl < was);
|
||||
}
|
||||
|
||||
/* prod += low << N */
|
||||
was = prodl;
|
||||
prodl += LHUP(low);
|
||||
prodh += HHALF(low) + (prodl < was);
|
||||
/* ... + low; */
|
||||
if ((prodl += low) < low)
|
||||
prodh++;
|
||||
/* prod += low << N */
|
||||
was = prodl;
|
||||
prodl += LHUP(low);
|
||||
prodh += HHALF(low) + (prodl < was);
|
||||
/* ... + low; */
|
||||
if ((prodl += low) < low)
|
||||
prodh++;
|
||||
|
||||
/* return 4N-bit product */
|
||||
prod.ui[H] = prodh;
|
||||
prod.ui[L] = prodl;
|
||||
return (prod.ll);
|
||||
/* return 4N-bit product */
|
||||
prod.ui[H] = prodh;
|
||||
prod.ui[L] = prodl;
|
||||
return (prod.ll);
|
||||
}
|
||||
|
||||
@@ -40,13 +40,11 @@
|
||||
/*
|
||||
* Return -a (or, equivalently, 0 - a), in long long. See subdi3.c.
|
||||
*/
|
||||
long long
|
||||
__negdi2(long long a)
|
||||
{
|
||||
union uu aa, res;
|
||||
long long __negdi2(long long a) {
|
||||
union uu aa, res;
|
||||
|
||||
aa.ll = a;
|
||||
res.ui[L] = -aa.ui[L];
|
||||
res.ui[H] = -aa.ui[H] - (res.ui[L] > 0);
|
||||
return (res.ll);
|
||||
aa.ll = a;
|
||||
res.ui[L] = -aa.ui[L];
|
||||
res.ui[H] = -aa.ui[H] - (res.ui[L] > 0);
|
||||
return (res.ll);
|
||||
}
|
||||
|
||||
@@ -41,13 +41,11 @@
|
||||
* Return ~a. For some reason gcc calls this `one's complement' rather
|
||||
* than `not'.
|
||||
*/
|
||||
long long
|
||||
__one_cmpldi2(long long a)
|
||||
{
|
||||
union uu aa;
|
||||
long long __one_cmpldi2(long long a) {
|
||||
union uu aa;
|
||||
|
||||
aa.ll = a;
|
||||
aa.ui[0] = ~aa.ui[0];
|
||||
aa.ui[1] = ~aa.ui[1];
|
||||
return (aa.ll);
|
||||
aa.ll = a;
|
||||
aa.ui[0] = ~aa.ui[0];
|
||||
aa.ui[1] = ~aa.ui[1];
|
||||
return (aa.ll);
|
||||
}
|
||||
|
||||
@@ -42,10 +42,10 @@
|
||||
|
||||
#include "longlong.h"
|
||||
|
||||
#define B ((int)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) (((unsigned int)(a) << HALF_BITS) | (b))
|
||||
#define COMBINE(a, b) (((unsigned int)(a) << HALF_BITS) | (b))
|
||||
|
||||
/* select a type for digits in base B: use unsigned short if they fit */
|
||||
#if UINT_MAX == 0xffffffffU && USHRT_MAX >= 0xffff
|
||||
@@ -64,202 +64,199 @@ static void shl(digit *p, int len, int sh);
|
||||
* length dividend and divisor are 4 `digits' in this base (they are
|
||||
* shorter if they have leading zeros).
|
||||
*/
|
||||
unsigned long long
|
||||
__qdivrem(unsigned long long ull, unsigned long long vll,
|
||||
unsigned long long *arq)
|
||||
{
|
||||
union uu tmp;
|
||||
digit *u, *v, *q;
|
||||
digit v1, v2;
|
||||
unsigned int qhat, rhat, t;
|
||||
int m, n, d, j, i;
|
||||
digit uspace[5], vspace[5], qspace[5];
|
||||
unsigned long long __qdivrem(unsigned long long ull, unsigned long long vll,
|
||||
unsigned long long *arq) {
|
||||
union uu tmp;
|
||||
digit *u, *v, *q;
|
||||
digit v1, v2;
|
||||
unsigned int qhat, rhat, t;
|
||||
int m, n, d, j, i;
|
||||
digit uspace[5], vspace[5], qspace[5];
|
||||
|
||||
/*
|
||||
* Take care of special cases: divide by zero, and u < v.
|
||||
*/
|
||||
if (vll == 0) {
|
||||
/* divide by zero. */
|
||||
static volatile const unsigned int zero = 0;
|
||||
/*
|
||||
* Take care of special cases: divide by zero, and u < v.
|
||||
*/
|
||||
if (vll == 0) {
|
||||
/* divide by zero. */
|
||||
static volatile const unsigned int zero = 0;
|
||||
|
||||
tmp.ui[H] = tmp.ui[L] = 1 / zero;
|
||||
if (arq)
|
||||
*arq = ull;
|
||||
return (tmp.ll);
|
||||
}
|
||||
if (ull < vll) {
|
||||
if (arq)
|
||||
*arq = ull;
|
||||
return (0);
|
||||
}
|
||||
u = &uspace[0];
|
||||
v = &vspace[0];
|
||||
q = &qspace[0];
|
||||
tmp.ui[H] = tmp.ui[L] = 1 / zero;
|
||||
if (arq)
|
||||
*arq = ull;
|
||||
return (tmp.ll);
|
||||
}
|
||||
if (ull < vll) {
|
||||
if (arq)
|
||||
*arq = ull;
|
||||
return (0);
|
||||
}
|
||||
u = &uspace[0];
|
||||
v = &vspace[0];
|
||||
q = &qspace[0];
|
||||
|
||||
/*
|
||||
* Break dividend and divisor into digits in base B, then
|
||||
* count leading zeros to determine m and n. When done, we
|
||||
* will have:
|
||||
* u = (u[1]u[2]...u[m+n]) sub B
|
||||
* v = (v[1]v[2]...v[n]) sub B
|
||||
* v[1] != 0
|
||||
* 1 < n <= 4 (if n = 1, we use a different division algorithm)
|
||||
* m >= 0 (otherwise u < v, which we already checked)
|
||||
* m + n = 4
|
||||
* and thus
|
||||
* m = 4 - n <= 2
|
||||
*/
|
||||
tmp.ull = ull;
|
||||
u[0] = 0;
|
||||
u[1] = (digit)HHALF(tmp.ui[H]);
|
||||
u[2] = (digit)LHALF(tmp.ui[H]);
|
||||
u[3] = (digit)HHALF(tmp.ui[L]);
|
||||
u[4] = (digit)LHALF(tmp.ui[L]);
|
||||
tmp.ull = vll;
|
||||
v[1] = (digit)HHALF(tmp.ui[H]);
|
||||
v[2] = (digit)LHALF(tmp.ui[H]);
|
||||
v[3] = (digit)HHALF(tmp.ui[L]);
|
||||
v[4] = (digit)LHALF(tmp.ui[L]);
|
||||
for (n = 4; v[1] == 0; v++) {
|
||||
if (--n == 1) {
|
||||
unsigned int rbj; /* r*B+u[j] (not root boy jim) */
|
||||
digit q1, q2, q3, q4;
|
||||
/*
|
||||
* Break dividend and divisor into digits in base B, then
|
||||
* count leading zeros to determine m and n. When done, we
|
||||
* will have:
|
||||
* u = (u[1]u[2]...u[m+n]) sub B
|
||||
* v = (v[1]v[2]...v[n]) sub B
|
||||
* v[1] != 0
|
||||
* 1 < n <= 4 (if n = 1, we use a different division algorithm)
|
||||
* m >= 0 (otherwise u < v, which we already checked)
|
||||
* m + n = 4
|
||||
* and thus
|
||||
* m = 4 - n <= 2
|
||||
*/
|
||||
tmp.ull = ull;
|
||||
u[0] = 0;
|
||||
u[1] = (digit)HHALF(tmp.ui[H]);
|
||||
u[2] = (digit)LHALF(tmp.ui[H]);
|
||||
u[3] = (digit)HHALF(tmp.ui[L]);
|
||||
u[4] = (digit)LHALF(tmp.ui[L]);
|
||||
tmp.ull = vll;
|
||||
v[1] = (digit)HHALF(tmp.ui[H]);
|
||||
v[2] = (digit)LHALF(tmp.ui[H]);
|
||||
v[3] = (digit)HHALF(tmp.ui[L]);
|
||||
v[4] = (digit)LHALF(tmp.ui[L]);
|
||||
for (n = 4; v[1] == 0; v++) {
|
||||
if (--n == 1) {
|
||||
unsigned int rbj; /* r*B+u[j] (not root boy jim) */
|
||||
digit q1, q2, q3, q4;
|
||||
|
||||
/*
|
||||
* Change of plan, per exercise 16.
|
||||
* r = 0;
|
||||
* for j = 1..4:
|
||||
* q[j] = floor((r*B + u[j]) / v),
|
||||
* r = (r*B + u[j]) % v;
|
||||
* We unroll this completely here.
|
||||
*/
|
||||
t = v[2]; /* nonzero, by definition */
|
||||
q1 = (digit)(u[1] / t);
|
||||
rbj = COMBINE(u[1] % t, u[2]);
|
||||
q2 = (digit)(rbj / t);
|
||||
rbj = COMBINE(rbj % t, u[3]);
|
||||
q3 = (digit)(rbj / t);
|
||||
rbj = COMBINE(rbj % t, u[4]);
|
||||
q4 = (digit)(rbj / t);
|
||||
if (arq)
|
||||
*arq = rbj % t;
|
||||
tmp.ui[H] = COMBINE(q1, q2);
|
||||
tmp.ui[L] = COMBINE(q3, q4);
|
||||
return (tmp.ll);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Change of plan, per exercise 16.
|
||||
* r = 0;
|
||||
* for j = 1..4:
|
||||
* q[j] = floor((r*B + u[j]) / v),
|
||||
* r = (r*B + u[j]) % v;
|
||||
* We unroll this completely here.
|
||||
*/
|
||||
t = v[2]; /* nonzero, by definition */
|
||||
q1 = (digit)(u[1] / t);
|
||||
rbj = COMBINE(u[1] % t, u[2]);
|
||||
q2 = (digit)(rbj / t);
|
||||
rbj = COMBINE(rbj % t, u[3]);
|
||||
q3 = (digit)(rbj / t);
|
||||
rbj = COMBINE(rbj % t, u[4]);
|
||||
q4 = (digit)(rbj / t);
|
||||
if (arq)
|
||||
*arq = rbj % t;
|
||||
tmp.ui[H] = COMBINE(q1, q2);
|
||||
tmp.ui[L] = COMBINE(q3, q4);
|
||||
return (tmp.ll);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* By adjusting q once we determine m, we can guarantee that
|
||||
* there is a complete four-digit quotient at &qspace[1] when
|
||||
* we finally stop.
|
||||
*/
|
||||
for (m = 4 - n; u[1] == 0; u++)
|
||||
m--;
|
||||
for (i = 4 - m; --i >= 0;)
|
||||
q[i] = 0;
|
||||
q += 4 - m;
|
||||
/*
|
||||
* By adjusting q once we determine m, we can guarantee that
|
||||
* there is a complete four-digit quotient at &qspace[1] when
|
||||
* we finally stop.
|
||||
*/
|
||||
for (m = 4 - n; u[1] == 0; u++)
|
||||
m--;
|
||||
for (i = 4 - m; --i >= 0;)
|
||||
q[i] = 0;
|
||||
q += 4 - m;
|
||||
|
||||
/*
|
||||
* Here we run Program D, translated from MIX to C and acquiring
|
||||
* a few minor changes.
|
||||
*
|
||||
* D1: choose multiplier 1 << d to ensure v[1] >= B/2.
|
||||
*/
|
||||
d = 0;
|
||||
for (t = v[1]; t < B / 2; t <<= 1)
|
||||
d++;
|
||||
if (d > 0) {
|
||||
shl(&u[0], m + n, d); /* u <<= d */
|
||||
shl(&v[1], n - 1, d); /* v <<= d */
|
||||
}
|
||||
/*
|
||||
* D2: j = 0.
|
||||
*/
|
||||
j = 0;
|
||||
v1 = v[1]; /* for D3 -- note that v[1..n] are constant */
|
||||
v2 = v[2]; /* for D3 */
|
||||
do {
|
||||
digit uj0, uj1, uj2;
|
||||
/*
|
||||
* Here we run Program D, translated from MIX to C and acquiring
|
||||
* a few minor changes.
|
||||
*
|
||||
* D1: choose multiplier 1 << d to ensure v[1] >= B/2.
|
||||
*/
|
||||
d = 0;
|
||||
for (t = v[1]; t < B / 2; t <<= 1)
|
||||
d++;
|
||||
if (d > 0) {
|
||||
shl(&u[0], m + n, d); /* u <<= d */
|
||||
shl(&v[1], n - 1, d); /* v <<= d */
|
||||
}
|
||||
/*
|
||||
* D2: j = 0.
|
||||
*/
|
||||
j = 0;
|
||||
v1 = v[1]; /* for D3 -- note that v[1..n] are constant */
|
||||
v2 = v[2]; /* for D3 */
|
||||
do {
|
||||
digit uj0, uj1, uj2;
|
||||
|
||||
/*
|
||||
* D3: Calculate qhat (\^q, in TeX notation).
|
||||
* Let qhat = min((u[j]*B + u[j+1])/v[1], B-1), and
|
||||
* let rhat = (u[j]*B + u[j+1]) mod v[1].
|
||||
* While rhat < B and v[2]*qhat > rhat*B+u[j+2],
|
||||
* decrement qhat and increase rhat correspondingly.
|
||||
* Note that if rhat >= B, v[2]*qhat < rhat*B.
|
||||
*/
|
||||
uj0 = u[j + 0]; /* for D3 only -- note that u[j+...] change */
|
||||
uj1 = u[j + 1]; /* for D3 only */
|
||||
uj2 = u[j + 2]; /* for D3 only */
|
||||
if (uj0 == v1) {
|
||||
qhat = B;
|
||||
rhat = uj1;
|
||||
goto qhat_too_big;
|
||||
} else {
|
||||
unsigned int nn = COMBINE(uj0, uj1);
|
||||
qhat = nn / v1;
|
||||
rhat = nn % v1;
|
||||
}
|
||||
while (v2 * qhat > COMBINE(rhat, uj2)) {
|
||||
qhat_too_big:
|
||||
qhat--;
|
||||
if ((rhat += v1) >= B)
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* D4: Multiply and subtract.
|
||||
* The variable `t' holds any borrows across the loop.
|
||||
* We split this up so that we do not require v[0] = 0,
|
||||
* and to eliminate a final special case.
|
||||
*/
|
||||
for (t = 0, i = n; i > 0; i--) {
|
||||
t = u[i + j] - v[i] * qhat - t;
|
||||
u[i + j] = (digit)LHALF(t);
|
||||
t = (B - HHALF(t)) & (B - 1);
|
||||
}
|
||||
t = u[j] - t;
|
||||
u[j] = (digit)LHALF(t);
|
||||
/*
|
||||
* D5: test remainder.
|
||||
* There is a borrow if and only if HHALF(t) is nonzero;
|
||||
* in that (rare) case, qhat was too large (by exactly 1).
|
||||
* Fix it by adding v[1..n] to u[j..j+n].
|
||||
*/
|
||||
if (HHALF(t)) {
|
||||
qhat--;
|
||||
for (t = 0, i = n; i > 0; i--) { /* D6: add back. */
|
||||
t += u[i + j] + v[i];
|
||||
u[i + j] = (digit)LHALF(t);
|
||||
t = HHALF(t);
|
||||
}
|
||||
u[j] = (digit)LHALF(u[j] + t);
|
||||
}
|
||||
q[j] = (digit)qhat;
|
||||
} while (++j <= m); /* D7: loop on j. */
|
||||
/*
|
||||
* D3: Calculate qhat (\^q, in TeX notation).
|
||||
* Let qhat = min((u[j]*B + u[j+1])/v[1], B-1), and
|
||||
* let rhat = (u[j]*B + u[j+1]) mod v[1].
|
||||
* While rhat < B and v[2]*qhat > rhat*B+u[j+2],
|
||||
* decrement qhat and increase rhat correspondingly.
|
||||
* Note that if rhat >= B, v[2]*qhat < rhat*B.
|
||||
*/
|
||||
uj0 = u[j + 0]; /* for D3 only -- note that u[j+...] change */
|
||||
uj1 = u[j + 1]; /* for D3 only */
|
||||
uj2 = u[j + 2]; /* for D3 only */
|
||||
if (uj0 == v1) {
|
||||
qhat = B;
|
||||
rhat = uj1;
|
||||
goto qhat_too_big;
|
||||
} else {
|
||||
unsigned int nn = COMBINE(uj0, uj1);
|
||||
qhat = nn / v1;
|
||||
rhat = nn % v1;
|
||||
}
|
||||
while (v2 * qhat > COMBINE(rhat, uj2)) {
|
||||
qhat_too_big:
|
||||
qhat--;
|
||||
if ((rhat += v1) >= B)
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* D4: Multiply and subtract.
|
||||
* The variable `t' holds any borrows across the loop.
|
||||
* We split this up so that we do not require v[0] = 0,
|
||||
* and to eliminate a final special case.
|
||||
*/
|
||||
for (t = 0, i = n; i > 0; i--) {
|
||||
t = u[i + j] - v[i] * qhat - t;
|
||||
u[i + j] = (digit)LHALF(t);
|
||||
t = (B - HHALF(t)) & (B - 1);
|
||||
}
|
||||
t = u[j] - t;
|
||||
u[j] = (digit)LHALF(t);
|
||||
/*
|
||||
* D5: test remainder.
|
||||
* There is a borrow if and only if HHALF(t) is nonzero;
|
||||
* in that (rare) case, qhat was too large (by exactly 1).
|
||||
* Fix it by adding v[1..n] to u[j..j+n].
|
||||
*/
|
||||
if (HHALF(t)) {
|
||||
qhat--;
|
||||
for (t = 0, i = n; i > 0; i--) { /* D6: add back. */
|
||||
t += u[i + j] + v[i];
|
||||
u[i + j] = (digit)LHALF(t);
|
||||
t = HHALF(t);
|
||||
}
|
||||
u[j] = (digit)LHALF(u[j] + t);
|
||||
}
|
||||
q[j] = (digit)qhat;
|
||||
} while (++j <= m); /* D7: loop on j. */
|
||||
|
||||
/*
|
||||
* If caller wants the remainder, we have to calculate it as
|
||||
* u[m..m+n] >> d (this is at most n digits and thus fits in
|
||||
* u[m+1..m+n], but we may need more source digits).
|
||||
*/
|
||||
if (arq) {
|
||||
if (d) {
|
||||
for (i = m + n; i > m; --i)
|
||||
u[i] = (digit)(((unsigned int)u[i] >> d) |
|
||||
LHALF((unsigned int)u[i - 1] <<
|
||||
(HALF_BITS - d)));
|
||||
u[i] = 0;
|
||||
}
|
||||
tmp.ui[H] = COMBINE(uspace[1], uspace[2]);
|
||||
tmp.ui[L] = COMBINE(uspace[3], uspace[4]);
|
||||
*arq = tmp.ll;
|
||||
}
|
||||
/*
|
||||
* If caller wants the remainder, we have to calculate it as
|
||||
* u[m..m+n] >> d (this is at most n digits and thus fits in
|
||||
* u[m+1..m+n], but we may need more source digits).
|
||||
*/
|
||||
if (arq) {
|
||||
if (d) {
|
||||
for (i = m + n; i > m; --i)
|
||||
u[i] = (digit)(((unsigned int)u[i] >> d) |
|
||||
LHALF((unsigned int)u[i - 1] << (HALF_BITS - d)));
|
||||
u[i] = 0;
|
||||
}
|
||||
tmp.ui[H] = COMBINE(uspace[1], uspace[2]);
|
||||
tmp.ui[L] = COMBINE(uspace[3], uspace[4]);
|
||||
*arq = tmp.ll;
|
||||
}
|
||||
|
||||
tmp.ui[H] = COMBINE(qspace[1], qspace[2]);
|
||||
tmp.ui[L] = COMBINE(qspace[3], qspace[4]);
|
||||
return (tmp.ll);
|
||||
tmp.ui[H] = COMBINE(qspace[1], qspace[2]);
|
||||
tmp.ui[L] = COMBINE(qspace[3], qspace[4]);
|
||||
return (tmp.ll);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -267,13 +264,11 @@ __qdivrem(unsigned long long ull, unsigned long long vll,
|
||||
* `fall out' the left (there never will be any such anyway).
|
||||
* We may assume len >= 0. NOTE THAT THIS WRITES len+1 DIGITS.
|
||||
*/
|
||||
static void
|
||||
shl(digit *p, int len, int sh)
|
||||
{
|
||||
int i;
|
||||
static void shl(digit *p, int len, int sh) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
p[i] = (digit)(LHALF((unsigned int)p[i] << sh) |
|
||||
((unsigned int)p[i + 1] >> (HALF_BITS - sh)));
|
||||
p[i] = (digit)(LHALF((unsigned int)p[i] << sh));
|
||||
for (i = 0; i < len; i++)
|
||||
p[i] = (digit)(LHALF((unsigned int)p[i] << sh) |
|
||||
((unsigned int)p[i + 1] >> (HALF_BITS - sh)));
|
||||
p[i] = (digit)(LHALF((unsigned int)p[i] << sh));
|
||||
}
|
||||
|
||||
@@ -42,14 +42,12 @@
|
||||
* carry from a single unsigned int difference x-y occurs if and only
|
||||
* if (x-y) > x.
|
||||
*/
|
||||
long long
|
||||
__subdi3(long long a, long long b)
|
||||
{
|
||||
union uu aa, bb, diff;
|
||||
long long __subdi3(long long a, long long b) {
|
||||
union uu aa, bb, diff;
|
||||
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
diff.ui[L] = aa.ui[L] - bb.ui[L];
|
||||
diff.ui[H] = aa.ui[H] - bb.ui[H] - (diff.ui[L] > aa.ui[L]);
|
||||
return (diff.ll);
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
diff.ui[L] = aa.ui[L] - bb.ui[L];
|
||||
diff.ui[H] = aa.ui[H] - bb.ui[H] - (diff.ui[L] > aa.ui[L]);
|
||||
return (diff.ll);
|
||||
}
|
||||
|
||||
@@ -41,13 +41,14 @@
|
||||
* Return 0, 1, or 2 as a <, =, > b respectively.
|
||||
* Neither a nor b are considered signed.
|
||||
*/
|
||||
int
|
||||
__ucmpdi2(unsigned long long a, unsigned long long b)
|
||||
{
|
||||
union uu aa, bb;
|
||||
int __ucmpdi2(unsigned long long a, unsigned long long b) {
|
||||
union uu aa, bb;
|
||||
|
||||
aa.ull = a;
|
||||
bb.ull = b;
|
||||
return (aa.ui[H] < bb.ui[H] ? 0 : aa.ui[H] > bb.ui[H] ? 2 :
|
||||
aa.ui[L] < bb.ui[L] ? 0 : aa.ui[L] > bb.ui[L] ? 2 : 1);
|
||||
aa.ull = a;
|
||||
bb.ull = b;
|
||||
return (aa.ui[H] < bb.ui[H] ? 0
|
||||
: aa.ui[H] > bb.ui[H] ? 2
|
||||
: aa.ui[L] < bb.ui[L] ? 0
|
||||
: aa.ui[L] > bb.ui[L] ? 2
|
||||
: 1);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
/*
|
||||
* Divide two unsigned long longs.
|
||||
*/
|
||||
unsigned long long
|
||||
__udivdi3(unsigned long long a, unsigned long long b)
|
||||
{
|
||||
unsigned long long __udivdi3(unsigned long long a, unsigned long long b) {
|
||||
|
||||
return __qdivrem(a, b, NULL);
|
||||
return __qdivrem(a, b, NULL);
|
||||
}
|
||||
|
||||
@@ -40,11 +40,9 @@
|
||||
/*
|
||||
* Return remainder after dividing two unsigned long longs.
|
||||
*/
|
||||
unsigned long long
|
||||
__umoddi3(unsigned long long a, unsigned long long b)
|
||||
{
|
||||
unsigned long long r;
|
||||
unsigned long long __umoddi3(unsigned long long a, unsigned long long b) {
|
||||
unsigned long long r;
|
||||
|
||||
(void)__qdivrem(a, b, &r);
|
||||
return (r);
|
||||
(void)__qdivrem(a, b, &r);
|
||||
return (r);
|
||||
}
|
||||
|
||||
@@ -40,14 +40,12 @@
|
||||
/*
|
||||
* Return a ^ b, in long long.
|
||||
*/
|
||||
long long
|
||||
__xordi3(long long a, long long b)
|
||||
{
|
||||
union uu aa, bb;
|
||||
long long __xordi3(long long a, long long b) {
|
||||
union uu aa, bb;
|
||||
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
aa.ui[0] ^= bb.ui[0];
|
||||
aa.ui[1] ^= bb.ui[1];
|
||||
return (aa.ll);
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
aa.ui[0] ^= bb.ui[0];
|
||||
aa.ui[1] ^= bb.ui[1];
|
||||
return (aa.ll);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user