27 OS <<
"IsSigned=" << IsSigned <<
", ";
28 OS <<
"HasUnsignedPadding=" << HasUnsignedPadding <<
", ";
29 OS <<
"IsSaturated=" << IsSaturated;
33 bool *Overflow)
const {
39 if (RelativeUpscale > 0)
47 APInt Masked(NewVal & Mask);
50 if (!(Masked == Mask || Masked == 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))
159 Other.getMsbWeight() -
Other.hasSignOrPaddingBit());
160 unsigned CommonWidth = CommonMSb - CommonLsb + 1;
164 bool ResultHasUnsignedPadding =
false;
165 if (!ResultIsSigned) {
168 Other.hasUnsignedPadding() && !ResultIsSaturated;
174 if (ResultIsSigned || ResultHasUnsignedPadding)
178 ResultIsSaturated, ResultHasUnsignedPadding);
182 bool *Overflow)
const {
188 bool Overflowed =
false;
191 if (CommonFXSema.isSaturated()) {
192 Result = CommonFXSema.isSigned() ? ThisVal.
sadd_sat(OtherVal)
196 : ThisVal.
uadd_ov(OtherVal, Overflowed);
200 *Overflow = Overflowed;
206 bool *Overflow)
const {
212 bool Overflowed =
false;
215 if (CommonFXSema.isSaturated()) {
216 Result = CommonFXSema.isSigned() ? ThisVal.
ssub_sat(OtherVal)
220 : ThisVal.
usub_ov(OtherVal, Overflowed);
224 *Overflow = Overflowed;
230 bool *Overflow)
const {
236 bool Overflowed =
false;
239 unsigned Wide = CommonFXSema.getWidth() * 2;
240 if (CommonFXSema.isSigned()) {
241 ThisVal = ThisVal.
sext(Wide);
242 OtherVal = OtherVal.
sext(Wide);
244 ThisVal = ThisVal.
zext(Wide);
245 OtherVal = OtherVal.
zext(Wide);
256 if (CommonFXSema.isSigned())
257 Result = ThisVal.
smul_ov(OtherVal, Overflowed)
260 Result = ThisVal.
umul_ov(OtherVal, Overflowed)
262 assert(!Overflowed &&
"Full multiplication cannot overflow!");
263 Result.setIsSigned(CommonFXSema.isSigned());
271 if (CommonFXSema.isSaturated()) {
274 else if (Result > Max)
277 Overflowed = Result < Min || Result > Max;
280 *Overflow = Overflowed;
282 return APFixedPoint(Result.sextOrTrunc(CommonFXSema.getWidth()),
287 bool *Overflow)
const {
293 bool Overflowed =
false;
299 CommonFXSema.getWidth() * 2 + std::max(-CommonFXSema.getMsbWeight(), 0);
300 if (CommonFXSema.isSigned()) {
301 ThisVal = ThisVal.
sext(Wide);
302 OtherVal = OtherVal.
sext(Wide);
304 ThisVal = ThisVal.
zext(Wide);
305 OtherVal = OtherVal.
zext(Wide);
310 if (CommonFXSema.getLsbWeight() < 0)
311 ThisVal = ThisVal.
shl(-CommonFXSema.getLsbWeight());
312 else if (CommonFXSema.getLsbWeight() > 0)
313 OtherVal = OtherVal.
shl(CommonFXSema.getLsbWeight());
315 if (CommonFXSema.isSigned()) {
323 Result = ThisVal.
udiv(OtherVal);
324 Result.setIsSigned(CommonFXSema.isSigned());
332 if (CommonFXSema.isSaturated()) {
335 else if (Result > Max)
338 Overflowed = Result < Min || Result > Max;
341 *Overflow = Overflowed;
343 return APFixedPoint(Result.sextOrTrunc(CommonFXSema.getWidth()),
349 bool Overflowed =
false;
352 unsigned Wide = Sema.
getWidth() * 2;
354 ThisVal = ThisVal.
sext(Wide);
356 ThisVal = ThisVal.
zext(Wide);
360 APSInt Result = ThisVal << Amt;
361 Result.setIsSigned(Sema.
isSigned());
370 else if (Result > Max)
373 Overflowed = Result < Min || Result > Max;
376 *Overflow = Overflowed;
406 unsigned Width = std::max(OrigWidth, Scale) + 4;
414 (FractPart * RadixInt)
417 FractPart = (FractPart * RadixInt) & FractPartMask;
418 }
while (FractPart != 0);
447 bool *Overflow)
const {
454 if (SrcWidth < DstWidth) {
455 Result = Result.extend(DstWidth);
456 }
else if (SrcWidth > DstWidth) {
457 DstMin = DstMin.
extend(SrcWidth);
458 DstMax = DstMax.
extend(SrcWidth);
462 if (Result.isSigned() && !DstSign) {
463 *Overflow = Result.isNegative() || Result.ugt(DstMax);
464 }
else if (Result.isUnsigned() && DstSign) {
465 *Overflow = Result.ugt(DstMax);
467 *Overflow = Result < DstMin || Result > DstMax;
471 Result.setIsSigned(DstSign);
472 return Result.extOrTrunc(DstWidth);
514 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
515 Flt.multiply(ScaleFactor, LosslessRM);
517 if (OpSema != &FloatSema)
518 Flt.convert(FloatSema, RM, &Ignored);
560 if (&FloatSema != OpSema)
561 Val.
convert(*OpSema, LosslessRM, &Ignored);
568 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
569 Val.
multiply(ScaleFactor, LosslessRM);
582 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
584 Val.
multiply(ScaleFactor, LosslessRM);
590 bool Overflowed =
false;
594 else if (Val < FloatMin)
597 Overflowed = Val > FloatMax || Val < FloatMin;
600 *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 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.
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.