Go to the documentation of this file.
20 bool *Overflow)
const {
22 unsigned DstWidth = DstSema.
getWidth();
23 unsigned DstScale = DstSema.
getScale();
24 bool Upscaling = DstScale >
getScale();
41 if (!(Masked ==
Mask || Masked == 0)) {
68 bool OtherSigned = OtherVal.
isSigned();
69 unsigned OtherScale =
Other.getScale();
83 OtherVal = OtherVal.
shl(CommonScale - OtherScale);
85 if (ThisSigned && OtherSigned) {
86 if (ThisVal.
sgt(OtherVal))
88 else if (ThisVal.
slt(OtherVal))
90 }
else if (!ThisSigned && !OtherSigned) {
91 if (ThisVal.
ugt(OtherVal))
93 else if (ThisVal.
ult(OtherVal))
95 }
else if (ThisSigned && !OtherSigned) {
98 else if (ThisVal.
ugt(OtherVal))
100 else if (ThisVal.
ult(OtherVal))
106 else if (ThisVal.
ugt(OtherVal))
108 else if (ThisVal.
ult(OtherVal))
154 unsigned CommonWidth =
159 bool ResultHasUnsignedPadding =
false;
160 if (!ResultIsSigned) {
163 Other.hasUnsignedPadding() && !ResultIsSaturated;
169 if (ResultIsSigned || ResultHasUnsignedPadding)
173 ResultIsSaturated, ResultHasUnsignedPadding);
177 bool *Overflow)
const {
183 bool Overflowed =
false;
186 if (CommonFXSema.isSaturated()) {
187 Result = CommonFXSema.isSigned() ? ThisVal.
sadd_sat(OtherVal)
191 : ThisVal.
uadd_ov(OtherVal, Overflowed);
195 *Overflow = Overflowed;
201 bool *Overflow)
const {
207 bool Overflowed =
false;
210 if (CommonFXSema.isSaturated()) {
211 Result = CommonFXSema.isSigned() ? ThisVal.
ssub_sat(OtherVal)
215 : ThisVal.
usub_ov(OtherVal, Overflowed);
219 *Overflow = Overflowed;
225 bool *Overflow)
const {
231 bool Overflowed =
false;
234 unsigned Wide = CommonFXSema.getWidth() * 2;
235 if (CommonFXSema.isSigned()) {
251 if (CommonFXSema.isSigned())
252 Result = ThisVal.
smul_ov(OtherVal, Overflowed)
253 .
ashr(CommonFXSema.getScale());
255 Result = ThisVal.
umul_ov(OtherVal, Overflowed)
256 .
lshr(CommonFXSema.getScale());
257 assert(!Overflowed &&
"Full multiplication cannot overflow!");
258 Result.setIsSigned(CommonFXSema.isSigned());
266 if (CommonFXSema.isSaturated()) {
269 else if (Result > Max)
272 Overflowed = Result < Min || Result > Max;
275 *Overflow = Overflowed;
277 return APFixedPoint(Result.sextOrTrunc(CommonFXSema.getWidth()),
282 bool *Overflow)
const {
288 bool Overflowed =
false;
291 unsigned Wide = CommonFXSema.getWidth() * 2;
292 if (CommonFXSema.isSigned()) {
302 ThisVal = ThisVal.
shl(CommonFXSema.getScale());
304 if (CommonFXSema.isSigned()) {
312 Result = ThisVal.
udiv(OtherVal);
313 Result.setIsSigned(CommonFXSema.isSigned());
321 if (CommonFXSema.isSaturated()) {
324 else if (Result > Max)
327 Overflowed = Result < Min || Result > Max;
330 *Overflow = Overflowed;
332 return APFixedPoint(Result.sextOrTrunc(CommonFXSema.getWidth()),
338 bool Overflowed =
false;
341 unsigned Wide = Sema.
getWidth() * 2;
349 APSInt Result = ThisVal << Amt;
350 Result.setIsSigned(Sema.
isSigned());
359 else if (Result > Max)
362 Overflowed = Result < Min || Result > Max;
365 *Overflow = Overflowed;
390 (FractPart * RadixInt)
393 FractPart = (FractPart * RadixInt) & FractPartMask;
394 }
while (FractPart != 0);
416 bool *Overflow)
const {
423 if (SrcWidth < DstWidth) {
424 Result = Result.extend(DstWidth);
425 }
else if (SrcWidth > DstWidth) {
426 DstMin = DstMin.
extend(SrcWidth);
427 DstMax = DstMax.
extend(SrcWidth);
431 if (Result.isSigned() && !DstSign) {
432 *Overflow = Result.isNegative() || Result.ugt(DstMax);
433 }
else if (Result.isUnsigned() && DstSign) {
434 *Overflow = Result.ugt(DstMax);
436 *Overflow = Result < DstMin || Result > DstMax;
440 Result.setIsSigned(DstSign);
441 return Result.extOrTrunc(DstWidth);
483 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
484 Flt.
multiply(ScaleFactor, LosslessRM);
486 if (OpSema != &FloatSema)
529 if (&FloatSema != OpSema)
530 Val.
convert(*OpSema, LosslessRM, &Ignored);
537 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
538 Val.
multiply(ScaleFactor, LosslessRM);
551 ScaleFactor.
convert(*OpSema, LosslessRM, &Ignored);
553 Val.
multiply(ScaleFactor, LosslessRM);
559 bool Overflowed =
false;
563 else if (Val < FloatMin)
566 Overflowed = Val > FloatMax || Val < FloatMin;
569 *Overflow = Overflowed;
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,...
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...
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.
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.
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...
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)
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.
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)
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
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)
APInt sextOrSelf(unsigned width) const
Sign-extend this APInt if necessary to ensure that its bit width is >= width.
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
APInt zextOrSelf(unsigned width) const
Zero-extend this APInt if necessary to ensure that its bit width is >= width.
#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
bool isNegative() const
Determine sign of this APSInt.
static constexpr roundingMode rmNearestTiesToEven
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
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
Align max(MaybeAlign Lhs, Align Rhs)
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 ...
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
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
LLVM Value Representation.
Optional< std::vector< StOtherPiece > > Other
unsigned getScale() const