16#ifndef LLVM_ADT_APFIXEDPOINT_H
17#define LLVM_ADT_APFIXEDPOINT_H
45 bool IsSaturated,
bool HasUnsignedPadding)
47 IsSaturated, HasUnsignedPadding) {}
49 bool IsSaturated,
bool HasUnsignedPadding)
50 : Width(Width), LsbWeight(Weight.LsbWeight), IsSigned(IsSigned),
51 IsSaturated(IsSaturated), HasUnsignedPadding(HasUnsignedPadding) {
52 assert(isUInt<WidthBitWidth>(Width) && isInt<LsbWeightBitWidth>(Weight.
LsbWeight));
53 assert(!(IsSigned && HasUnsignedPadding) &&
54 "Cannot have unsigned padding on a signed type.");
60 return LsbWeight <= 0 && static_cast<int>(Width) >= -LsbWeight;
66 return LsbWeight + Width - 1 ;
112 return Width ==
Other.Width && LsbWeight ==
Other.LsbWeight &&
113 IsSigned ==
Other.IsSigned && IsSaturated ==
Other.IsSaturated &&
114 HasUnsignedPadding ==
Other.HasUnsignedPadding;
121 unsigned IsSigned : 1;
122 unsigned IsSaturated : 1;
123 unsigned HasUnsignedPadding : 1;
126static_assert(
sizeof(FixedPointSemantics) == 4,
"");
157 : Val(Val, !Sema.
isSigned()), Sema(Sema) {
159 "The value should have a bit width that matches the Sema width");
184 bool *Overflow =
nullptr)
const;
217 if (Val < 0 && Val != -Val)
228 bool *Overflow =
nullptr)
const;
238 return std::string(S);
275 bool *Overflow =
nullptr);
286 bool *Overflow =
nullptr);
316 return LHS.getSemantics() ==
RHS.getSemantics() &&
317 LHS.getValue() ==
RHS.getValue();
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
This file defines DenseMapInfo traits for DenseMap.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
The APFixedPoint class works similarly to APInt/APSInt in that it is a functional replacement for a s...
void toString(SmallVectorImpl< char > &Str) const
APFixedPoint(const APInt &Val, const FixedPointSemantics &Sema)
static APFixedPoint getMin(const FixedPointSemantics &Sema)
bool operator==(const APFixedPoint &Other) const
bool operator!=(const APFixedPoint &Other) const
FixedPointSemantics getSemantics() const
int compare(const APFixedPoint &Other) const
bool operator<(const APFixedPoint &Other) const
APSInt convertToInt(unsigned DstWidth, bool DstSign, bool *Overflow=nullptr) const
Return the integral part of this fixed point number, rounded towards zero.
APFixedPoint shr(unsigned Amt, bool *Overflow=nullptr) const
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,...
APFixedPoint(const FixedPointSemantics &Sema)
APFixedPoint sub(const APFixedPoint &Other, bool *Overflow=nullptr) const
APFloat convertToFloat(const fltSemantics &FloatSema) const
Convert this fixed point number to a floating point value with the provided semantics.
APFixedPoint(uint64_t Val, const FixedPointSemantics &Sema)
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 ...
unsigned getScale() const
std::string toString() const
void print(raw_ostream &) const
unsigned getWidth() const
bool operator>=(const APFixedPoint &Other) const
APFixedPoint negate(bool *Overflow=nullptr) const
Perform a unary negation (-X) on this fixed point type, taking into account saturation if applicable.
APFixedPoint shl(unsigned Amt, bool *Overflow=nullptr) const
bool operator<=(const APFixedPoint &Other) const
bool operator>(const APFixedPoint &Other) const
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 l...
APFixedPoint div(const APFixedPoint &Other, bool *Overflow=nullptr) const
APFixedPoint mul(const APFixedPoint &Other, bool *Overflow=nullptr) const
APSInt getIntPart() const
Return the integral part of this fixed point number, rounded towards zero.
APFixedPoint add(const APFixedPoint &Other, bool *Overflow=nullptr) const
bool getBoolValue() const
static APFixedPoint getMax(const FixedPointSemantics &Sema)
Class for arbitrary precision integers.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool getBoolValue() const
Convert APInt to a boolean value.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
An arbitrary precision integer that knows its signedness.
APSInt relativeShl(unsigned Amt) const
APSInt extend(uint32_t width) const
The fixed point semantics work similarly to fltSemantics.
static constexpr unsigned WidthBitWidth
unsigned getWidth() const
void setSaturated(bool Saturated)
bool hasUnsignedPadding() const
static constexpr unsigned LsbWeightBitWidth
unsigned getScale() const
unsigned getIntegralBits() const
Return the number of integral bits represented by these semantics.
FixedPointSemantics getCommonSemantics(const FixedPointSemantics &Other) const
Return the FixedPointSemantics that allows for calculating the full precision semantic that can preci...
bool operator!=(FixedPointSemantics Other) const
bool operator==(FixedPointSemantics Other) const
void print(llvm::raw_ostream &OS) const
Print semantics for debug purposes.
bool fitsInFloatSemantics(const fltSemantics &FloatSema) const
Returns true if this fixed-point semantic with its value bits interpreted as an integer can fit in th...
bool hasSignOrPaddingBit() const
return true if the first bit doesn't have a strictly positive weight
FixedPointSemantics(unsigned Width, Lsb Weight, bool IsSigned, bool IsSaturated, bool HasUnsignedPadding)
FixedPointSemantics(unsigned Width, unsigned Scale, 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.
static FixedPointSemantics GetIntegerSemantics(unsigned Width, bool IsSigned)
Return the FixedPointSemantics for an integer type.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LLVM Value Representation.
An opaque object representing a hash code.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
hash_code hash_value(const FixedPointSemantics &Val)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static unsigned getHashValue(const APFixedPoint &Val)
static APFixedPoint getTombstoneKey()
static bool isEqual(const APFixedPoint &LHS, const APFixedPoint &RHS)
static APFixedPoint getEmptyKey()
static FixedPointSemantics getEmptyKey()
static bool isEqual(const char &LHS, const char &RHS)
static unsigned getHashValue(const FixedPointSemantics &Val)
static FixedPointSemantics getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...
Used to differentiate between constructors with Width and Lsb from the default Width and scale.