clang  10.0.0svn
Public Member Functions | Static Public Member Functions | List of all members
clang::APFixedPoint Class Reference

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

#include "clang/Basic/FixedPoint.h"

Public Member Functions

 APFixedPoint (const llvm::APInt &Val, const FixedPointSemantics &Sema)
 
 APFixedPoint (uint64_t Val, const FixedPointSemantics &Sema)
 
 APFixedPoint (const FixedPointSemantics &Sema)
 
llvm::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 negate (bool *Overflow=nullptr) const
 Perform a unary negation (-X) on this fixed point type, taking into account saturation if applicable. More...
 
APFixedPoint shr (unsigned Amt) const
 
APFixedPoint shl (unsigned Amt) const
 
llvm::APSInt getIntPart () const
 Return the integral part of this fixed point number, rounded towards zero. More...
 
llvm::APSInt convertToInt (unsigned DstWidth, bool DstSign, bool *Overflow=nullptr) const
 Return the integral part of this fixed point number, rounded towards zero. More...
 
void toString (llvm::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 APFixedPoint getFromIntValue (const llvm::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...
 

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.

Semantically this does not represent any existing C type other than fixed point types and should eventually be moved to LLVM if fixed point types gain native IR support.

Definition at line 95 of file FixedPoint.h.

Constructor & Destructor Documentation

◆ APFixedPoint() [1/3]

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

Definition at line 97 of file FixedPoint.h.

References clang::FixedPointSemantics::getWidth().

Referenced by add(), convert(), getFromIntValue(), getMax(), getMin(), and negate().

◆ APFixedPoint() [2/3]

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

Definition at line 103 of file FixedPoint.h.

◆ APFixedPoint() [3/3]

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

Definition at line 108 of file FixedPoint.h.

Member Function Documentation

◆ add()

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

◆ compare()

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

Definition at line 63 of file FixedPoint.cpp.

References getScale(), getValue(), and max().

◆ convert()

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

◆ convertToInt()

llvm::APSInt clang::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.

If the overflow parameter is provided, set this value to true or false to indicate if this operation results in an overflow.

Definition at line 221 of file FixedPoint.cpp.

References getIntPart(), getWidth(), and clang::Result.

Referenced by CheckImplicitConversion().

◆ getBoolValue()

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

◆ getFromIntValue()

APFixedPoint clang::APFixedPoint::getFromIntValue ( const llvm::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 250 of file FixedPoint.cpp.

References APFixedPoint(), and clang::FixedPointSemantics::GetIntegerSemantics().

Referenced by CheckImplicitConversion(), and EvaluateComparisonBinaryOperator().

◆ getIntPart()

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

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

(-2.5k -> -2)

Definition at line 146 of file FixedPoint.h.

References clang::FixedPointSemantics::getScale(), and toString().

Referenced by convertToInt().

◆ getMax()

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

◆ getMin()

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

◆ getScale()

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

◆ getSemantics()

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

Definition at line 116 of file FixedPoint.h.

Referenced by add(), and clang::ASTRecordWriter::AddAPValue().

◆ getValue()

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

◆ getWidth()

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

Definition at line 111 of file FixedPoint.h.

Referenced by convertToInt().

◆ hasPadding()

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

Definition at line 115 of file FixedPoint.h.

◆ isSaturated()

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

Definition at line 113 of file FixedPoint.h.

Referenced by clang::FixedPointSemantics::getCommonSemantics(), and negate().

◆ isSigned()

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

Definition at line 114 of file FixedPoint.h.

Referenced by clang::FixedPointSemantics::getCommonSemantics(), and negate().

◆ negate()

APFixedPoint clang::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 203 of file FixedPoint.cpp.

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

◆ operator!=()

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

Definition at line 176 of file FixedPoint.h.

References compare().

◆ operator<()

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

Definition at line 180 of file FixedPoint.h.

References compare().

◆ operator<=()

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

Definition at line 184 of file FixedPoint.h.

References compare().

◆ operator==()

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

Definition at line 173 of file FixedPoint.h.

References compare().

◆ operator>()

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

Definition at line 179 of file FixedPoint.h.

References compare().

◆ operator>=()

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

Definition at line 181 of file FixedPoint.h.

References compare().

◆ shl()

APFixedPoint clang::APFixedPoint::shl ( unsigned  Amt) const
inline

Definition at line 140 of file FixedPoint.h.

◆ shr()

APFixedPoint clang::APFixedPoint::shr ( unsigned  Amt) const
inline

Definition at line 136 of file FixedPoint.h.

◆ toString() [1/2]

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

◆ toString() [2/2]

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

Definition at line 165 of file FixedPoint.h.


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