LLVM 19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
llvm::APFixedPoint Class Reference

The APFixedPoint class works similarly to APInt/APSInt in that it is a functional replacement for a scaled integer. More...

#include "llvm/ADT/APFixedPoint.h"

Public Member Functions

 APFixedPoint (const APInt &Val, const FixedPointSemantics &Sema)
 
 APFixedPoint (uint64_t Val, const FixedPointSemantics &Sema)
 
 APFixedPoint (const FixedPointSemantics &Sema)
 
APSInt getValue () const
 
unsigned getWidth () const
 
unsigned getScale () const
 
int getLsbWeight () const
 
int getMsbWeight () const
 
bool isSaturated () const
 
bool isSigned () const
 
bool hasPadding () const
 
FixedPointSemantics getSemantics () const
 
bool getBoolValue () const
 
APFixedPoint convert (const FixedPointSemantics &DstSema, bool *Overflow=nullptr) const
 
APFixedPoint add (const APFixedPoint &Other, bool *Overflow=nullptr) const
 
APFixedPoint sub (const APFixedPoint &Other, bool *Overflow=nullptr) const
 
APFixedPoint mul (const APFixedPoint &Other, bool *Overflow=nullptr) const
 
APFixedPoint div (const APFixedPoint &Other, bool *Overflow=nullptr) const
 
APFixedPoint shl (unsigned Amt, bool *Overflow=nullptr) const
 
APFixedPoint shr (unsigned Amt, bool *Overflow=nullptr) const
 
APFixedPoint negate (bool *Overflow=nullptr) const
 Perform a unary negation (-X) on this fixed point type, taking into account saturation if applicable.
 
APSInt getIntPart () const
 Return the integral part of this fixed point number, rounded towards zero.
 
APSInt convertToInt (unsigned DstWidth, bool DstSign, bool *Overflow=nullptr) const
 Return the integral part of this fixed point number, rounded towards zero.
 
APFloat convertToFloat (const fltSemantics &FloatSema) const
 Convert this fixed point number to a floating point value with the provided semantics.
 
void toString (SmallVectorImpl< char > &Str) const
 
std::string toString () const
 
void print (raw_ostream &) const
 
void dump () const
 
int compare (const APFixedPoint &Other) const
 
bool operator== (const APFixedPoint &Other) const
 
bool operator!= (const APFixedPoint &Other) const
 
bool operator> (const APFixedPoint &Other) const
 
bool operator< (const APFixedPoint &Other) const
 
bool operator>= (const APFixedPoint &Other) const
 
bool operator<= (const APFixedPoint &Other) const
 

Static Public Member Functions

static APFixedPoint getMax (const FixedPointSemantics &Sema)
 
static APFixedPoint getMin (const FixedPointSemantics &Sema)
 
static APFixedPoint getEpsilon (const FixedPointSemantics &Sema)
 
static const fltSemanticspromoteFloatSemantics (const fltSemantics *S)
 Given a floating point semantic, return the next floating point semantic with a larger exponent and larger or equal mantissa.
 
static APFixedPoint getFromIntValue (const APSInt &Value, const FixedPointSemantics &DstFXSema, bool *Overflow=nullptr)
 Create an APFixedPoint with a value equal to that of the provided integer, and in the same semantics as the provided target semantics.
 
static APFixedPoint getFromFloatValue (const APFloat &Value, const FixedPointSemantics &DstFXSema, bool *Overflow=nullptr)
 Create an APFixedPoint with a value equal to that of the provided floating point value, in the provided target semantics.
 

Detailed Description

The APFixedPoint class works similarly to APInt/APSInt in that it is a functional replacement for a scaled integer.

It supports a wide range of semantics including the one used by fixed point types proposed in ISO/IEC JTC1 SC22 WG14 N1169. The class carries the value and semantics of a fixed point, and provides different operations that would normally be performed on fixed point types.

Definition at line 154 of file APFixedPoint.h.

Constructor & Destructor Documentation

◆ APFixedPoint() [1/3]

llvm::APFixedPoint::APFixedPoint ( const APInt Val,
const FixedPointSemantics Sema 
)
inline

◆ APFixedPoint() [2/3]

llvm::APFixedPoint::APFixedPoint ( uint64_t  Val,
const FixedPointSemantics Sema 
)
inline

Definition at line 162 of file APFixedPoint.h.

◆ APFixedPoint() [3/3]

llvm::APFixedPoint::APFixedPoint ( const FixedPointSemantics Sema)
inline

Definition at line 166 of file APFixedPoint.h.

Member Function Documentation

◆ add()

APFixedPoint llvm::APFixedPoint::add ( const APFixedPoint Other,
bool Overflow = nullptr 
) const

◆ compare()

