Go to the documentation of this file.
22 OS <<
"width=" <<
getWidth() <<
", ";
24 OS <<
"scale=" <<
getScale() <<
", ";
27 OS <<
"IsSigned=" << IsSigned <<
", ";
28 OS <<
"HasUnsignedPadding=" << HasUnsignedPadding <<
", ";
29 OS <<
"IsSaturated=" << IsSaturated;
33 bool *Overflow)
const {
39 if (RelativeUpscale > 0)
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;
414 (FractPart * RadixInt)
417 FractPart = (FractPart * RadixInt) & FractPartMask;
418 }
while (FractPart != 0);
422 OS <<
"APFixedPoint(" <<
toString() <<
", {";
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;
APSInt relativeShl(unsigned Amt) const
int compare(const APFixedPoint &Other) const
opStatus
IEEE-754R 7: Default exception handling.
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,...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
APInt sadd_ov(const APInt &RHS, bool &Overflow) const
This is an optimization pass for GlobalISel generic memory operations.
The APFixedPoint class works similarly to APInt/APSInt in that it is a functional replacement for a s...
Used to differentiate between constructors with Width and Lsb from the default Width and scale.
static const fltSemantics & IEEEsingle() LLVM_READNONE
unsigned getScale() const
unsigned getIntegralBits() const
Return the number of integral bits represented by these semantics.
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
void print(raw_ostream &) const
APFixedPoint negate(bool *Overflow=nullptr) const
Perform a unary negation (-X) on this fixed point type, taking into account saturation if applicable.
void setIsSigned(bool Val)
unsigned getBitWidth() const
Return the number of bits in the APInt.
APSInt extend(uint32_t width) const
static const fltSemantics & BFloat() LLVM_READNONE
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
APSInt getIntPart() const
Return the integral part of this fixed point number, rounded towards zero.
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.
APInt relativeAShl(int RelativeShift) const
relative arithmetic shift left
bool hasUnsignedPadding() const
static const fltSemantics & IEEEquad() LLVM_READNONE
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
APInt umul_ov(const APInt &RHS, bool &Overflow) const
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
FixedPointSemantics(unsigned Width, unsigned Scale, bool IsSigned, bool IsSaturated, bool HasUnsignedPadding)
bool hasSignOrPaddingBit() const
return true if the first bit doesn't have a strictly positive weight
static const fltSemantics & IEEEhalf() LLVM_READNONE
RoundingMode
Rounding mode.
APInt usub_sat(const APInt &RHS) const
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
unsigned getWidth() const
The fixed point semantics work similarly to fltSemantics.
static APFixedPoint getMax(const FixedPointSemantics &Sema)
An arbitrary precision integer that knows its signedness.
This class implements an extremely fast bulk output stream that can only output to a stream.
void setIsUnsigned(bool Val)
static APFixedPoint getMin(const FixedPointSemantics &Sema)
static APSInt getMinValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the minimum integer value with the given bit width and signedness.
APInt usub_ov(const APInt &RHS, bool &Overflow) const
opStatus multiply(const APFloat &RHS, roundingMode RM)
unsigned getWidth() const
bool slt(const APInt &RHS) const
Signed less than comparison.
APFixedPoint shl(unsigned Amt, bool *Overflow=nullptr) const
opStatus roundToIntegral(roundingMode RM)
APFixedPoint div(const APFixedPoint &Other, bool *Overflow=nullptr) const
static FixedPointSemantics GetIntegerSemantics(unsigned Width, bool IsSigned)
Return the FixedPointSemantics for an integer type.
static void sdivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
APFloat convertToFloat(const fltSemantics &FloatSema) const
Convert this fixed point number to a floating point value with the provided semantics.
APSInt convertToInt(unsigned DstWidth, bool DstSign, bool *Overflow=nullptr) const
Return the integral part of this fixed point number, rounded towards zero.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
APFixedPoint add(const APFixedPoint &Other, bool *Overflow=nullptr) const
Class for arbitrary precision integers.
static APSInt getMaxValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the maximum integer value with the given bit width and signedness.
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...
APInt ssub_ov(const APInt &RHS, bool &Overflow) const
static constexpr roundingMode rmNearestTiesToAway
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
static const fltSemantics & IEEEdouble() LLVM_READNONE
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
APFixedPoint(const APInt &Val, const FixedPointSemantics &Sema)
bool ult(const APInt &RHS) const
Unsigned less than comparison.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
APSInt extOrTrunc(uint32_t width) const
APInt zext(unsigned width) const
Zero extend to a new width.
APInt uadd_ov(const APInt &RHS, bool &Overflow) const
APInt ssub_sat(const APInt &RHS) const
static constexpr roundingMode rmTowardZero
APInt uadd_sat(const APInt &RHS) const
bool isMinSignedValue() const
Determine if this is the smallest signed value.
APFixedPoint mul(const APFixedPoint &Other, bool *Overflow=nullptr) const
APInt smul_ov(const APInt &RHS, bool &Overflow) const
APInt sext(unsigned width) const
Sign extend to a new width.
bool isNegative() const
Determine sign of this APSInt.
APInt relativeLShl(int RelativeShift) const
relative logical shift left
static constexpr roundingMode rmNearestTiesToEven
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
std::optional< std::vector< StOtherPiece > > Other
static const fltSemantics * promoteFloatSemantics(const fltSemantics *S)
Given a floating point semantic, return the next floating point semantic with a larger exponent and l...
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
std::string toString() const
bool sgt(const APInt &RHS) const
Signed greater than comparison.
APFixedPoint convert(const FixedPointSemantics &DstSema, bool *Overflow=nullptr) const
APInt sadd_sat(const APInt &RHS) const
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 ...
Vector Shift Left don t map to llvm shl and lshr
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
APInt shl(unsigned shiftAmt) const
Left-shift function.
APFixedPoint sub(const APFixedPoint &Other, bool *Overflow=nullptr) const
bool isValidLegacySema() const
Check if the Semantic follow the requirements of an older more limited version of this class.
LLVM Value Representation.
static APSInt get(int64_t X)