LLVM 22.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 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 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 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. |
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.
|
inline |
Definition at line 165 of file APFixedPoint.h.
References assert(), and isSigned().
Referenced by add(), APFixedPoint(), APFixedPoint(), compare(), convert(), div(), getEpsilon(), getFromFloatValue(), getFromIntValue(), getMax(), getMin(), mul(), negate(), operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), shl(), shr(), and sub().
|
inline |
Definition at line 171 of file APFixedPoint.h.
References APFixedPoint(), getWidth(), and isSigned().
|
inline |
Definition at line 177 of file APFixedPoint.h.
References APFixedPoint().
APFixedPoint llvm::APFixedPoint::add | ( | const APFixedPoint & | Other, |
bool * | Overflow = nullptr ) const |
Definition at line 197 of file APFixedPoint.cpp.
References APFixedPoint(), convert(), 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 83 of file APFixedPoint.cpp.
References APFixedPoint(), 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 42 of file APFixedPoint.cpp.
References APFixedPoint(), llvm::APSInt::extend(), llvm::APSInt::extOrTrunc(), llvm::APInt::getBitsSetFrom(), llvm::APInt::getBitWidth(), llvm::FixedPointSemantics::getIntegralBits(), getLsbWeight(), llvm::FixedPointSemantics::getLsbWeight(), llvm::FixedPointSemantics::getWidth(), llvm::APSInt::isNegative(), llvm::FixedPointSemantics::isSaturated(), llvm::APSInt::isSigned(), llvm::FixedPointSemantics::isSigned(), llvm::Masked, llvm::APSInt::relativeShl(), and llvm::APSInt::setIsSigned().
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().
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().
APFixedPoint llvm::APFixedPoint::div | ( | const APFixedPoint & | Other, |
bool * | Overflow = nullptr ) const |
Definition at line 303 of file APFixedPoint.cpp.
References APFixedPoint(), convert(), llvm::APSInt::extOrTrunc(), 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 448 of file APFixedPoint.cpp.
References llvm::errs(), LLVM_DUMP_METHOD, and print().
|
inline |
Definition at line 189 of file APFixedPoint.h.
|
static |
Definition at line 142 of file APFixedPoint.cpp.
References APFixedPoint().
|
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.
|
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().
|
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().
|
inline |
Definition at line 182 of file APFixedPoint.h.
Referenced by compare(), convert(), getIntPart(), and toString().
|
static |
Definition at line 129 of file APFixedPoint.cpp.
References APFixedPoint(), llvm::APSInt::getMaxValue(), and isSigned().
Referenced by div(), llvm::FixedPointSemantics::fitsInFloatSemantics(), getFromFloatValue(), mul(), negate(), and shl().
|
static |
Definition at line 137 of file APFixedPoint.cpp.
References APFixedPoint(), and llvm::APSInt::getMinValue().
Referenced by div(), llvm::FixedPointSemantics::fitsInFloatSemantics(), getFromFloatValue(), mul(), and shl().
|
inline |
Definition at line 183 of file APFixedPoint.h.
Referenced by compare(), and getIntPart().
|
inline |
Definition at line 181 of file APFixedPoint.h.
|
inline |
Definition at line 187 of file APFixedPoint.h.
Referenced by llvm::hash_value().
|
inline |
Definition at line 179 of file APFixedPoint.h.
Referenced by add(), compare(), div(), llvm::FixedPointSemantics::fitsInFloatSemantics(), getFromFloatValue(), llvm::hash_value(), mul(), shl(), sub(), and toString().
|
inline |
Definition at line 180 of file APFixedPoint.h.
Referenced by APFixedPoint(), convertToInt(), getIntPart(), and toString().
|
inline |
Definition at line 186 of file APFixedPoint.h.
|
inline |
Definition at line 184 of file APFixedPoint.h.
Referenced by negate().
|
inline |
Definition at line 185 of file APFixedPoint.h.
Referenced by APFixedPoint(), APFixedPoint(), getMax(), and negate().
APFixedPoint llvm::APFixedPoint::mul | ( | const APFixedPoint & | Other, |
bool * | Overflow = nullptr ) const |
Definition at line 245 of file APFixedPoint.cpp.
References APFixedPoint(), assert(), convert(), llvm::APSInt::extOrTrunc(), 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 451 of file APFixedPoint.cpp.
References APFixedPoint(), getMax(), isSaturated(), and isSigned().
|
inline |
Definition at line 267 of file APFixedPoint.h.
References APFixedPoint(), compare(), and llvm::Other.
|
inline |
Definition at line 271 of file APFixedPoint.h.
References APFixedPoint(), compare(), and llvm::Other.
|
inline |
Definition at line 275 of file APFixedPoint.h.
References APFixedPoint(), compare(), and llvm::Other.
|
inline |
Definition at line 264 of file APFixedPoint.h.
References APFixedPoint(), compare(), and llvm::Other.
|
inline |
Definition at line 270 of file APFixedPoint.h.
References APFixedPoint(), compare(), and llvm::Other.
|
inline |
Definition at line 272 of file APFixedPoint.h.
References APFixedPoint(), compare(), and llvm::Other.
void llvm::APFixedPoint::print | ( | raw_ostream & | OS | ) | const |
|
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().
APFixedPoint llvm::APFixedPoint::shl | ( | unsigned | Amt, |
bool * | Overflow = nullptr ) const |
Definition at line 366 of file APFixedPoint.cpp.
References APFixedPoint(), llvm::APSInt::extOrTrunc(), llvm::APInt::getBitWidth(), getMax(), getMin(), getValue(), llvm::APInt::sext(), and llvm::APInt::zext().
|
inline |
Definition at line 214 of file APFixedPoint.h.
References APFixedPoint().
APFixedPoint llvm::APFixedPoint::sub | ( | const APFixedPoint & | Other, |
bool * | Overflow = nullptr ) const |
Definition at line 221 of file APFixedPoint.cpp.
References APFixedPoint(), convert(), 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 250 of file APFixedPoint.h.
References toString().
Referenced by print(), and toString().
void llvm::APFixedPoint::toString | ( | SmallVectorImpl< char > & | Str | ) | const |
Definition at line 401 of file APFixedPoint.cpp.
References llvm::APSInt::get(), llvm::APInt::getAllOnes(), getLsbWeight(), getValue(), getWidth(), llvm::APInt::zext(), and llvm::APInt::zextOrTrunc().
Referenced by llvm::operator<<().