Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:08

0001 //===- SlowDynamicAPInt.h - SlowDynamicAPInt Class --------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This is a simple class to represent arbitrary precision signed integers.
0010 // Unlike APInt, one does not have to specify a fixed maximum size, and the
0011 // integer can take on any arbitrary values.
0012 //
0013 // This class is to be used as a fallback slow path for the DynamicAPInt class,
0014 // and is not intended to be used directly.
0015 //
0016 //===----------------------------------------------------------------------===//
0017 
0018 #ifndef LLVM_ADT_SLOWDYNAMICAPINT_H
0019 #define LLVM_ADT_SLOWDYNAMICAPINT_H
0020 
0021 #include "llvm/ADT/APInt.h"
0022 
0023 namespace llvm {
0024 class DynamicAPInt;
0025 class raw_ostream;
0026 } // namespace llvm
0027 
0028 namespace llvm::detail {
0029 /// A simple class providing dynamic arbitrary-precision arithmetic. Internally,
0030 /// it stores an APInt, whose width is doubled whenever an overflow occurs at a
0031 /// certain width. The default constructor sets the initial width to 64.
0032 /// SlowDynamicAPInt is primarily intended to be used as a slow fallback path
0033 /// for the upcoming DynamicAPInt class.
0034 class SlowDynamicAPInt {
0035   APInt Val;
0036 
0037 public:
0038   explicit SlowDynamicAPInt(int64_t Val);
0039   SlowDynamicAPInt();
0040   explicit SlowDynamicAPInt(const APInt &Val);
0041   SlowDynamicAPInt &operator=(int64_t Val);
0042   explicit operator int64_t() const;
0043   SlowDynamicAPInt operator-() const;
0044   bool operator==(const SlowDynamicAPInt &O) const;
0045   bool operator!=(const SlowDynamicAPInt &O) const;
0046   bool operator>(const SlowDynamicAPInt &O) const;
0047   bool operator<(const SlowDynamicAPInt &O) const;
0048   bool operator<=(const SlowDynamicAPInt &O) const;
0049   bool operator>=(const SlowDynamicAPInt &O) const;
0050   SlowDynamicAPInt operator+(const SlowDynamicAPInt &O) const;
0051   SlowDynamicAPInt operator-(const SlowDynamicAPInt &O) const;
0052   SlowDynamicAPInt operator*(const SlowDynamicAPInt &O) const;
0053   SlowDynamicAPInt operator/(const SlowDynamicAPInt &O) const;
0054   SlowDynamicAPInt operator%(const SlowDynamicAPInt &O) const;
0055   SlowDynamicAPInt &operator+=(const SlowDynamicAPInt &O);
0056   SlowDynamicAPInt &operator-=(const SlowDynamicAPInt &O);
0057   SlowDynamicAPInt &operator*=(const SlowDynamicAPInt &O);
0058   SlowDynamicAPInt &operator/=(const SlowDynamicAPInt &O);
0059   SlowDynamicAPInt &operator%=(const SlowDynamicAPInt &O);
0060 
0061   SlowDynamicAPInt &operator++();
0062   SlowDynamicAPInt &operator--();
0063 
0064   friend SlowDynamicAPInt abs(const SlowDynamicAPInt &X);
0065   friend SlowDynamicAPInt ceilDiv(const SlowDynamicAPInt &LHS,
0066                                   const SlowDynamicAPInt &RHS);
0067   friend SlowDynamicAPInt floorDiv(const SlowDynamicAPInt &LHS,
0068                                    const SlowDynamicAPInt &RHS);
0069   /// The operands must be non-negative for gcd.
0070   friend SlowDynamicAPInt gcd(const SlowDynamicAPInt &A,
0071                               const SlowDynamicAPInt &B);
0072 
0073   /// Overload to compute a hash_code for a SlowDynamicAPInt value.
0074   friend hash_code hash_value(const SlowDynamicAPInt &X); // NOLINT
0075 
0076   // Make DynamicAPInt a friend so it can access Val directly.
0077   friend DynamicAPInt;
0078 
0079   unsigned getBitWidth() const { return Val.getBitWidth(); }
0080 
0081   void print(raw_ostream &OS) const;
0082   LLVM_DUMP_METHOD void dump() const;
0083 };
0084 
0085 inline raw_ostream &operator<<(raw_ostream &OS, const SlowDynamicAPInt &X) {
0086   X.print(OS);
0087   return OS;
0088 }
0089 
0090 /// Returns the remainder of dividing LHS by RHS.
0091 ///
0092 /// The RHS is always expected to be positive, and the result
0093 /// is always non-negative.
0094 SlowDynamicAPInt mod(const SlowDynamicAPInt &LHS, const SlowDynamicAPInt &RHS);
0095 
0096 /// Returns the least common multiple of A and B.
0097 SlowDynamicAPInt lcm(const SlowDynamicAPInt &A, const SlowDynamicAPInt &B);
0098 
0099 /// Redeclarations of friend declarations above to
0100 /// make it discoverable by lookups.
0101 SlowDynamicAPInt abs(const SlowDynamicAPInt &X);
0102 SlowDynamicAPInt ceilDiv(const SlowDynamicAPInt &LHS,
0103                          const SlowDynamicAPInt &RHS);
0104 SlowDynamicAPInt floorDiv(const SlowDynamicAPInt &LHS,
0105                           const SlowDynamicAPInt &RHS);
0106 SlowDynamicAPInt gcd(const SlowDynamicAPInt &A, const SlowDynamicAPInt &B);
0107 hash_code hash_value(const SlowDynamicAPInt &X); // NOLINT
0108 
0109 /// ---------------------------------------------------------------------------
0110 /// Convenience operator overloads for int64_t.
0111 /// ---------------------------------------------------------------------------
0112 SlowDynamicAPInt &operator+=(SlowDynamicAPInt &A, int64_t B);
0113 SlowDynamicAPInt &operator-=(SlowDynamicAPInt &A, int64_t B);
0114 SlowDynamicAPInt &operator*=(SlowDynamicAPInt &A, int64_t B);
0115 SlowDynamicAPInt &operator/=(SlowDynamicAPInt &A, int64_t B);
0116 SlowDynamicAPInt &operator%=(SlowDynamicAPInt &A, int64_t B);
0117 
0118 bool operator==(const SlowDynamicAPInt &A, int64_t B);
0119 bool operator!=(const SlowDynamicAPInt &A, int64_t B);
0120 bool operator>(const SlowDynamicAPInt &A, int64_t B);
0121 bool operator<(const SlowDynamicAPInt &A, int64_t B);
0122 bool operator<=(const SlowDynamicAPInt &A, int64_t B);
0123 bool operator>=(const SlowDynamicAPInt &A, int64_t B);
0124 SlowDynamicAPInt operator+(const SlowDynamicAPInt &A, int64_t B);
0125 SlowDynamicAPInt operator-(const SlowDynamicAPInt &A, int64_t B);
0126 SlowDynamicAPInt operator*(const SlowDynamicAPInt &A, int64_t B);
0127 SlowDynamicAPInt operator/(const SlowDynamicAPInt &A, int64_t B);
0128 SlowDynamicAPInt operator%(const SlowDynamicAPInt &A, int64_t B);
0129 
0130 bool operator==(int64_t A, const SlowDynamicAPInt &B);
0131 bool operator!=(int64_t A, const SlowDynamicAPInt &B);
0132 bool operator>(int64_t A, const SlowDynamicAPInt &B);
0133 bool operator<(int64_t A, const SlowDynamicAPInt &B);
0134 bool operator<=(int64_t A, const SlowDynamicAPInt &B);
0135 bool operator>=(int64_t A, const SlowDynamicAPInt &B);
0136 SlowDynamicAPInt operator+(int64_t A, const SlowDynamicAPInt &B);
0137 SlowDynamicAPInt operator-(int64_t A, const SlowDynamicAPInt &B);
0138 SlowDynamicAPInt operator*(int64_t A, const SlowDynamicAPInt &B);
0139 SlowDynamicAPInt operator/(int64_t A, const SlowDynamicAPInt &B);
0140 SlowDynamicAPInt operator%(int64_t A, const SlowDynamicAPInt &B);
0141 } // namespace llvm::detail
0142 
0143 #endif // LLVM_ADT_SLOWDYNAMICAPINT_H