20 llvm::APSInt NewVal = Val;
21 unsigned DstWidth = DstSema.
getWidth();
22 unsigned DstScale = DstSema.
getScale();
23 bool Upscaling = DstScale >
getScale();
26 NewVal = NewVal.extend(NewVal.getBitWidth() + DstScale -
getScale());
33 auto Mask = llvm::APInt::getBitsSetFrom(
36 llvm::APInt Masked(NewVal & Mask);
39 if (!(Masked == Mask || Masked == 0))
40 NewVal = NewVal.isNegative() ? Mask : ~Mask;
42 if (!DstSema.
isSigned() && NewVal.isNegative())
46 NewVal = NewVal.extOrTrunc(DstWidth);
47 NewVal.setIsSigned(DstSema.
isSigned());
53 llvm::APSInt OtherVal = Other.
getValue();
54 bool ThisSigned = Val.isSigned();
55 bool OtherSigned = OtherVal.isSigned();
56 unsigned OtherScale = Other.
getScale();
57 unsigned OtherWidth = OtherVal.getBitWidth();
59 unsigned CommonWidth =
std::max(Val.getBitWidth(), OtherWidth);
65 ThisVal = ThisVal.extOrTrunc(CommonWidth);
66 OtherVal = OtherVal.extOrTrunc(CommonWidth);
69 ThisVal = ThisVal.shl(CommonScale -
getScale());
70 OtherVal = OtherVal.shl(CommonScale - OtherScale);
72 if (ThisSigned && OtherSigned) {
73 if (ThisVal.sgt(OtherVal))
75 else if (ThisVal.slt(OtherVal))
77 }
else if (!ThisSigned && !OtherSigned) {
78 if (ThisVal.ugt(OtherVal))
80 else if (ThisVal.ult(OtherVal))
82 }
else if (ThisSigned && !OtherSigned) {
83 if (ThisVal.isSignBitSet())
85 else if (ThisVal.ugt(OtherVal))
87 else if (ThisVal.ult(OtherVal))
91 if (OtherVal.isSignBitSet())
93 else if (ThisVal.ugt(OtherVal))
95 else if (ThisVal.ult(OtherVal))
104 auto Val = llvm::APSInt::getMaxValue(Sema.
getWidth(), IsUnsigned);
static APFixedPoint getMax(const FixedPointSemantics &Sema)
llvm::APSInt getValue() const
APFixedPoint convert(const FixedPointSemantics &DstSema) const
The fixed point semantics work similarly to llvm::fltSemantics.
unsigned getScale() const
int compare(const APFixedPoint &Other) const
unsigned getIntegralBits() const
static APFixedPoint getMin(const FixedPointSemantics &Sema)
unsigned getScale() const
The APFixedPoint class works similarly to APInt/APSInt in that it is a functional replacement for a s...
Sema - This implements semantic analysis and AST building for C.
bool hasUnsignedPadding() const
Defines the fixed point number interface.
Dataflow Directional Tag Classes.
unsigned getWidth() const
APFixedPoint(const llvm::APInt &Val, const FixedPointSemantics &Sema)
__DEVICE__ int max(int __a, int __b)
__DEVICE__ int min(int __a, int __b)