27 OS <<
"IsSigned=" << IsSigned <<
", ";
28 OS <<
"HasUnsignedPadding=" << HasUnsignedPadding <<
", ";
29 OS <<
"IsSaturated=" << IsSaturated;
33 bool *Overflow)
const {
39 if (RelativeUpscale > 0)
77 bool OtherSigned = OtherVal.
isSigned();
81 unsigned CommonWidth = CommonMsb - CommonLsb + 1;
87 OtherVal = OtherVal.
shl(
Other.getLsbWeight() - CommonLsb);
89 if (ThisSigned && OtherSigned) {
90 if (ThisVal.
sgt(OtherVal))
92 else if (ThisVal.
slt(OtherVal))
94 }
else if (!ThisSigned && !OtherSigned) {
95 if (ThisVal.
ugt(OtherVal))
97 else if (ThisVal.
ult(OtherVal))
99 }
else if (ThisSigned && !OtherSigned) {
102 else if (ThisVal.
ugt(OtherVal))
104 else if (ThisVal.
ult(OtherVal))
110 else if (ThisVal.
ugt(OtherVal))
112 else if (ThisVal.
ult(OtherVal))
165 Other.getMsbWeight() -
Other.hasSignOrPaddingBit());
166 unsigned CommonWidth = CommonMSb - CommonLsb + 1;
170 bool ResultHasUnsignedPadding =
false;
171 if (!ResultIsSigned) {
174 Other.hasUnsignedPadding() && !ResultIsSaturated;
180 if (ResultIsSigned || ResultHasUnsignedPadding)
184 ResultIsSaturated, ResultHasUnsignedPadding);
188 bool *Overflow)
const {
194 bool Overflowed =
false;
197 if (CommonFXSema.isSaturated()) {
198 Result = CommonFXSema.isSigned() ? ThisVal.
sadd_sat(OtherVal)
202 : ThisVal.
uadd_ov(OtherVal, Overflowed);
206 *Overflow = Overflowed;
212 bool *Overflow)
const {
218 bool Overflowed =
false;
221 if (CommonFXSema.isSaturated()) {
222 Result = CommonFXSema.isSigned() ? ThisVal.
ssub_sat(OtherVal)
226 : ThisVal.
usub_ov(OtherVal, Overflowed);
230 *Overflow = Overflowed;
236 bool *Overflow)
const {
242 bool Overflowed =
false;
245 unsigned Wide = CommonFXSema.getWidth() * 2;
246 if (CommonFXSema.isSigned()) {
247 ThisVal = ThisVal.
sext(Wide);
248 OtherVal = OtherVal.
sext(Wide);
250 ThisVal = ThisVal.
zext(Wide);
251 OtherVal = OtherVal.
zext(Wide);
262 if (CommonFXSema.isSigned())
263 Result = ThisVal.
smul_ov(OtherVal, Overflowed)
266 Result = ThisVal.
umul_ov(OtherVal, Overflowed)
268 assert(!Overflowed &&
"Full multiplication cannot overflow!");
269 Result.setIsSigned(CommonFXSema.isSigned());
277 if (CommonFXSema.isSaturated()) {
280 else if (Result > Max)
283 Overflowed = Result < Min || Result > Max;
286 *Overflow = Overflowed;
288 return APFixedPoint(Result.sextOrTrunc(CommonFXSema.getWidth()),
293 bool *Overflow)
const {
299 bool Overflowed =
false;
305 CommonFXSema.getWidth() * 2 + std::max(-CommonFXSema.getMsbWeight(), 0);
306 if (CommonFXSema.isSigned()) {
307 ThisVal = ThisVal.
sext(Wide);
308 OtherVal = OtherVal.
sext(Wide);
310 ThisVal = ThisVal.
zext(Wide);
311 OtherVal = OtherVal.
zext(Wide);
316 if (CommonFXSema.getLsbWeight() < 0)
317 ThisVal = ThisVal.
shl(-CommonFXSema.getLsbWeight());
318 else if (CommonFXSema.getLsbWeight() > 0)
319 OtherVal = OtherVal.
shl(CommonFXSema.getLsbWeight());
321 if (CommonFXSema.isSigned()) {
329 Result = ThisVal.
udiv(OtherVal);
330 Result.setIsSigned(CommonFXSema.isSigned());
338 if (CommonFXSema.isSaturated()) {
341 else if (Result > Max)
344 Overflowed = Result < Min || Result > Max;
347 *Overflow = Overflowed;
349 return APFixedPoint(Result.sextOrTrunc(CommonFXSema.getWidth()),
355 bool Overflowed =
false;
358 unsigned Wide = Sema.
getWidth() * 2;
360 ThisVal = ThisVal.
sext(Wide);
362 ThisVal = ThisVal.
zext(Wide);
366 APSInt Result = ThisVal << Amt;
367 Result.setIsSigned(Sema.
isSigned());
376 else if (Result > Max)
379 Overflowed = Result < Min || Result > Max;
382 *Overflow = Overflowed;
412 unsigned Width = std::max(OrigWidth, Scale) + 4;
420 (FractPart * RadixInt)
423 FractPart = (FractPart * RadixInt) & FractPartMask;
424 }
while (FractPart != 0);
453 bool *Overflow)
const {
460 if (SrcWidth < DstWidth) {
461 Result = Result.extend(DstWidth);
462 }
else if (SrcWidth > DstWidth) {
463 DstMin = DstMin.
extend(SrcWidth);
464 DstMax = DstMax.
extend(SrcWidth);
468 if (Result.isSigned() && !DstSign) {
469 *Overflow = Result.isNegative() || Result.ugt(DstMax);
470 }
else if (Result.isUnsigned() && DstSign) {
471 *Overflow = Result.ugt(DstMax);
473 *Overflow = Result < DstMin || Result > DstMax;
477 Result.setIsSigned(DstSign);
478 return Result.extOrTrunc(DstWidth);
520 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
521 Flt.multiply(ScaleFactor, LosslessRM);
523 if (OpSema != &FloatSema)
524 Flt.convert(FloatSema, RM, &Ignored);
566 if (&FloatSema != OpSema)
567 Val.
convert(*OpSema, LosslessRM, &Ignored);
574 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
575 Val.
multiply(ScaleFactor, LosslessRM);
588 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
590 Val.
multiply(ScaleFactor, LosslessRM);
596 bool Overflowed =
false;
600 else if (Val < FloatMin)
603 Overflowed = Val > FloatMax || Val < FloatMin;
606 *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.
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
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.