LLVM 22.0.0git
|
The fixed point semantics work similarly to fltSemantics. More...
#include "llvm/ADT/APFixedPoint.h"
Classes | |
struct | Lsb |
Used to differentiate between constructors with Width and Lsb from the default Width and scale. More... |
Public Member Functions | |
FixedPointSemantics (unsigned Width, unsigned Scale, bool IsSigned, bool IsSaturated, bool HasUnsignedPadding) | |
FixedPointSemantics (unsigned Width, Lsb Weight, bool IsSigned, bool IsSaturated, bool HasUnsignedPadding) | |
bool | isValidLegacySema () const |
Check if the Semantic follow the requirements of an older more limited version of this class. | |
unsigned | getWidth () const |
unsigned | getScale () const |
int | getLsbWeight () const |
int | getMsbWeight () const |
bool | isSigned () const |
bool | isSaturated () const |
bool | hasUnsignedPadding () const |
void | setSaturated (bool Saturated) |
bool | hasSignOrPaddingBit () const |
return true if the first bit doesn't have a strictly positive weight | |
unsigned | getIntegralBits () const |
Return the number of integral bits represented by these semantics. | |
LLVM_ABI FixedPointSemantics | getCommonSemantics (const FixedPointSemantics &Other) const |
Return the FixedPointSemantics that allows for calculating the full precision semantic that can precisely represent the precision and ranges of both input values. | |
LLVM_ABI void | print (llvm::raw_ostream &OS) const |
Print semantics for debug purposes. | |
LLVM_ABI bool | fitsInFloatSemantics (const fltSemantics &FloatSema) const |
Returns true if this fixed-point semantic with its value bits interpreted as an integer can fit in the given floating point semantic without overflowing to infinity. | |
bool | operator== (FixedPointSemantics Other) const |
bool | operator!= (FixedPointSemantics Other) const |
LLVM_ABI uint32_t | toOpaqueInt () const |
Convert the semantics to a 32-bit unsigned integer. |
Static Public Member Functions | |
static FixedPointSemantics | GetIntegerSemantics (unsigned Width, bool IsSigned) |
Return the FixedPointSemantics for an integer type. | |
static LLVM_ABI FixedPointSemantics | getFromOpaqueInt (uint32_t) |
Create a FixedPointSemantics object from an integer created via toOpaqueInt(). |
Static Public Attributes | |
static constexpr unsigned | WidthBitWidth = 16 |
static constexpr unsigned | LsbWeightBitWidth = 13 |
The fixed point semantics work similarly to fltSemantics.
The width specifies the whole bit width of the underlying scaled integer (with padding if any). The scale represents the number of fractional bits in this type. When HasUnsignedPadding is true and this type is unsigned, the first bit in the value this represents is treated as padding.
Definition at line 35 of file APFixedPoint.h.
|
inline |
Definition at line 44 of file APFixedPoint.h.
References FixedPointSemantics().
Referenced by FixedPointSemantics(), getCommonSemantics(), getFromOpaqueInt(), GetIntegerSemantics(), operator!=(), and operator==().
|
inline |
Definition at line 48 of file APFixedPoint.h.
References assert(), llvm::isInt(), llvm::isUInt(), and llvm::FixedPointSemantics::Lsb::LsbWeight.
bool llvm::FixedPointSemantics::fitsInFloatSemantics | ( | const fltSemantics & | FloatSema | ) | const |
Returns true if this fixed-point semantic with its value bits interpreted as an integer can fit in the given floating point semantic without overflowing to infinity.
For example, a signed 8-bit fixed-point semantic has a maximum and minimum integer representation of 127 and -128, respectively. If both of these values can be represented (possibly inexactly) in the floating point semantic without overflowing, this returns true.
Definition at line 148 of file APFixedPoint.cpp.
References F, llvm::APFixedPoint::getMax(), llvm::APFixedPoint::getMin(), llvm::APFixedPoint::getValue(), llvm::APSInt::isSigned(), isSigned(), llvm::APFloatBase::opOverflow, and llvm::APFloatBase::rmNearestTiesToAway.
Referenced by llvm::APFixedPoint::getFromFloatValue().
FixedPointSemantics llvm::FixedPointSemantics::getCommonSemantics | ( | const FixedPointSemantics & | Other | ) | const |
Return the FixedPointSemantics that allows for calculating the full precision semantic that can precisely represent the precision and ranges of both input values.
This does not compute the resulting semantics for a given binary operation.
Definition at line 171 of file APFixedPoint.cpp.
References FixedPointSemantics(), getLsbWeight(), getMsbWeight(), hasSignOrPaddingBit(), hasUnsignedPadding(), isSaturated(), isSigned(), and llvm::Other.
Referenced by llvm::FixedPointBuilder< IRBuilderTy >::CreateAdd(), llvm::FixedPointBuilder< IRBuilderTy >::CreateDiv(), llvm::FixedPointBuilder< IRBuilderTy >::CreateMul(), and llvm::FixedPointBuilder< IRBuilderTy >::CreateSub().
|
static |
Create a FixedPointSemantics object from an integer created via toOpaqueInt().
Definition at line 36 of file APFixedPoint.cpp.
References F, FixedPointSemantics(), and I.
|
inlinestatic |
Return the FixedPointSemantics for an integer type.
Definition at line 104 of file APFixedPoint.h.
References FixedPointSemantics().
Referenced by llvm::FixedPointBuilder< IRBuilderTy >::CreateFixedToInteger(), llvm::FixedPointBuilder< IRBuilderTy >::CreateIntegerToFixed(), and llvm::APFixedPoint::getFromIntValue().
|
inline |
Return the number of integral bits represented by these semantics.
These are separate from the fractional bits and do not include the sign or padding bit.
Definition at line 80 of file APFixedPoint.h.
References getMsbWeight(), and hasSignOrPaddingBit().
Referenced by llvm::APFixedPoint::convert().
|
inline |
Definition at line 64 of file APFixedPoint.h.
Referenced by llvm::APFixedPoint::convert(), getCommonSemantics(), llvm::APFixedPoint::getFromFloatValue(), and print().
|
inline |
Definition at line 65 of file APFixedPoint.h.
Referenced by getCommonSemantics(), getIntegralBits(), and print().
|
inline |
Definition at line 63 of file APFixedPoint.h.
References assert(), and isValidLegacySema().
Referenced by llvm::FixedPointBuilder< IRBuilderTy >::CreateFixedToFloating(), llvm::FixedPointBuilder< IRBuilderTy >::CreateFloatingToFixed(), and print().
|
inline |
Definition at line 62 of file APFixedPoint.h.
Referenced by llvm::APFixedPoint::convert(), llvm::FixedPointBuilder< IRBuilderTy >::CreateFloatingToFixed(), llvm::APFixedPoint::getFromFloatValue(), and print().
|
inline |
return true if the first bit doesn't have a strictly positive weight
Definition at line 75 of file APFixedPoint.h.
Referenced by getCommonSemantics(), and getIntegralBits().
|
inline |
Definition at line 70 of file APFixedPoint.h.
Referenced by llvm::FixedPointBuilder< IRBuilderTy >::CreateFloatingToFixed(), llvm::FixedPointBuilder< IRBuilderTy >::CreateShl(), and getCommonSemantics().
|
inline |
Definition at line 69 of file APFixedPoint.h.
Referenced by llvm::APFixedPoint::convert(), llvm::FixedPointBuilder< IRBuilderTy >::CreateFloatingToFixed(), llvm::FixedPointBuilder< IRBuilderTy >::CreateShl(), getCommonSemantics(), and llvm::APFixedPoint::getFromFloatValue().
|
inline |
Definition at line 68 of file APFixedPoint.h.
Referenced by llvm::APFixedPoint::convert(), llvm::FixedPointBuilder< IRBuilderTy >::CreateFixedToFloating(), llvm::FixedPointBuilder< IRBuilderTy >::CreateFloatingToFixed(), llvm::FixedPointBuilder< IRBuilderTy >::CreateShl(), llvm::FixedPointBuilder< IRBuilderTy >::CreateShr(), fitsInFloatSemantics(), getCommonSemantics(), and llvm::APFixedPoint::getFromFloatValue().
|
inline |
Check if the Semantic follow the requirements of an older more limited version of this class.
Definition at line 59 of file APFixedPoint.h.
Referenced by getScale(), and print().
|
inline |
Definition at line 116 of file APFixedPoint.h.
References FixedPointSemantics(), and llvm::Other.
|
inline |
Definition at line 111 of file APFixedPoint.h.
References FixedPointSemantics(), and llvm::Other.
void llvm::FixedPointSemantics::print | ( | llvm::raw_ostream & | OS | ) | const |
Print semantics for debug purposes.
Definition at line 21 of file APFixedPoint.cpp.
References getLsbWeight(), getMsbWeight(), getScale(), getWidth(), and isValidLegacySema().
|
inline |
Definition at line 72 of file APFixedPoint.h.
uint32_t llvm::FixedPointSemantics::toOpaqueInt | ( | ) | const |
Convert the semantics to a 32-bit unsigned integer.
The result is dependent on the host endianness and not stable across LLVM versions. See getFromOpaqueInt() to convert it back to a FixedPointSemantics object.
Definition at line 32 of file APFixedPoint.cpp.
References llvm::bit_cast().
|
staticconstexpr |
Definition at line 38 of file APFixedPoint.h.
|
staticconstexpr |
Definition at line 37 of file APFixedPoint.h.