int llvm::APFixedPoint::compare ( const APFixedPoint Other) const

◆ convert()

APFixedPoint llvm::APFixedPoint::convert ( const FixedPointSemantics DstSema,
bool Overflow = nullptr 
) const

◆ convertToFloat()

APFloat llvm::APFixedPoint::convertToFloat ( const fltSemantics FloatSema) const

◆ convertToInt()

APSInt llvm::APFixedPoint::convertToInt ( unsigned  DstWidth,
bool  DstSign,
bool Overflow = nullptr 
) const

Return the integral part of this fixed point number, rounded towards zero.

The value is stored into an APSInt with the provided width and sign. If the overflow parameter is provided, and the integral value is not able to be fully stored in the provided width and sign, the overflow parameter is set to true.

Definition at line 452 of file APFixedPoint.cpp.

References llvm::APSInt::extend(), getIntPart(), llvm::APSInt::getMaxValue(), llvm::APSInt::getMinValue(), and getWidth().

◆ div()

APFixedPoint llvm::APFixedPoint::div ( const APFixedPoint Other,
bool Overflow = nullptr 
) const

◆ dump()

LLVM_DUMP_METHOD void llvm::APFixedPoint::dump ( ) const

Definition at line 432 of file APFixedPoint.cpp.

References llvm::errs(), and print().

◆ getBoolValue()

bool llvm::APFixedPoint::getBoolValue ( ) const
inline

Definition at line 178 of file APFixedPoint.h.

References llvm::APInt::getBoolValue().

◆ getEpsilon()

APFixedPoint llvm::APFixedPoint::getEpsilon ( const FixedPointSemantics Sema)
static

◆ getFromFloatValue()

APFixedPoint llvm::APFixedPoint::getFromFloatValue ( const APFloat Value,
const FixedPointSemantics DstFXSema,
bool Overflow = nullptr 
)
static

Create an APFixedPoint with a value equal to that of the provided floating point value, in the provided target semantics.

If the value is not able to fit in the specified fixed point semantics and the overflow parameter is specified, it is set to true. For NaN, the Overflow flag is always set. For +inf and -inf, if the semantic is saturating, the value saturates. Otherwise, the Overflow flag is set.

Definition at line 538 of file APFixedPoint.cpp.

References llvm::APFloat::convert(), convertToFloat(), llvm::APFloat::convertToInteger(), llvm::FixedPointSemantics::fitsInFloatSemantics(), llvm::FixedPointSemantics::getLsbWeight(), getMax(), getMin(), getValue(), llvm::FixedPointSemantics::getWidth(), llvm::FixedPointSemantics::isSaturated(), llvm::FixedPointSemantics::isSigned(), llvm::APFloat::multiply(), promoteFloatSemantics(), llvm::APFloatBase::rmTowardZero, and llvm::APFloat::roundToIntegral().

◆ getFromIntValue()

APFixedPoint llvm::APFixedPoint::getFromIntValue ( const APSInt Value,
const FixedPointSemantics DstFXSema,
bool Overflow = nullptr 
)
static

Create an APFixedPoint with a value equal to that of the provided integer, and in the same semantics as the provided target semantics.

If the value is not able to fit in the specified fixed point semantics, and the overflow parameter is provided, it is set to true.

Definition at line 529 of file APFixedPoint.cpp.

References convert(), and llvm::FixedPointSemantics::GetIntegerSemantics().

◆ getIntPart()

APSInt llvm::APFixedPoint::getIntPart ( ) const
inline

Return the integral part of this fixed point number, rounded towards zero.

(-2.5k -> -2)

Definition at line 212 of file APFixedPoint.h.

References llvm::APSInt::extend(), getLsbWeight(), getMsbWeight(), getWidth(), llvm::APInt::getZero(), llvm::APSInt::isUnsigned(), and llvm::APSInt::relativeShl().

Referenced by convertToInt().

◆ getLsbWeight()

int llvm::APFixedPoint::getLsbWeight ( ) const
inline

Definition at line 171 of file APFixedPoint.h.

References llvm::FixedPointSemantics::getLsbWeight().

Referenced by compare(), convert(), getIntPart(), and toString().

◆ getMax()

APFixedPoint llvm::APFixedPoint::getMax ( const FixedPointSemantics Sema)
static

◆ getMin()

APFixedPoint llvm::APFixedPoint::getMin ( const FixedPointSemantics Sema)
static

◆ getMsbWeight()

int llvm::APFixedPoint::getMsbWeight ( ) const
inline

Definition at line 172 of file APFixedPoint.h.

References llvm::FixedPointSemantics::getMsbWeight().

Referenced by compare(), and getIntPart().

◆ getScale()

unsigned llvm::APFixedPoint::getScale ( ) const
inline

