LLVM  14.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
 
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. More...
 
APSInt getIntPart () const
 Return the integral part of this fixed point number, rounded towards zero. More...
 
APSInt convertToInt (unsigned DstWidth, bool DstSign, bool *Overflow=nullptr) const
 Return the integral part of this fixed point number, rounded towards zero. More...
 
APFloat convertToFloat (const fltSemantics &FloatSema) const
 Convert this fixed point number to a floating point value with the provided semantics. More...
 
void toString (SmallVectorImpl< char > &Str) const
 
std::string toString () 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 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. More...
 
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. More...
 
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. More...
 

Detailed Description

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

It is meant to replicate the fixed point types proposed in ISO/IEC JTC1 SC22 WG14 N1169. The class carries info about the fixed point type's width, sign, scale, and saturation, and provides different operations that would normally be performed on fixed point types.

Definition at line 100 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 108 of file APFixedPoint.h.

◆ APFixedPoint() [3/3]

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

Definition at line 112 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 415 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

◆ getBoolValue()

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

Definition at line 122 of file APFixedPoint.h.

References llvm::APInt::getBoolValue().

◆ 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 501 of file APFixedPoint.cpp.

References APFixedPoint(), llvm::lltok::APFloat, llvm::APFloat::convert(), convertToFloat(), llvm::APFloat::convertToInteger(), llvm::FixedPointSemantics::fitsInFloatSemantics(), getMax(), getMin(), llvm::FixedPointSemantics::getScale(), getValue(), llvm::FixedPointSemantics::getWidth(), llvm::FixedPointSemantics::isSaturated(), llvm::FixedPointSemantics::isSigned(), llvm::APFloat::multiply(), promoteFloatSemantics(), llvm::AArch64::RM, 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 492 of file APFixedPoint.cpp.

References APFixedPoint(), 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 156 of file APFixedPoint.h.

References getScale().

Referenced by convertToInt().

◆ getMax()

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

◆ getMin()

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

◆ getScale()

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

Definition at line 116 of file APFixedPoint.h.

References llvm::FixedPointSemantics::getScale().

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

◆ getSemantics()

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

Definition at line 120 of file APFixedPoint.h.

◆ getValue()

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

◆ getWidth()

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

Definition at line 115 of file APFixedPoint.h.

References llvm::FixedPointSemantics::getWidth().

Referenced by convertToInt().

◆ hasPadding()

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

Definition at line 119 of file APFixedPoint.h.

References llvm::FixedPointSemantics::hasUnsignedPadding().

◆ isSaturated()

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

Definition at line 117 of file APFixedPoint.h.

References llvm::FixedPointSemantics::isSaturated().

Referenced by negate().

◆ isSigned()

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

Definition at line 118 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 397 of file APFixedPoint.cpp.

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

◆ operator!=()

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

Definition at line 187 of file APFixedPoint.h.

References compare(), and Other.

◆ operator<()

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

Definition at line 191 of file APFixedPoint.h.

References compare(), and Other.

◆ operator<=()

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

Definition at line 195 of file APFixedPoint.h.

References compare(), and Other.

◆ operator==()

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

Definition at line 184 of file APFixedPoint.h.

References compare(), and Other.

◆ operator>()

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

Definition at line 190 of file APFixedPoint.h.

References compare(), and Other.

◆ operator>=()

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

Definition at line 192 of file APFixedPoint.h.

References compare(), and Other.

◆ 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 444 of file APFixedPoint.cpp.

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

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 143 of file APFixedPoint.h.

References APFixedPoint().

◆ 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 176 of file APFixedPoint.h.

References S.

◆ toString() [2/2]

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

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