clang
9.0.0
|
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... | |
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.
|
inline |
Definition at line 97 of file FixedPoint.h.
References clang::FixedPointSemantics::getWidth().
Referenced by add(), convert(), getFromIntValue(), getMax(), getMin(), and negate().
|
inline |
Definition at line 103 of file FixedPoint.h.
|
inline |
Definition at line 108 of file FixedPoint.h.
APFixedPoint clang::APFixedPoint::add | ( | const APFixedPoint & | Other, |
bool * | Overflow = nullptr |
||
) | const |
Definition at line 152 of file FixedPoint.cpp.
References APFixedPoint(), convert(), getSemantics(), getValue(), and clang::Result.
Referenced by EvaluateComparisonBinaryOperator().
int clang::APFixedPoint::compare | ( | const APFixedPoint & | Other | ) | const |
Definition at line 63 of file FixedPoint.cpp.
References getScale(), getValue(), and max().
APFixedPoint clang::APFixedPoint::convert | ( | const FixedPointSemantics & | DstSema, |
bool * | Overflow = nullptr |
||
) | const |
Definition at line 18 of file FixedPoint.cpp.
References APFixedPoint(), clang::FixedPointSemantics::getIntegralBits(), clang::FixedPointSemantics::getScale(), getScale(), clang::FixedPointSemantics::getWidth(), clang::FixedPointSemantics::isSaturated(), clang::FixedPointSemantics::isSigned(), and min().
Referenced by add(), and EvaluateComparisonBinaryOperator().
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.
|
inline |
Definition at line 118 of file FixedPoint.h.
Referenced by EvaluateComparisonBinaryOperator(), HandleConversionToBool(), and HandleIntToIntCast().
|
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 EvaluateComparisonBinaryOperator().
|
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().
|
static |
Definition at line 114 of file FixedPoint.cpp.
References APFixedPoint(), clang::FixedPointSemantics::getWidth(), clang::FixedPointSemantics::hasUnsignedPadding(), and clang::FixedPointSemantics::isSigned().
Referenced by clang::ASTContext::getFixedPointMax(), and negate().
|
static |
Definition at line 122 of file FixedPoint.cpp.
References APFixedPoint(), clang::FixedPointSemantics::getWidth(), and clang::FixedPointSemantics::isSigned().
Referenced by clang::ASTContext::getFixedPointMin().
|
inline |
Definition at line 112 of file FixedPoint.h.
Referenced by compare(), convert(), clang::FixedPointSemantics::getCommonSemantics(), and toString().
|
inline |
Definition at line 116 of file FixedPoint.h.
Referenced by add(), and clang::ASTRecordWriter::AddAPValue().
|
inline |
Definition at line 110 of file FixedPoint.h.
Referenced by add(), clang::ASTRecordWriter::AddAPValue(), compare(), clang::APValue::needsCleanup(), toString(), and clang::CodeGen::ConstantEmitter::tryEmitPrivate().
|
inline |
Definition at line 111 of file FixedPoint.h.
Referenced by convertToInt().
|
inline |
Definition at line 115 of file FixedPoint.h.
|
inline |
Definition at line 113 of file FixedPoint.h.
Referenced by clang::FixedPointSemantics::getCommonSemantics(), and negate().
|
inline |
Definition at line 114 of file FixedPoint.h.
Referenced by clang::FixedPointSemantics::getCommonSemantics(), and 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().
|
inline |
Definition at line 176 of file FixedPoint.h.
References compare().
|
inline |
Definition at line 180 of file FixedPoint.h.
References compare().
|
inline |
Definition at line 184 of file FixedPoint.h.
References compare().
|
inline |
Definition at line 173 of file FixedPoint.h.
References compare().
|
inline |
Definition at line 179 of file FixedPoint.h.
References compare().
|
inline |
Definition at line 181 of file FixedPoint.h.
References compare().
|
inline |
Definition at line 140 of file FixedPoint.h.
|
inline |
Definition at line 136 of file FixedPoint.h.
void clang::APFixedPoint::toString | ( | llvm::SmallVectorImpl< char > & | Str | ) | const |
Definition at line 176 of file FixedPoint.cpp.
References getScale(), and getValue().
Referenced by clang::FixedPointValueToString(), and clang::operator<<().
|
inline |
Definition at line 165 of file FixedPoint.h.