LLVM  6.0.0svn
Functions | Variables
llvm::ScaledNumbers Namespace Reference

Functions

template<class DigitsT >
int getWidth ()
 Get the width of a number. More...
 
template<class DigitsT >
std::pair< DigitsT, int16_t > getRounded (DigitsT Digits, int16_t Scale, bool ShouldRound)
 Conditionally round up a scaled number. More...
 
std::pair< uint32_t, int16_t > getRounded32 (uint32_t Digits, int16_t Scale, bool ShouldRound)
 Convenience helper for 32-bit rounding. More...
 
std::pair< uint64_t, int16_t > getRounded64 (uint64_t Digits, int16_t Scale, bool ShouldRound)
 Convenience helper for 64-bit rounding. More...
 
template<class DigitsT >
std::pair< DigitsT, int16_t > getAdjusted (uint64_t Digits, int16_t Scale=0)
 Adjust a 64-bit scaled number down to the appropriate width. More...
 
std::pair< uint32_t, int16_t > getAdjusted32 (uint64_t Digits, int16_t Scale=0)
 Convenience helper for adjusting to 32 bits. More...
 
std::pair< uint64_t, int16_t > getAdjusted64 (uint64_t Digits, int16_t Scale=0)
 Convenience helper for adjusting to 64 bits. More...
 
std::pair< uint64_t, int16_t > multiply64 (uint64_t LHS, uint64_t RHS)
 Multiply two 64-bit integers to create a 64-bit scaled number. More...
 
template<class DigitsT >
std::pair< DigitsT, int16_t > getProduct (DigitsT LHS, DigitsT RHS)
 Multiply two 32-bit integers to create a 32-bit scaled number. More...
 
std::pair< uint32_t, int16_t > getProduct32 (uint32_t LHS, uint32_t RHS)
 Convenience helper for 32-bit product. More...
 
std::pair< uint64_t, int16_t > getProduct64 (uint64_t LHS, uint64_t RHS)
 Convenience helper for 64-bit product. More...
 
std::pair< uint64_t, int16_t > divide64 (uint64_t Dividend, uint64_t Divisor)
 Divide two 64-bit integers to create a 64-bit scaled number. More...
 
std::pair< uint32_t, int16_t > divide32 (uint32_t Dividend, uint32_t Divisor)
 Divide two 32-bit integers to create a 32-bit scaled number. More...
 
template<class DigitsT >
std::pair< DigitsT, int16_t > getQuotient (DigitsT Dividend, DigitsT Divisor)
 Divide two 32-bit numbers to create a 32-bit scaled number. More...
 
std::pair< uint32_t, int16_t > getQuotient32 (uint32_t Dividend, uint32_t Divisor)
 Convenience helper for 32-bit quotient. More...
 
std::pair< uint64_t, int16_t > getQuotient64 (uint64_t Dividend, uint64_t Divisor)
 Convenience helper for 64-bit quotient. More...
 
template<class DigitsT >
std::pair< int32_t, int > getLgImpl (DigitsT Digits, int16_t Scale)
 Implementation of getLg() and friends. More...
 
template<class DigitsT >
int32_t getLg (DigitsT Digits, int16_t Scale)
 Get the lg (rounded) of a scaled number. More...
 
template<class DigitsT >
int32_t getLgFloor (DigitsT Digits, int16_t Scale)
 Get the lg floor of a scaled number. More...
 
template<class DigitsT >
int32_t getLgCeiling (DigitsT Digits, int16_t Scale)
 Get the lg ceiling of a scaled number. More...
 
int compareImpl (uint64_t L, uint64_t R, int ScaleDiff)
 Implementation for comparing scaled numbers. More...
 
template<class DigitsT >
int compare (DigitsT LDigits, int16_t LScale, DigitsT RDigits, int16_t RScale)
 Compare two scaled numbers. More...
 
template<class DigitsT >
int16_t matchScales (DigitsT &LDigits, int16_t &LScale, DigitsT &RDigits, int16_t &RScale)
 Match scales of two numbers. More...
 
template<class DigitsT >
std::pair< DigitsT, int16_t > getSum (DigitsT LDigits, int16_t LScale, DigitsT RDigits, int16_t RScale)
 Get the sum of two scaled numbers. More...
 
std::pair< uint32_t, int16_t > getSum32 (uint32_t LDigits, int16_t LScale, uint32_t RDigits, int16_t RScale)
 Convenience helper for 32-bit sum. More...
 
std::pair< uint64_t, int16_t > getSum64 (uint64_t LDigits, int16_t LScale, uint64_t RDigits, int16_t RScale)
 Convenience helper for 64-bit sum. More...
 
template<class DigitsT >
std::pair< DigitsT, int16_t > getDifference (DigitsT LDigits, int16_t LScale, DigitsT RDigits, int16_t RScale)
 Get the difference of two scaled numbers. More...
 
