27 OS <<
"IsSigned=" << IsSigned <<
", ";
28 OS <<
"HasUnsignedPadding=" << HasUnsignedPadding <<
", ";
29 OS <<
"IsSaturated=" << IsSaturated;
33 return llvm::bit_cast<uint32_t>(*
this);
38 std::memcpy(&
F, &
I,
sizeof(
F));
43 bool *Overflow)
const {
49 if (RelativeUpscale > 0)
87 bool OtherSigned = OtherVal.
isSigned();
91 unsigned CommonWidth = CommonMsb - CommonLsb + 1;
97 OtherVal = OtherVal.
shl(
Other.getLsbWeight() - CommonLsb);
99 if (ThisSigned && OtherSigned) {
100 if (ThisVal.
sgt(OtherVal))
102 else if (ThisVal.
slt(OtherVal))
104 }
else if (!ThisSigned && !OtherSigned) {
105 if (ThisVal.
ugt(OtherVal))
107 else if (ThisVal.
ult(OtherVal))
109 }
else if (ThisSigned && !OtherSigned) {
112 else if (ThisVal.
ugt(OtherVal))
114 else if (ThisVal.
ult(OtherVal))
120 else if (ThisVal.
ugt(OtherVal))
122 else if (ThisVal.
ult(OtherVal))
175 Other.getMsbWeight() -
Other.hasSignOrPaddingBit());
176 unsigned CommonWidth = CommonMSb - CommonLsb + 1;
180 bool ResultHasUnsignedPadding =
false;
181 if (!ResultIsSigned) {
184 Other.hasUnsignedPadding() && !ResultIsSaturated;
190 if (ResultIsSigned || ResultHasUnsignedPadding)
194 ResultIsSaturated, ResultHasUnsignedPadding);
198 bool *Overflow)
const {
204 bool Overflowed =
false;
207 if (CommonFXSema.isSaturated()) {
208 Result = CommonFXSema.isSigned() ? ThisVal.
sadd_sat(OtherVal)
212 : ThisVal.
uadd_ov(OtherVal, Overflowed);
216 *Overflow = Overflowed;
222 bool *Overflow)
const {
228 bool Overflowed =
false;
231 if (CommonFXSema.isSaturated()) {
232 Result = CommonFXSema.isSigned() ? ThisVal.
ssub_sat(OtherVal)
236 : ThisVal.
usub_ov(OtherVal, Overflowed);
240 *Overflow = Overflowed;
246 bool *Overflow)
const {
252 bool Overflowed =
false;
255 unsigned Wide = CommonFXSema.getWidth() * 2;
256 if (CommonFXSema.isSigned()) {
257 ThisVal = ThisVal.
sext(Wide);
258 OtherVal = OtherVal.
sext(Wide);
260 ThisVal = ThisVal.
zext(Wide);
261 OtherVal = OtherVal.
zext(Wide);
272 if (CommonFXSema.isSigned())
273 Result = ThisVal.
smul_ov(OtherVal, Overflowed)
276 Result = ThisVal.
umul_ov(OtherVal, Overflowed)
278 assert(!Overflowed &&
"Full multiplication cannot overflow!");
279 Result.setIsSigned(CommonFXSema.isSigned());
287 if (CommonFXSema.isSaturated()) {
290 else if (Result > Max)
293 Overflowed = Result < Min || Result > Max;
296 *Overflow = Overflowed;
298 return APFixedPoint(Result.sextOrTrunc(CommonFXSema.getWidth()),
303 bool *Overflow)
const {
309 bool Overflowed =
false;
315 CommonFXSema.getWidth() * 2 + std::max(-CommonFXSema.getMsbWeight(), 0);
316 if (CommonFXSema.isSigned()) {
317 ThisVal = ThisVal.
sext(Wide);
318 OtherVal = OtherVal.
sext(Wide);
320 ThisVal = ThisVal.
zext(Wide);
321 OtherVal = OtherVal.
zext(Wide);
326 if (CommonFXSema.getLsbWeight() < 0)
327 ThisVal = ThisVal.
shl(-CommonFXSema.getLsbWeight());
328 else if (CommonFXSema.getLsbWeight() > 0)
329 OtherVal = OtherVal.
shl(CommonFXSema.getLsbWeight());
331 if (CommonFXSema.isSigned()) {
339 Result = ThisVal.
udiv(OtherVal);
340 Result.setIsSigned(CommonFXSema.isSigned());
348 if (CommonFXSema.isSaturated()) {
351 else if (Result > Max)
354 Overflowed = Result < Min || Result > Max;
357 *Overflow = Overflowed;
359 return APFixedPoint(Result.sextOrTrunc(CommonFXSema.getWidth()),
365 bool Overflowed =
false;
368 unsigned Wide = Sema.
getWidth() * 2;
370 ThisVal = ThisVal.
sext(Wide);
372 ThisVal = ThisVal.
zext(Wide);
376 APSInt Result = ThisVal << Amt;
377 Result.setIsSigned(Sema.
isSigned());
386 else if (Result > Max)
389 Overflowed = Result < Min || Result > Max;
392 *Overflow = Overflowed;
422 unsigned Width = std::max(OrigWidth, Scale) + 4;
430 (FractPart * RadixInt)
433 FractPart = (FractPart * RadixInt) & FractPartMask;
434 }
while (FractPart != 0);
463 bool *Overflow)
const {
470 if (SrcWidth < DstWidth) {
471 Result = Result.extend(DstWidth);
472 }
else if (SrcWidth > DstWidth) {
473 DstMin = DstMin.
extend(SrcWidth);
474 DstMax = DstMax.
extend(SrcWidth);
478 if (Result.isSigned() && !DstSign) {
479 *Overflow = Result.isNegative() || Result.ugt(DstMax);
480 }
else if (Result.isUnsigned() && DstSign) {
481 *Overflow = Result.ugt(DstMax);
483 *Overflow = Result < DstMin || Result > DstMax;
487 Result.setIsSigned(DstSign);
488 return Result.extOrTrunc(DstWidth);
530 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
531 Flt.multiply(ScaleFactor, LosslessRM);
533 if (OpSema != &FloatSema)
534 Flt.convert(FloatSema, RM, &Ignored);
576 if (&FloatSema != OpSema)
577 Val.
convert(*OpSema, LosslessRM, &Ignored);
584 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
585 Val.
multiply(ScaleFactor, LosslessRM);
598 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
600 Val.
multiply(ScaleFactor, LosslessRM);
606 bool Overflowed =
false;
610 else if (Val < FloatMin)
613 Overflowed = Val > FloatMax || Val < FloatMin;
616 *Overflow = Overflowed;
Defines the fixed point number interface.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
The APFixedPoint class works similarly to APInt/APSInt in that it is a functional replacement for a s...
APFixedPoint convert(const FixedPointSemantics &DstSema, bool *Overflow=nullptr) const
static APFixedPoint getMin(const FixedPointSemantics &Sema)
int compare(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.
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 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.
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 ...
std::string toString() const
void print(raw_ostream &) const
unsigned getWidth() 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
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
static APFixedPoint getMax(const FixedPointSemantics &Sema)
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
opStatus multiply(const APFloat &RHS, roundingMode RM)
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
opStatus roundToIntegral(roundingMode RM)
Class for arbitrary precision integers.
APInt umul_ov(const APInt &RHS, bool &Overflow) const
APInt usub_sat(const APInt &RHS) const
APInt udiv(const APInt &RHS) const
Unsigned division operation.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
APInt zext(unsigned width) const
Zero extend to a new width.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
static void sdivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
APInt relativeLShl(int RelativeShift) const
relative logical shift left
APInt sadd_sat(const APInt &RHS) const
bool sgt(const APInt &RHS) const
Signed greater than comparison.
APInt usub_ov(const APInt &RHS, bool &Overflow) const
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
APInt sadd_ov(const APInt &RHS, bool &Overflow) const
APInt relativeAShl(int RelativeShift) const
relative arithmetic shift left
APInt uadd_ov(const APInt &RHS, bool &Overflow) const
APInt uadd_sat(const APInt &RHS) const
APInt smul_ov(const APInt &RHS, bool &Overflow) const
APInt sext(unsigned width) const
Sign extend to a new width.
APInt shl(unsigned shiftAmt) const
Left-shift function.
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
bool slt(const APInt &RHS) const
Signed less than comparison.
APInt ssub_ov(const APInt &RHS, bool &Overflow) const
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
APInt ssub_sat(const APInt &RHS) const
An arbitrary precision integer that knows its signedness.
APSInt extOrTrunc(uint32_t width) const
static APSInt getMinValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the minimum integer value with the given bit width and signedness.
static APSInt get(int64_t X)
bool isNegative() const
Determine sign of this APSInt.
static APSInt getMaxValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the maximum integer value with the given bit width and signedness.
void setIsSigned(bool Val)
APSInt relativeShl(unsigned Amt) const
void setIsUnsigned(bool Val)
APSInt extend(uint32_t width) const
The fixed point semantics work similarly to fltSemantics.
static FixedPointSemantics getFromOpaqueInt(uint32_t)
Create a FixedPointSemantics object from an integer created via toOpaqueInt().
unsigned getWidth() const
bool hasUnsignedPadding() const
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...
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
uint32_t toOpaqueInt() const
Convert the semantics to a 32-bit unsigned integer.
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.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
RoundingMode
Rounding mode.
static const fltSemantics & IEEEsingle() LLVM_READNONE
static constexpr roundingMode rmNearestTiesToAway
static constexpr roundingMode rmNearestTiesToEven
static constexpr roundingMode rmTowardZero
static const fltSemantics & IEEEquad() LLVM_READNONE
static const fltSemantics & IEEEdouble() LLVM_READNONE
static const fltSemantics & IEEEhalf() LLVM_READNONE
static const fltSemantics & BFloat() LLVM_READNONE
opStatus
IEEE-754R 7: Default exception handling.
Used to differentiate between constructors with Width and Lsb from the default Width and scale.