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;
130 unsigned IsSigned : 1;
131 unsigned IsSaturated : 1;
132 unsigned HasUnsignedPadding : 1;
135static_assert(
sizeof(FixedPointSemantics) == 4,
"");
166 : Val(Val, !Sema.
isSigned()), Sema(Sema) {
168 "The value should have a bit width that matches the Sema width");
195 bool *Overflow =
nullptr)
const;
202 bool *Overflow =
nullptr)
const;
204 bool *Overflow =
nullptr)
const;
206 bool *Overflow =
nullptr)
const;
208 bool *Overflow =
nullptr)
const;
232 if (Val < 0 && Val != -Val)
243 bool *Overflow =
nullptr)
const;
253 return std::string(S);
258#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
294 bool *Overflow =
nullptr);
305 bool *Overflow =
nullptr);
335 return LHS.getSemantics() ==
RHS.getSemantics() &&
336 LHS.getValue() ==
RHS.getValue();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines the SmallString class.
The APFixedPoint class works similarly to APInt/APSInt in that it is a functional replacement for a s...
LLVM_ABI APFixedPoint convert(const FixedPointSemantics &DstSema, bool *Overflow=nullptr) const
LLVM_ABI void toString(SmallVectorImpl< char > &Str) const
APFixedPoint(const APInt &Val, const FixedPointSemantics &Sema)
static LLVM_ABI APFixedPoint getMin(const FixedPointSemantics &Sema)
bool operator==(const APFixedPoint &Other) const
bool operator!=(const APFixedPoint &Other) const
FixedPointSemantics getSemantics() const
LLVM_ABI int compare(const APFixedPoint &Other) const
bool operator<(const APFixedPoint &Other) const
LLVM_ABI 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 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,...
APFixedPoint(const FixedPointSemantics &Sema)
LLVM_ABI APFixedPoint sub(const APFixedPoint &Other, bool *Overflow=nullptr) const
LLVM_ABI 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)
LLVM_DUMP_METHOD void dump() const
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 ...
unsigned getScale() const
std::string toString() const
LLVM_ABI void print(raw_ostream &) const
unsigned getWidth() const
bool operator>=(const APFixedPoint &Other) const
LLVM_ABI APFixedPoint negate(bool *Overflow=nullptr) const
Perform a unary negation (-X) on this fixed point type, taking into account saturation if applicable.
LLVM_ABI APFixedPoint shl(unsigned Amt, bool *Overflow=nullptr) const
bool operator<=(const APFixedPoint &Other) const
bool operator>(const APFixedPoint &Other) const
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 l...
LLVM_ABI APFixedPoint div(const APFixedPoint &Other, bool *Overflow=nullptr) const
LLVM_ABI APFixedPoint mul(const APFixedPoint &Other, bool *Overflow=nullptr) const
APSInt getIntPart() const
Return the integral part of this fixed point number, rounded towards zero.
LLVM_ABI APFixedPoint add(const APFixedPoint &Other, bool *Overflow=nullptr) const
bool getBoolValue() const
static LLVM_ABI 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 LLVM_ABI FixedPointSemantics getFromOpaqueInt(uint32_t)
Create a FixedPointSemantics object from an integer created via toOpaqueInt().
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.
LLVM_ABI 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
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 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)
LLVM_ABI uint32_t toOpaqueInt() const
Convert the semantics to a 32-bit unsigned integer.
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.