Lines Matching defs:Integral
1 //===--- Integral.h - Wrapper for numeric types for the VM ------*- C++ -*-===//
56 template <unsigned Bits, bool Signed> class Integral {
58 template <unsigned OtherBits, bool OtherSigned> friend class Integral;
60 // The primitive representing the integral.
68 /// Construct an integral from anything that is convertible to storage.
69 template <typename T> explicit Integral(T V) : V(V) {}
72 /// Zero-initializes an integral.
73 Integral() : V(0) {}
75 /// Constructs an integral from another integral.
77 explicit Integral(Integral<SrcBits, SrcSign> V) : V(V.V) {}
79 /// Construct an integral from a value based on signedness.
80 explicit Integral(const APSInt &V)
83 bool operator<(Integral RHS) const { return V < RHS.V; }
84 bool operator>(Integral RHS) const { return V > RHS.V; }
85 bool operator<=(Integral RHS) const { return V <= RHS.V; }
86 bool operator>=(Integral RHS) const { return V >= RHS.V; }
87 bool operator==(Integral RHS) const { return V == RHS.V; }
88 bool operator!=(Integral RHS) const { return V != RHS.V; }
94 Integral operator-() const { return Integral(-V); }
95 Integral operator~() const { return Integral(~V); }
98 explicit operator Integral<DstBits, DstSign>() const {
99 return Integral<DstBits, DstSign>(V);
117 Integral<Bits, false> toUnsigned() const {
118 return Integral<Bits, false>(*this);
134 ComparisonCategoryResult compare(const Integral &RHS) const {
140 Integral truncate(unsigned TruncBits) const {
146 return Integral((V & BitMask) | (Signed && (V & SignBit) ? ExtMask : 0));
151 static Integral min(unsigned NumBits) {
152 return Integral(Min);
154 static Integral max(unsigned NumBits) {
155 return Integral(Max);
159 static std::enable_if_t<std::is_integral<T>::value, Integral> from(T Value) {
160 return Integral(Value);
164 static std::enable_if_t<SrcBits != 0, Integral>
165 from(Integral<SrcBits, SrcSign> Value) {
166 return Integral(Value.V);
169 template <bool SrcSign> static Integral from(Integral<0, SrcSign> Value) {
171 return Integral(Value.V.getSExtValue());
173 return Integral(Value.V.getZExtValue());
176 static Integral zero() { return from(0); }
178 template <typename T> static Integral from(T Value, unsigned NumBits) {
179 return Integral(Value);
186 static bool increment(Integral A, Integral *R) {
187 return add(A, Integral(T(1)), A.bitWidth(), R);
190 static bool decrement(Integral A, Integral *R) {
191 return sub(A, Integral(T(1)), A.bitWidth(), R);
194 static bool add(Integral A, Integral B, unsigned OpBits, Integral *R) {
198 static bool sub(Integral A, Integral B, unsigned OpBits, Integral *R) {
202 static bool mul(Integral A, Integral B, unsigned OpBits, Integral *R) {
260 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, Integral<Bits, Signed> I) {