Definition at line 170 of file APFixedPoint.h.

References llvm::FixedPointSemantics::getScale().

◆ getSemantics()

FixedPointSemantics llvm::APFixedPoint::getSemantics ( ) const
inline

Definition at line 176 of file APFixedPoint.h.

Referenced by llvm::hash_value().

◆ getValue()

APSInt llvm::APFixedPoint::getValue ( ) const
inline

◆ getWidth()

unsigned llvm::APFixedPoint::getWidth ( ) const
inline

Definition at line 169 of file APFixedPoint.h.

References llvm::FixedPointSemantics::getWidth().

Referenced by convertToInt(), getIntPart(), and toString().

◆ hasPadding()

bool llvm::APFixedPoint::hasPadding ( ) const
inline

Definition at line 175 of file APFixedPoint.h.

References llvm::FixedPointSemantics::hasUnsignedPadding().

◆ isSaturated()

bool llvm::APFixedPoint::isSaturated ( ) const
inline

Definition at line 173 of file APFixedPoint.h.

References llvm::FixedPointSemantics::isSaturated().

Referenced by negate().

◆ isSigned()

bool llvm::APFixedPoint::isSigned ( ) const
inline

Definition at line 174 of file APFixedPoint.h.

References llvm::FixedPointSemantics::isSigned().

Referenced by negate().

◆ mul()

APFixedPoint llvm::APFixedPoint::mul ( const APFixedPoint Other,
bool Overflow = nullptr 
) const

◆ negate()

APFixedPoint llvm::APFixedPoint::negate ( bool Overflow = nullptr) const

Perform a unary negation (-X) on this fixed point type, taking into account saturation if applicable.

Definition at line 434 of file APFixedPoint.cpp.

References getMax(), llvm::APInt::isMinSignedValue(), isSaturated(), and isSigned().

◆ operator!=()

bool llvm::APFixedPoint::operator!= ( const APFixedPoint Other) const
inline

Definition at line 249 of file APFixedPoint.h.

References compare(), and llvm::Other.

◆ operator<()

bool llvm::APFixedPoint::operator< ( const APFixedPoint Other) const
inline

Definition at line 253 of file APFixedPoint.h.

References compare(), and llvm::Other.

◆ operator<=()

bool llvm::APFixedPoint::operator<= ( const APFixedPoint Other) const
inline

Definition at line 257 of file APFixedPoint.h.

References compare(), and llvm::Other.

◆ operator==()

bool llvm::APFixedPoint::operator== ( const APFixedPoint Other) const
inline

Definition at line 246 of file APFixedPoint.h.

References compare(), and llvm::Other.

◆ operator>()

bool llvm::APFixedPoint::operator> ( const APFixedPoint Other) const
inline

Definition at line 252 of file APFixedPoint.h.

References compare(), and llvm::Other.

◆ operator>=()

bool llvm::APFixedPoint::operator>= ( const APFixedPoint Other) const
inline

Definition at line 254 of file APFixedPoint.h.

References compare(), and llvm::Other.

◆ print()

void llvm::APFixedPoint::print ( raw_ostream OS) const

Definition at line 427 of file APFixedPoint.cpp.

References OS, llvm::FixedPointSemantics::print(), and toString().

Referenced by dump().

◆ promoteFloatSemantics()

const fltSemantics * llvm::APFixedPoint::promoteFloatSemantics ( const fltSemantics S)
static

Given a floating point semantic, return the next floating point semantic with a larger exponent and larger or equal mantissa.

Definition at line 481 of file APFixedPoint.cpp.

References llvm::APFloatBase::BFloat(), llvm::APFloatBase::IEEEdouble(), llvm::APFloatBase::IEEEhalf(), llvm::APFloatBase::IEEEquad(), llvm::APFloatBase::IEEEsingle(), and llvm_unreachable.

Referenced by convertToFloat(), and getFromFloatValue().

◆ shl()

APFixedPoint llvm::APFixedPoint::shl ( unsigned  Amt,
bool Overflow = nullptr 
) const

◆ shr()

APFixedPoint llvm::APFixedPoint::shr ( unsigned  Amt,
bool Overflow = nullptr 
) const
inline

Definition at line 199 of file APFixedPoint.h.

◆ sub()

APFixedPoint llvm::APFixedPoint::sub ( const APFixedPoint Other,
bool Overflow = nullptr 
) const

◆ toString() [1/2]

std::string llvm::APFixedPoint::toString ( ) const
inline

Definition at line 235 of file APFixedPoint.h.

References toString().

Referenced by print(), and toString().

◆ toString() [2/2]

void llvm::APFixedPoint::toString ( SmallVectorImpl< char > &  Str) const

The documentation for this class was generated from the following files: