LLVM 22.0.0git
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
LLVM_ABI APFixedPoint convert (const FixedPointSemantics &DstSema, bool *Overflow=nullptr) const
LLVM_ABI APFixedPoint add (const APFixedPoint &Other, bool *Overflow=nullptr) const
LLVM_ABI APFixedPoint sub (const APFixedPoint &Other, bool *Overflow=nullptr) const
LLVM_ABI APFixedPoint mul (const APFixedPoint &Other, bool *Overflow=nullptr) const
LLVM_ABI APFixedPoint div (const APFixedPoint &Other, bool *Overflow=nullptr) const
LLVM_ABI APFixedPoint shl (unsigned Amt, bool *Overflow=nullptr) const
APFixedPoint shr (unsigned Amt, bool *Overflow=nullptr) const
LLVM_ABI 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.
LLVM_ABI APSInt convertToInt (unsigned DstWidth, bool DstSign, bool *Overflow=nullptr) const
 Return the integral part of this fixed point number, rounded towards zero.
LLVM_ABI APFloat convertToFloat (const fltSemantics &FloatSema) const
 Convert this fixed point number to a floating point value with the provided semantics.
LLVM_ABI void toString (SmallVectorImpl< char > &Str) const
std::string toString () const
LLVM_ABI void print (raw_ostream &) const
LLVM_DUMP_METHOD void dump () const
LLVM_ABI 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 LLVM_ABI APFixedPoint getMax (const FixedPointSemantics &Sema)
static LLVM_ABI APFixedPoint getMin (const FixedPointSemantics &Sema)
static LLVM_ABI APFixedPoint getEpsilon (const FixedPointSemantics &Sema)
static LLVM_ABI 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 LLVM_ABI 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 LLVM_ABI 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 163 of file APFixedPoint.h.

Constructor & Destructor Documentation

◆ APFixedPoint() [1/3]

◆ APFixedPoint() [2/3]

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

Definition at line 171 of file APFixedPoint.h.

References APFixedPoint(), getWidth(), and isSigned().

◆ APFixedPoint() [3/3]

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

Definition at line 177 of file APFixedPoint.h.

References APFixedPoint().

Member Function Documentation

◆ add()

◆ compare()

◆ convert()

◆ convertToFloat()

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

Convert this fixed point number to a floating point value with the provided semantics.

Definition at line 510 of file APFixedPoint.cpp.

References llvm::APFloat::convert(), Flt, promoteFloatSemantics(), llvm::APFloatBase::rmNearestTiesToEven, and llvm::APFloatBase::rmTowardZero.

Referenced by getFromFloatValue().

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

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

◆ div()

◆ dump()

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

Definition at line 448 of file APFixedPoint.cpp.

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

◆ getBoolValue()

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

Definition at line 189 of file APFixedPoint.h.

◆ getEpsilon()

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

Definition at line 142 of file APFixedPoint.cpp.

References APFixedPoint().

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

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

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

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

Referenced by convertToInt().

◆ getLsbWeight()

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

Definition at line 182 of file APFixedPoint.h.

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

◆ getMax()

◆ getMin()

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

◆ getMsbWeight()

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

Definition at line 183 of file APFixedPoint.h.

Referenced by compare(), and getIntPart().

◆ getScale()

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

Definition at line 181 of file APFixedPoint.h.

◆ getSemantics()

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

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

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

◆ hasPadding()

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

Definition at line 186 of file APFixedPoint.h.

◆ isSaturated()

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

Definition at line 184 of file APFixedPoint.h.

Referenced by negate().

◆ isSigned()

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

Definition at line 185 of file APFixedPoint.h.

Referenced by APFixedPoint(), APFixedPoint(), getMax(), and negate().

◆ mul()

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

References APFixedPoint(), getMax(), isSaturated(), and isSigned().

◆ operator!=()

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

Definition at line 267 of file APFixedPoint.h.

References APFixedPoint(), compare(), and llvm::Other.

◆ operator<()

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

Definition at line 271 of file APFixedPoint.h.

References APFixedPoint(), compare(), and llvm::Other.

◆ operator<=()

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

Definition at line 275 of file APFixedPoint.h.

References APFixedPoint(), compare(), and llvm::Other.

◆ operator==()

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

Definition at line 264 of file APFixedPoint.h.

References APFixedPoint(), compare(), and llvm::Other.

◆ operator>()

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

Definition at line 270 of file APFixedPoint.h.

References APFixedPoint(), compare(), and llvm::Other.

◆ operator>=()

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

Definition at line 272 of file APFixedPoint.h.

References APFixedPoint(), compare(), and llvm::Other.

◆ print()

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

Definition at line 441 of file APFixedPoint.cpp.

References 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 498 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 214 of file APFixedPoint.h.

References APFixedPoint().

◆ sub()

◆ toString() [1/2]

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

Definition at line 250 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: