LLVM 20.0.0git
|
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"
Static Public Member Functions | |
static APFixedPoint | getMax (const FixedPointSemantics &Sema) |
static APFixedPoint | getMin (const FixedPointSemantics &Sema) |
static APFixedPoint | getEpsilon (const FixedPointSemantics &Sema) |
static const fltSemantics * | promoteFloatSemantics (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. | |
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 153 of file APFixedPoint.h.
|
inline |
Definition at line 155 of file APFixedPoint.h.
References assert(), llvm::APInt::getBitWidth(), and llvm::FixedPointSemantics::getWidth().
|
inline |
Definition at line 161 of file APFixedPoint.h.
|
inline |
Definition at line 165 of file APFixedPoint.h.
APFixedPoint llvm::APFixedPoint::add | ( | const APFixedPoint & | Other, |
bool * | Overflow = nullptr |
||
) | const |
Definition at line 187 of file APFixedPoint.cpp.
References convert, llvm::FixedPointSemantics::getCommonSemantics(), getValue(), llvm::APSInt::isSigned(), llvm::Other, llvm::APInt::sadd_ov(), llvm::APInt::sadd_sat(), llvm::APInt::uadd_ov(), and llvm::APInt::uadd_sat().
int llvm::APFixedPoint::compare | ( | const APFixedPoint & | Other | ) | const |
Definition at line 73 of file APFixedPoint.cpp.
References llvm::APSInt::extOrTrunc(), getLsbWeight(), getMsbWeight(), getValue(), llvm::APInt::isSignBitSet(), llvm::APSInt::isSigned(), llvm::Other, llvm::APInt::sgt(), llvm::APInt::shl(), llvm::APInt::slt(), llvm::APInt::ugt(), and llvm::APInt::ult().
Referenced by operator!=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().
APFixedPoint llvm::APFixedPoint::convert | ( | const FixedPointSemantics & | DstSema, |
bool * | Overflow = nullptr |
||
) | const |
Definition at line 32 of file APFixedPoint.cpp.
References llvm::APSInt::extend(), llvm::APSInt::extOrTrunc(), llvm::APInt::getBitsSetFrom(), llvm::APInt::getBitWidth(), llvm::FixedPointSemantics::getIntegralBits(), llvm::FixedPointSemantics::getLsbWeight(), getLsbWeight(), llvm::FixedPointSemantics::getWidth(), llvm::APSInt::isNegative(), llvm::FixedPointSemantics::isSaturated(), llvm::FixedPointSemantics::isSigned(), llvm::APSInt::isSigned(), llvm::Masked, llvm::APSInt::relativeShl(), and llvm::APSInt::setIsSigned().
Referenced by getFromIntValue().
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 493 of file APFixedPoint.cpp.
References llvm::APFloat::convert(), llvm::FixedPointSemantics::fitsInFloatSemantics(), Flt, llvm::FixedPointSemantics::getLsbWeight(), llvm::FixedPointSemantics::isSigned(), promoteFloatSemantics(), llvm::APFloatBase::rmNearestTiesToEven, and llvm::APFloatBase::rmTowardZero.
Referenced by getFromFloatValue().
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().
APFixedPoint llvm::APFixedPoint::div | ( | const APFixedPoint & | Other, |
bool * | Overflow = nullptr |
||
) | const |
Definition at line 292 of file APFixedPoint.cpp.
References convert, llvm::APSInt::extOrTrunc(), llvm::FixedPointSemantics::getCommonSemantics(), getMax(), getMin(), getValue(), llvm::APSInt::isNegative(), llvm::APInt::isZero(), llvm::Other, llvm::APInt::sdivrem(), llvm::APInt::sext(), llvm::APInt::shl(), llvm::APInt::udiv(), and llvm::APInt::zext().
LLVM_DUMP_METHOD void llvm::APFixedPoint::dump | ( | ) | const |
Definition at line 432 of file APFixedPoint.cpp.
References llvm::errs(), and print().
|
inline |
Definition at line 177 of file APFixedPoint.h.
References llvm::APInt::getBoolValue().
|
static |
Definition at line 132 of file APFixedPoint.cpp.
References llvm::FixedPointSemantics::getWidth(), llvm::FixedPointSemantics::isSigned(), and llvm::APInt::setBit().
|
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().
|
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().
|
inline |
Return the integral part of this fixed point number, rounded towards zero.
(-2.5k -> -2)
Definition at line 211 of file APFixedPoint.h.
References llvm::APSInt::extend(), getLsbWeight(), getMsbWeight(), getWidth(), llvm::APInt::getZero(), llvm::APSInt::isUnsigned(), and llvm::APSInt::relativeShl().
Referenced by convertToInt().
|
inline |
Definition at line 170 of file APFixedPoint.h.
References llvm::FixedPointSemantics::getLsbWeight().
Referenced by compare(), convert(), getIntPart(), and toString().
|
static |
Definition at line 119 of file APFixedPoint.cpp.
References llvm::APSInt::getMaxValue(), llvm::FixedPointSemantics::getWidth(), llvm::FixedPointSemantics::hasUnsignedPadding(), llvm::FixedPointSemantics::isSigned(), and llvm::APInt::lshr().
Referenced by div(), llvm::FixedPointSemantics::fitsInFloatSemantics(), getFromFloatValue(), mul(), negate(), and shl().
|
static |
Definition at line 127 of file APFixedPoint.cpp.
References llvm::APSInt::getMinValue(), llvm::FixedPointSemantics::getWidth(), and llvm::FixedPointSemantics::isSigned().
Referenced by div(), llvm::FixedPointSemantics::fitsInFloatSemantics(), getFromFloatValue(), mul(), and shl().
|
inline |
Definition at line 171 of file APFixedPoint.h.
References llvm::FixedPointSemantics::getMsbWeight().
Referenced by compare(), and getIntPart().
|
inline |
Definition at line 169 of file APFixedPoint.h.
References llvm::FixedPointSemantics::getScale().
|
inline |
Definition at line 175 of file APFixedPoint.h.
Referenced by llvm::hash_value().
|
inline |
Definition at line 167 of file APFixedPoint.h.
References llvm::FixedPointSemantics::isSigned().
Referenced by add(), compare(), div(), llvm::FixedPointSemantics::fitsInFloatSemantics(), getFromFloatValue(), llvm::hash_value(), mul(), shl(), sub(), and toString().
|
inline |
Definition at line 168 of file APFixedPoint.h.
References llvm::FixedPointSemantics::getWidth().
Referenced by convertToInt(), getIntPart(), and toString().
|
inline |
Definition at line 174 of file APFixedPoint.h.
References llvm::FixedPointSemantics::hasUnsignedPadding().
|
inline |
Definition at line 172 of file APFixedPoint.h.
References llvm::FixedPointSemantics::isSaturated().
Referenced by negate().
|
inline |
Definition at line 173 of file APFixedPoint.h.
References llvm::FixedPointSemantics::isSigned().
Referenced by negate().
APFixedPoint llvm::APFixedPoint::mul | ( | const APFixedPoint & | Other, |
bool * | Overflow = nullptr |
||
) | const |
Definition at line 235 of file APFixedPoint.cpp.
References assert(), convert, llvm::APSInt::extOrTrunc(), llvm::FixedPointSemantics::getCommonSemantics(), getMax(), getMin(), getValue(), llvm::Other, llvm::APInt::relativeAShl(), llvm::APInt::relativeLShl(), llvm::APInt::sext(), llvm::APInt::smul_ov(), llvm::APInt::umul_ov(), and llvm::APInt::zext().
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().
|
inline |
Definition at line 248 of file APFixedPoint.h.
References compare(), and llvm::Other.
|
inline |
Definition at line 252 of file APFixedPoint.h.
References compare(), and llvm::Other.
|
inline |
Definition at line 256 of file APFixedPoint.h.
References compare(), and llvm::Other.
|
inline |
Definition at line 245 of file APFixedPoint.h.
References compare(), and llvm::Other.
|
inline |
Definition at line 251 of file APFixedPoint.h.
References compare(), and llvm::Other.
|
inline |
Definition at line 253 of file APFixedPoint.h.
References compare(), and llvm::Other.
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().
|
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().
APFixedPoint llvm::APFixedPoint::shl | ( | unsigned | Amt, |
bool * | Overflow = nullptr |
||
) | const |
Definition at line 353 of file APFixedPoint.cpp.
References llvm::APSInt::extOrTrunc(), llvm::APInt::getBitWidth(), getMax(), getMin(), getValue(), llvm::FixedPointSemantics::getWidth(), llvm::FixedPointSemantics::isSaturated(), llvm::FixedPointSemantics::isSigned(), llvm::APInt::sext(), and llvm::APInt::zext().
|
inline |
Definition at line 198 of file APFixedPoint.h.
APFixedPoint llvm::APFixedPoint::sub | ( | const APFixedPoint & | Other, |
bool * | Overflow = nullptr |
||
) | const |
Definition at line 211 of file APFixedPoint.cpp.
References convert, llvm::FixedPointSemantics::getCommonSemantics(), getValue(), llvm::APSInt::isSigned(), llvm::Other, llvm::APInt::ssub_ov(), llvm::APInt::ssub_sat(), llvm::APInt::usub_ov(), and llvm::APInt::usub_sat().
|
inline |
Definition at line 234 of file APFixedPoint.h.
References toString().
Referenced by print(), and toString().
void llvm::APFixedPoint::toString | ( | SmallVectorImpl< char > & | Str | ) | const |
Definition at line 387 of file APFixedPoint.cpp.
References llvm::APSInt::get(), llvm::APInt::getAllOnes(), getLsbWeight(), getValue(), getWidth(), llvm::APSInt::isNegative(), llvm::APSInt::isSigned(), llvm::APSInt::setIsUnsigned(), llvm::APInt::zext(), and llvm::APInt::zextOrTrunc().
Referenced by llvm::operator<<().