Support: Extract ScaledNumbers::compare()

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211507 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2014-06-23 17:47:40 +00:00
parent 88a564f55e
commit 18a301e578
4 changed files with 87 additions and 35 deletions

View File

@ -66,19 +66,6 @@ public:
return IsNeg ? INT64_MIN : INT64_MAX;
return IsNeg ? -int64_t(U) : int64_t(U);
}
static int compare(uint64_t L, uint64_t R, int Shift) {
assert(Shift >= 0);
assert(Shift < 64);
uint64_t L_adjusted = L >> Shift;
if (L_adjusted < R)
return -1;
if (L_adjusted > R)
return 1;
return L > L_adjusted << Shift ? 1 : 0;
}
};
/// \brief Simple representation of an unsigned floating point.
@ -289,7 +276,9 @@ public:
return joinSigned(scaleByInverse(Unsigned.first), Unsigned.second);
}
int compare(const UnsignedFloat &X) const;
int compare(const UnsignedFloat &X) const {
return ScaledNumbers::compare(Digits, Exponent, X.Digits, X.Exponent);
}
int compareTo(uint64_t N) const {
UnsignedFloat Float = getFloat(N);
int Compare = compare(Float);
@ -605,27 +594,6 @@ void UnsignedFloat<DigitsT>::shiftRight(int32_t Shift) {
return;
}
template <class DigitsT>
int UnsignedFloat<DigitsT>::compare(const UnsignedFloat &X) const {
// Check for zero.
if (isZero())
return X.isZero() ? 0 : -1;
if (X.isZero())
return 1;
// Check for the scale. Use lgFloor to be sure that the exponent difference
// is always lower than 64.
int32_t lgL = lgFloor(), lgR = X.lgFloor();
if (lgL != lgR)
return lgL < lgR ? -1 : 1;
// Compare digits.
if (Exponent < X.Exponent)
return UnsignedFloatBase::compare(Digits, X.Digits, X.Exponent - Exponent);
return -UnsignedFloatBase::compare(X.Digits, Digits, Exponent - X.Exponent);
}
template <class T> struct isPodLike<UnsignedFloat<T>> {
static const bool value = true;
};