forked from OSchip/llvm-project
Support: Extract ScaledNumbers::MinScale and MaxScale
llvm-svn: 211558
This commit is contained in:
parent
b6bbd3f569
commit
e488c4a835
|
@ -42,8 +42,6 @@ namespace llvm {
|
|||
|
||||
class ScaledNumberBase {
|
||||
public:
|
||||
static const int32_t MaxScale = 16383;
|
||||
static const int32_t MinScale = -16382;
|
||||
static const int DefaultPrecision = 10;
|
||||
|
||||
static void dump(uint64_t D, int16_t E, int Width);
|
||||
|
@ -146,7 +144,7 @@ public:
|
|||
static ScaledNumber getZero() { return ScaledNumber(0, 0); }
|
||||
static ScaledNumber getOne() { return ScaledNumber(1, 0); }
|
||||
static ScaledNumber getLargest() {
|
||||
return ScaledNumber(DigitsLimits::max(), MaxScale);
|
||||
return ScaledNumber(DigitsLimits::max(), ScaledNumbers::MaxScale);
|
||||
}
|
||||
static ScaledNumber getFloat(uint64_t N) { return adjustToWidth(N, 0); }
|
||||
static ScaledNumber getInverseFloat(uint64_t N) {
|
||||
|
@ -235,7 +233,7 @@ public:
|
|||
std::tie(Digits, Scale) =
|
||||
ScaledNumbers::getSum(Digits, Scale, X.Digits, X.Scale);
|
||||
// Check for exponent past MaxScale.
|
||||
if (Scale > MaxScale)
|
||||
if (Scale > ScaledNumbers::MaxScale)
|
||||
*this = getLargest();
|
||||
return *this;
|
||||
}
|
||||
|
@ -331,8 +329,9 @@ private:
|
|||
///
|
||||
/// \pre Shift >= MinScale && Shift + 64 <= MaxScale.
|
||||
static ScaledNumber adjustToWidth(uint64_t N, int32_t Shift) {
|
||||
assert(Shift >= MinScale && "Shift should be close to 0");
|
||||
assert(Shift <= MaxScale - 64 && "Shift should be close to 0");
|
||||
assert(Shift >= ScaledNumbers::MinScale && "Shift should be close to 0");
|
||||
assert(Shift <= ScaledNumbers::MaxScale - 64 &&
|
||||
"Shift should be close to 0");
|
||||
auto Adjusted = ScaledNumbers::getAdjusted<DigitsT>(N, Shift);
|
||||
return Adjusted;
|
||||
}
|
||||
|
@ -462,7 +461,7 @@ template <class DigitsT> void ScaledNumber<DigitsT>::shiftLeft(int32_t Shift) {
|
|||
}
|
||||
|
||||
// Shift as much as we can in the exponent.
|
||||
int32_t ScaleShift = std::min(Shift, MaxScale - Scale);
|
||||
int32_t ScaleShift = std::min(Shift, ScaledNumbers::MaxScale - Scale);
|
||||
Scale += ScaleShift;
|
||||
if (ScaleShift == Shift)
|
||||
return;
|
||||
|
@ -493,7 +492,7 @@ template <class DigitsT> void ScaledNumber<DigitsT>::shiftRight(int32_t Shift) {
|
|||
}
|
||||
|
||||
// Shift as much as we can in the exponent.
|
||||
int32_t ScaleShift = std::min(Shift, Scale - MinScale);
|
||||
int32_t ScaleShift = std::min(Shift, Scale - ScaledNumbers::MinScale);
|
||||
Scale -= ScaleShift;
|
||||
if (ScaleShift == Shift)
|
||||
return;
|
||||
|
|
|
@ -32,6 +32,12 @@
|
|||
namespace llvm {
|
||||
namespace ScaledNumbers {
|
||||
|
||||
/// \brief Maximum scale; same as APFloat for easy debug printing.
|
||||
const int32_t MaxScale = 16383;
|
||||
|
||||
/// \brief Maximum scale; same as APFloat for easy debug printing.
|
||||
const int32_t MinScale = -16382;
|
||||
|
||||
/// \brief Get the width of a number.
|
||||
template <class DigitsT> inline int getWidth() { return sizeof(DigitsT) * 8; }
|
||||
|
||||
|
|
|
@ -27,11 +27,6 @@ using namespace llvm::bfi_detail;
|
|||
// ScaledNumber implementation.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifndef _MSC_VER
|
||||
const int32_t ScaledNumberBase::MaxScale;
|
||||
const int32_t ScaledNumberBase::MinScale;
|
||||
#endif
|
||||
|
||||
static void appendDigit(std::string &Str, unsigned D) {
|
||||
assert(D < 10);
|
||||
Str += '0' + D % 10;
|
||||
|
@ -58,22 +53,22 @@ static bool doesRoundUp(char Digit) {
|
|||
}
|
||||
|
||||
static std::string toStringAPFloat(uint64_t D, int E, unsigned Precision) {
|
||||
assert(E >= ScaledNumberBase::MinScale);
|
||||
assert(E <= ScaledNumberBase::MaxScale);
|
||||
assert(E >= ScaledNumbers::MinScale);
|
||||
assert(E <= ScaledNumbers::MaxScale);
|
||||
|
||||
// Find a new E, but don't let it increase past MaxScale.
|
||||
int LeadingZeros = ScaledNumberBase::countLeadingZeros64(D);
|
||||
int NewE = std::min(ScaledNumberBase::MaxScale, E + 63 - LeadingZeros);
|
||||
int NewE = std::min(ScaledNumbers::MaxScale, E + 63 - LeadingZeros);
|
||||
int Shift = 63 - (NewE - E);
|
||||
assert(Shift <= LeadingZeros);
|
||||
assert(Shift == LeadingZeros || NewE == ScaledNumberBase::MaxScale);
|
||||
assert(Shift == LeadingZeros || NewE == ScaledNumbers::MaxScale);
|
||||
D <<= Shift;
|
||||
E = NewE;
|
||||
|
||||
// Check for a denormal.
|
||||
unsigned AdjustedE = E + 16383;
|
||||
if (!(D >> 63)) {
|
||||
assert(E == ScaledNumberBase::MaxScale);
|
||||
assert(E == ScaledNumbers::MaxScale);
|
||||
AdjustedE = 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue