Lines Matching full:integral
1 //===--- Integral.h - Wrapper for numeric types for the VM ------*- C++ -*-===//
50 template <unsigned Bits, bool Signed> class Integral final {
52 template <unsigned OtherBits, bool OtherSigned> friend class Integral;
54 // The primitive representing the integral.
62 /// Construct an integral from anything that is convertible to storage.
63 template <typename T> explicit Integral(T V) : V(V) {}
66 using AsUnsigned = Integral<Bits, false>;
68 /// Zero-initializes an integral.
69 Integral() : V(0) {}
71 /// Constructs an integral from another integral.
73 explicit Integral(Integral<SrcBits, SrcSign> V) : V(V.V) {}
75 /// Construct an integral from a value based on signedness.
76 explicit Integral(const APSInt &V)
79 bool operator<(Integral RHS) const { return V < RHS.V; }
80 bool operator>(Integral RHS) const { return V > RHS.V; }
81 bool operator<=(Integral RHS) const { return V <= RHS.V; }
82 bool operator>=(Integral RHS) const { return V >= RHS.V; }
83 bool operator==(Integral RHS) const { return V == RHS.V; }
84 bool operator!=(Integral RHS) const { return V != RHS.V; }
90 Integral operator-() const { return Integral(-V); }
91 Integral operator-(const Integral &Other) const {
92 return Integral(V - Other.V);
94 Integral operator~() const { return Integral(~V); }
97 explicit operator Integral<DstBits, DstSign>() const {
98 return Integral<DstBits, DstSign>(V);
117 Integral<Bits, false> toUnsigned() const {
118 return Integral<Bits, false>(*this);
134 ComparisonCategoryResult compare(const Integral &RHS) const {
151 Integral truncate(unsigned TruncBits) const {
157 return Integral((V & BitMask) | (Signed && (V & SignBit) ? ExtMask : 0));
162 static Integral min(unsigned NumBits) {
163 return Integral(Min);
165 static Integral max(unsigned NumBits) {
166 return Integral(Max);
169 template <typename ValT> static Integral from(ValT Value) {
171 return Integral(Value);
173 return Integral::from(static_cast<Integral::ReprT>(Value));
177 static std::enable_if_t<SrcBits != 0, Integral>
178 from(Integral<SrcBits, SrcSign> Value) {
179 return Integral(Value.V);
182 static Integral zero() { return from(0); }
184 template <typename T> static Integral from(T Value, unsigned NumBits) {
185 return Integral(Value);
192 static bool increment(Integral A, Integral *R) {
193 return add(A, Integral(ReprT(1)), A.bitWidth(), R);
196 static bool decrement(Integral A, Integral *R) {
197 return sub(A, Integral(ReprT(1)), A.bitWidth(), R);
200 static bool add(Integral A, Integral B, unsigned OpBits, Integral *R) {
204 static bool sub(Integral A, Integral B, unsigned OpBits, Integral *R) {
208 static bool mul(Integral A, Integral B, unsigned OpBits, Integral *R) {
212 static bool rem(Integral A, Integral B, unsigned OpBits, Integral *R) {
213 *R = Integral(A.V % B.V);
217 static bool div(Integral A, Integral B, unsigned OpBits, Integral *R) {
218 *R = Integral(A.V / B.V);
222 static bool bitAnd(Integral A, Integral B, unsigned OpBits, Integral *R) {
223 *R = Integral(A.V & B.V);
227 static bool bitOr(Integral A, Integral B, unsigned OpBits, Integral *R) {
228 *R = Integral(A.V | B.V);
232 static bool bitXor(Integral A, Integral B, unsigned OpBits, Integral *R) {
233 *R = Integral(A.V ^ B.V);
237 static bool neg(Integral A, Integral *R) {
245 static bool comp(Integral A, Integral *R) {
246 *R = Integral(~A.V);
251 static void shiftLeft(const Integral A, const Integral<RHSBits, RHSSign> B,
252 unsigned OpBits, Integral *R) {
253 *R = Integral::from(A.V << B.V, OpBits);
257 static void shiftRight(const Integral A, const Integral<RHSBits, RHSSign> B,
258 unsigned OpBits, Integral *R) {
259 *R = Integral::from(A.V >> B.V, OpBits);
299 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, Integral<Bits, Signed> I) {