std::pair< uint32_t, int16_t > getDifference32 (uint32_t LDigits, int16_t LScale, uint32_t RDigits, int16_t RScale)
 Convenience helper for 32-bit difference. More...
 
std::pair< uint64_t, int16_t > getDifference64 (uint64_t LDigits, int16_t LScale, uint64_t RDigits, int16_t RScale)
 Convenience helper for 64-bit difference. More...
 

Variables

const int32_t MaxScale = 16383
 Maximum scale; same as APFloat for easy debug printing. More...
 
const int32_t MinScale = -16382
 Maximum scale; same as APFloat for easy debug printing. More...
 

Function Documentation

◆ compare()

template<class DigitsT >
int llvm::ScaledNumbers::compare ( DigitsT  LDigits,
int16_t  LScale,
DigitsT  RDigits,
int16_t  RScale 
)

◆ compareImpl()

int llvm::ScaledNumbers::compareImpl ( uint64_t  L,
uint64_t  R,
int  ScaleDiff 
)

Implementation for comparing scaled numbers.

Compare two 64-bit numbers with different scales. Given that the scale of L is higher than that of R by ScaleDiff, compare them. Return -1, 1, and 0 for less than, greater than, and equal, respectively.

Precondition
0 <= ScaleDiff < 64.

Definition at line 125 of file ScaledNumber.cpp.

References assert().

Referenced by compare(), and getLgCeiling().

◆ divide32()

std::pair< uint32_t, int16_t > llvm::ScaledNumbers::divide32 ( uint32_t  Dividend,
uint32_t  Divisor 
)

Divide two 32-bit integers to create a 32-bit scaled number.

Implemented with one 64-bit integer divide/remainder pair.

Precondition
Dividend and Divisor are non-zero.

Definition at line 58 of file ScaledNumber.cpp.

References assert(), llvm::countLeadingZeros(), and getHalf().

Referenced by getProduct64(), and getQuotient().

◆ divide64()

std::pair< uint64_t, int16_t > llvm::ScaledNumbers::divide64 ( uint64_t  Dividend,
uint64_t  Divisor 
)

Divide two 64-bit integers to create a 64-bit scaled number.

Implemented with long division.

Precondition
Dividend and Divisor are non-zero.

Definition at line 81 of file ScaledNumber.cpp.

References assert(), llvm::countLeadingZeros(), llvm::countTrailingZeros(), getHalf(), and getRounded().

Referenced by getProduct64(), and getQuotient().

◆ getAdjusted()

template<class DigitsT >
std::pair<DigitsT, int16_t> llvm::ScaledNumbers::getAdjusted ( uint64_t  Digits,
int16_t  Scale = 0 
)
inline

Adjust a 64-bit scaled number down to the appropriate width.

Precondition
Adding 64 to Scale will not overflow INT16_MAX.

Definition at line 80 of file ScaledNumber.h.

References llvm::countLeadingZeros(), and llvm::max().

◆ getAdjusted32()

std::pair<uint32_t, int16_t> llvm::ScaledNumbers::getAdjusted32 ( uint64_t  Digits,
int16_t  Scale = 0 
)
inline

Convenience helper for adjusting to 32 bits.

Definition at line 95 of file ScaledNumber.h.

◆ getAdjusted64()

std::pair<uint64_t, int16_t> llvm::ScaledNumbers::getAdjusted64 ( uint64_t  Digits,
int16_t  Scale = 0 
)
inline

Convenience helper for adjusting to 64 bits.

Definition at line 101 of file ScaledNumber.h.

References multiply64().

◆ getDifference()

template<class DigitsT >
std::pair<DigitsT, int16_t> llvm::ScaledNumbers::getDifference ( DigitsT  LDigits,
int16_t  LScale,
DigitsT  RDigits,
int16_t  RScale 
)

Get the difference of two scaled numbers.

Get LHS minus RHS with as much precision as possible.

Returns (0, 0) if the RHS is larger than the LHS.

Definition at line 373 of file ScaledNumber.h.

References compare(), getLgFloor(), matchScales(), and llvm::max().

Referenced by getDifference32(), getDifference64(), and llvm::ScaledNumber< uint64_t >::operator-=().

◆ getDifference32()

std::pair<uint32_t, int16_t> llvm::ScaledNumbers::getDifference32 ( uint32_t  LDigits,
int16_t  LScale,
uint32_t  RDigits,
int16_t  RScale 
)
inline

Convenience helper for 32-bit difference.

Definition at line 399 of file ScaledNumber.h.

References getDifference().

◆ getDifference64()

