LLVM 19.0.0git
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, int > getLgImpl (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

◆ compare()

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

References compareImpl(), and getLgFloor().

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

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

References assert().

Referenced by compare().

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

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

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

References assert(), llvm::countl_zero(), llvm::countr_zero(), getHalf(), and getRounded().

Referenced by 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 79 of file ScaledNumber.h.

References llvm::bit_width().

◆ 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 94 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 100 of file ScaledNumber.h.

◆ 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(), and matchScales().

Referenced by getDifference32(), getDifference64(), and llvm::ScaledNumber< DigitsT >::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< DigitsT >::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 getLgImpl().

Referenced by llvm::ScaledNumber< DigitsT >::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< DigitsT >::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 188 of file ScaledNumber.h.

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

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

References LHS, multiply64(), and RHS.

Referenced by getProduct32(), and getProduct64().

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

References getProduct(), LHS, and RHS.

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

References getProduct(), LHS, and RHS.

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

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

Referenced by getQuotient32(), and getQuotient64().

◆ 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 170 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 176 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 52 of file ScaledNumber.h.

Referenced by divide64(), getRounded32(), getRounded64(), 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 64 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 70 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< DigitsT >::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 42 of file ScaledNumber.h.

◆ 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(), llvm::countl_zero(), and matchScales().

Referenced by getDifference(), getSum(), and matchScales().

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

References llvm::countl_zero(), getRounded(), LHS, llvm::Lower, N, RHS, and llvm::Upper.

Referenced by getProduct().

Variable Documentation

◆ MaxScale

const int32_t llvm::ScaledNumbers::MaxScale = 16383

Maximum scale; same as APFloat for easy debug printing.

Definition at line 36 of file ScaledNumber.h.

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

◆ MinScale

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

Maximum scale; same as APFloat for easy debug printing.

Definition at line 39 of file ScaledNumber.h.

Referenced by toStringAPFloat().