LLVM API Documentation

Functions | Variables
llvm::ScaledNumbers Namespace Reference

Functions

template<class DigitsT >
int getWidth ()
 Get the width of a number.
template<class DigitsT >
std::pair< DigitsT, int16_t > getRounded (DigitsT Digits, int16_t Scale, bool ShouldRound)
 Conditionally round up a scaled number.
std::pair< uint32_t, int16_t > getRounded32 (uint32_t Digits, int16_t Scale, bool ShouldRound)
 Convenience helper for 32-bit rounding.
std::pair< uint64_t, int16_t > getRounded64 (uint64_t Digits, int16_t Scale, bool ShouldRound)
 Convenience helper for 64-bit rounding.
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.
std::pair< uint32_t, int16_t > getAdjusted32 (uint64_t Digits, int16_t Scale=0)
 Convenience helper for adjusting to 32 bits.
std::pair< uint64_t, int16_t > getAdjusted64 (uint64_t Digits, int16_t Scale=0)
 Convenience helper for adjusting to 64 bits.
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.
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.
std::pair< uint32_t, int16_t > getProduct32 (uint32_t LHS, uint32_t RHS)
 Convenience helper for 32-bit product.
std::pair< uint64_t, int16_t > getProduct64 (uint64_t LHS, uint64_t RHS)
 Convenience helper for 64-bit product.
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.
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.
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.
std::pair< uint32_t, int16_t > getQuotient32 (uint32_t Dividend, uint32_t Divisor)
 Convenience helper for 32-bit quotient.
std::pair< uint64_t, int16_t > getQuotient64 (uint64_t Dividend, uint64_t Divisor)
 Convenience helper for 64-bit quotient.
template<class DigitsT >
std::pair< int32_t, intgetLgImpl (DigitsT Digits, int16_t Scale)
 Implementation of getLg() and friends.
template<class DigitsT >
int32_t getLg (DigitsT Digits, int16_t Scale)
 Get the lg (rounded) of a scaled number.
template<class DigitsT >
int32_t getLgFloor (DigitsT Digits, int16_t Scale)
 Get the lg floor of a scaled number.
template<class DigitsT >
int32_t getLgCeiling (DigitsT Digits, int16_t Scale)
 Get the lg ceiling of a scaled number.
int compareImpl (uint64_t L, uint64_t R, int ScaleDiff)
 Implementation for comparing scaled numbers.
template<class DigitsT >
int compare (DigitsT LDigits, int16_t LScale, DigitsT RDigits, int16_t RScale)
 Compare two scaled numbers.
template<class DigitsT >
int16_t matchScales (DigitsT &LDigits, int16_t &LScale, DigitsT &RDigits, int16_t &RScale)
 Match scales of two numbers.
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.
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.
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.
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.
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.
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.

Variables

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

Function Documentation

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

Compare two scaled numbers.

Compare two scaled numbers. Returns 0 for equal, -1 for less than, and 1 for greater than.

Definition at line 253 of file ScaledNumber.h.

References compareImpl(), and getLgFloor().

Referenced by getDifference(), and llvm::APInt::tcDivide().

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 124 of file ScaledNumber.cpp.

Referenced by compare().

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 57 of file ScaledNumber.cpp.

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

Referenced by getQuotient().

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 80 of file ScaledNumber.cpp.

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

Referenced by getQuotient().

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 81 of file ScaledNumber.h.

References llvm::countLeadingZeros().

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 96 of file ScaledNumber.h.

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 102 of file ScaledNumber.h.

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 374 of file ScaledNumber.h.

References compare(), getLgFloor(), and matchScales().

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

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 400 of file ScaledNumber.h.

References getDifference().

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 408 of file ScaledNumber.h.

References getDifference().

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 215 of file ScaledNumber.h.

References getLgImpl().

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

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 234 of file ScaledNumber.h.

References getLgImpl().

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

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 224 of file ScaledNumber.h.

References getLgImpl().

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

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 190 of file ScaledNumber.h.

References llvm::countLeadingZeros().

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

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 116 of file ScaledNumber.h.

References multiply64().

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

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 126 of file ScaledNumber.h.

References getProduct().

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 131 of file ScaledNumber.h.

References getProduct().

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 155 of file ScaledNumber.h.

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

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

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 172 of file ScaledNumber.h.

References getQuotient().

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 178 of file ScaledNumber.h.

References getQuotient().

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 54 of file ScaledNumber.h.

Referenced by divide64(), getRounded32(), getRounded64(), and multiply64().

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 66 of file ScaledNumber.h.

References getRounded().

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 72 of file ScaledNumber.h.

References getRounded().

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 334 of file ScaledNumber.h.

References matchScales().

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

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 357 of file ScaledNumber.h.

References getSum().

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 363 of file ScaledNumber.h.

References getSum().

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

Get the width of a number.

Definition at line 44 of file ScaledNumber.h.

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 unspecifed.

Definition at line 288 of file ScaledNumber.h.

References llvm::countLeadingZeros().

Referenced by getDifference(), and getSum().

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 22 of file ScaledNumber.cpp.

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

Referenced by getProduct().


Variable Documentation

Maximum scale; same as APFloat for easy debug printing.

Definition at line 38 of file ScaledNumber.h.

Referenced by llvm::ScaledNumber< uint64_t >::getLargest(), getQuotient(), llvm::ScaledNumber< uint64_t >::operator+=(), and toStringAPFloat().

Maximum scale; same as APFloat for easy debug printing.

Definition at line 41 of file ScaledNumber.h.

Referenced by toStringAPFloat().