std::pair<uint64_t, int16_t> llvm::ScaledNumbers::getDifference64 ( uint64_t  LDigits,
int16_t  LScale,
uint64_t  RDigits,
int16_t  RScale 
)
inline

Convenience helper for 64-bit difference.

Definition at line 407 of file ScaledNumber.h.

References getDifference().

◆ getLg()

template<class DigitsT >
int32_t llvm::ScaledNumbers::getLg ( DigitsT  Digits,
int16_t  Scale 
)

Get the lg (rounded) of a scaled number.

Get the lg of Digits*2^Scale.

Returns INT32_MIN when Digits is zero.

Definition at line 214 of file ScaledNumber.h.

References getLgImpl().

Referenced by llvm::ScaledNumber< uint64_t >::lg().

◆ getLgCeiling()

template<class DigitsT >
int32_t llvm::ScaledNumbers::getLgCeiling ( DigitsT  Digits,
int16_t  Scale 
)

Get the lg ceiling of a scaled number.

Get the ceiling of the lg of Digits*2^Scale.

Returns INT32_MIN when Digits is zero.

Definition at line 233 of file ScaledNumber.h.

References compareImpl(), and getLgImpl().

Referenced by llvm::ScaledNumber< uint64_t >::lgCeiling().

◆ getLgFloor()

template<class DigitsT >
int32_t llvm::ScaledNumbers::getLgFloor ( DigitsT  Digits,
int16_t  Scale 
)

Get the lg floor of a scaled number.

Get the floor of the lg of Digits*2^Scale.

Returns INT32_MIN when Digits is zero.

Definition at line 223 of file ScaledNumber.h.

References getLgImpl().

Referenced by compare(), getDifference(), and llvm::ScaledNumber< uint64_t >::lgFloor().

◆ getLgImpl()

template<class DigitsT >
std::pair<int32_t, int> llvm::ScaledNumbers::getLgImpl ( DigitsT  Digits,
int16_t  Scale 
)
inline

Implementation of getLg() and friends.

Returns the rounded lg of Digits*2^Scale and an int specifying whether this was rounded up (1), down (-1), or exact (0).

Returns INT32_MIN when Digits is zero.

Definition at line 189 of file ScaledNumber.h.

References assert(), and llvm::countLeadingZeros().

Referenced by getLg(), getLgCeiling(), and getLgFloor().

◆ getProduct()

template<class DigitsT >
std::pair<DigitsT, int16_t> llvm::ScaledNumbers::getProduct ( DigitsT  LHS,
DigitsT  RHS 
)
inline

Multiply two 32-bit integers to create a 32-bit scaled number.

Implemented with one 64-bit integer multiply.

Definition at line 115 of file ScaledNumber.h.

References multiply64().

Referenced by getProduct32(), getProduct64(), llvm::ScaledNumber< uint64_t >::inverse(), and llvm::ScaledNumber< uint64_t >::operator*=().

◆ getProduct32()

std::pair<uint32_t, int16_t> llvm::ScaledNumbers::getProduct32 ( uint32_t  LHS,
uint32_t  RHS 
)
inline

Convenience helper for 32-bit product.

Definition at line 125 of file ScaledNumber.h.

References getProduct().

◆ getProduct64()

std::pair<uint64_t, int16_t> llvm::ScaledNumbers::getProduct64 ( uint64_t  LHS,
uint64_t  RHS 
)
inline

Convenience helper for 64-bit product.

Definition at line 130 of file ScaledNumber.h.

References divide32(), divide64(), and getProduct().

◆ getQuotient()

template<class DigitsT >
std::pair<DigitsT, int16_t> llvm::ScaledNumbers::getQuotient ( DigitsT  Dividend,
DigitsT  Divisor 
)

Divide two 32-bit numbers to create a 32-bit scaled number.

Implemented with one 64-bit integer divide/remainder pair.

Returns (DigitsT_MAX, MaxScale) for divide-by-zero (0 for 0/0).

Definition at line 154 of file ScaledNumber.h.

References divide32(), divide64(), and llvm::max().

Referenced by llvm::ScaledNumber< uint64_t >::getFraction(), getQuotient32(), getQuotient64(), llvm::ScaledNumber< uint64_t >::inverse(), and llvm::ScaledNumber< uint64_t >::operator/=().

◆ getQuotient32()

std::pair<uint32_t, int16_t> llvm::ScaledNumbers::getQuotient32 ( uint32_t  Dividend,
uint32_t  Divisor 
)
inline

Convenience helper for 32-bit quotient.

Definition at line 171 of file ScaledNumber.h.

References getQuotient().

◆ getQuotient64()

std::pair<uint64_t, int16_t> llvm::ScaledNumbers::getQuotient64 ( uint64_t  Dividend,
uint64_t  Divisor 
)
inline

Convenience helper for 64-bit quotient.

Definition at line 177 of file ScaledNumber.h.

References getQuotient().

◆ getRounded()

template<class DigitsT >
std::pair<DigitsT, int16_t> llvm::ScaledNumbers::getRounded ( DigitsT  Digits,
int16_t  Scale,
bool  ShouldRound 
)
inline

Conditionally round up a scaled number.

Given Digits and Scale, round up iff ShouldRound is true. Always returns Scale unless there's an overflow, in which case it returns 1+Scale.

Precondition
adding 1 to Scale will not overflow INT16_MAX.

Definition at line 53 of file ScaledNumber.h.

Referenced by divide64(), getRounded32(), getRounded64(), llvm::ScaledNumber< uint64_t >::inverse(), and multiply64().

◆ getRounded32()

std::pair<uint32_t, int16_t> llvm::ScaledNumbers::getRounded32 ( uint32_t  Digits,
int16_t  Scale,
bool  ShouldRound 
)
inline

Convenience helper for 32-bit rounding.

Definition at line 65 of file ScaledNumber.h.

References getRounded().

◆ getRounded64()

std::pair<uint64_t, int16_t> llvm::ScaledNumbers::getRounded64 ( uint64_t  Digits,
int16_t  Scale,
bool  ShouldRound 
)
inline

Convenience helper for 64-bit rounding.

Definition at line 71 of file ScaledNumber.h.

References getRounded().

◆ getSum()

template<class DigitsT >
std::pair<DigitsT, int16_t> llvm::ScaledNumbers::getSum ( DigitsT  LDigits,
int16_t  LScale,
DigitsT  RDigits,
int16_t  RScale 
)

Get the sum of two scaled numbers.

Get the sum of two scaled numbers with as much precision as possible.

Precondition
Adding 1 to LScale (or RScale) will not overflow INT16_MAX.

Definition at line 333 of file ScaledNumber.h.

References assert(), and matchScales().

Referenced by getSum32(), getSum64(), and llvm::ScaledNumber< uint64_t >::operator+=().

◆ getSum32()

std::pair<uint32_t, int16_t> llvm::ScaledNumbers::getSum32 ( uint32_t  LDigits,
int16_t  LScale,
uint32_t  RDigits,
int16_t  RScale 
)
inline

Convenience helper for 32-bit sum.

Definition at line 356 of file ScaledNumber.h.

References getSum().

◆ getSum64()

std::pair<uint64_t, int16_t> llvm::ScaledNumbers::getSum64 ( uint64_t  LDigits,
int16_t  LScale,
uint64_t  RDigits,
int16_t  RScale 
)
inline

Convenience helper for 64-bit sum.

Definition at line 362 of file ScaledNumber.h.

References getSum().

◆ getWidth()

template<class DigitsT >
int llvm::ScaledNumbers::getWidth ( )
inline

Get the width of a number.

Definition at line 43 of file ScaledNumber.h.

Referenced by llvm::InterleaveGroup::addMetadata().

◆ matchScales()

template<class DigitsT >
int16_t llvm::ScaledNumbers::matchScales ( DigitsT &  LDigits,
int16_t &  LScale,
DigitsT &  RDigits,
int16_t &  RScale 
)

Match scales of two numbers.

Given two scaled numbers, match up their scales. Change the digits and scales in place. Shift the digits as necessary to form equivalent numbers, losing precision only when necessary.

If the output value of LDigits (RDigits) is 0, the output value of LScale (RScale) is unspecified.

As a convenience, returns the matching scale. If the output value of one number is zero, returns the scale of the other. If both are zero, which scale is returned is unspecified.

Definition at line 287 of file ScaledNumber.h.

References assert(), and llvm::countLeadingZeros().

Referenced by getDifference(), getSum(), and llvm::ScaledNumber< uint64_t >::operator>>=().

◆ multiply64()

std::pair< uint64_t, int16_t > llvm::ScaledNumbers::multiply64 ( uint64_t  LHS,
uint64_t  RHS 
)

Multiply two 64-bit integers to create a 64-bit scaled number.

Implemented with four 64-bit integer multiplies.

Definition at line 23 of file ScaledNumber.cpp.

References llvm::countLeadingZeros(), getRounded(), getU(), llvm::Lower, N, and llvm::Upper.

Referenced by getAdjusted64(), and getProduct().

Variable Documentation

◆ MaxScale

const int32_t llvm::ScaledNumbers::MaxScale = 16383

◆ MinScale

const int32_t llvm::ScaledNumbers::MinScale = -16382

Maximum scale; same as APFloat for easy debug printing.

Definition at line 40 of file ScaledNumber.h.

Referenced by llvm::ScaledNumber< uint64_t >::inverse(), llvm::ScaledNumber< uint64_t >::operator/=(), and toStringAPFloat().