sc_signed.h

来自「基于4个mips核的noc设计」· C头文件 代码 · 共 1,885 行 · 第 1/5 页

H
1,885
字号
inlinesc_signed_concref<sc_signed_concref<T1,T2>,sc_signed_subref>concat( sc_signed_concref<T1,T2>, sc_signed_subref );template <class T1, class T2>inlinesc_signed_concref<sc_signed_concref<T1,T2>,sc_signed>concat( sc_signed_concref<T1,T2>, sc_signed& );template <class T1, class T2>inlineistream&operator >> ( istream&, sc_signed_concref<T1,T2>& );// ----------------------------------------------------------------------------//  CLASS : sc_signed////  Arbitrary precision signed number.// ----------------------------------------------------------------------------class sc_signed{    friend class sc_signed_bitref_r;    friend class sc_signed_bitref;    friend class sc_signed_subref_r;    friend class sc_signed_subref;    friend class sc_unsigned;    friend class sc_unsigned_subref;  // Needed for types using sc_signed.  typedef bool elemtype;public:    // constructors    explicit sc_signed( int nb = sc_length_param().len() );    sc_signed( const sc_signed&   v );    sc_signed( const sc_unsigned& v );    // assignment operators    sc_signed& operator = (const sc_signed&          v);    sc_signed& operator = (const sc_signed_subref_r& a );    template <class T1, class T2>    sc_signed& operator = ( const sc_signed_concref_r<T1,T2>& a )	{ NOT_YET_IMPLEMENTED; return *this; }    sc_signed& operator = (const sc_unsigned&        v);    sc_signed& operator = (const sc_unsigned_subref_r& a );    template <class T1, class T2>    sc_signed& operator = ( const sc_unsigned_concref_r<T1,T2>& a )	{ NOT_YET_IMPLEMENTED; return *this; }    sc_signed& operator = (const char*               v);    sc_signed& operator = (int64                     v);    sc_signed& operator = (uint64                    v);    sc_signed& operator = (long                      v);    sc_signed& operator = (unsigned long             v);    sc_signed& operator = (int                       v) 	{ return operator=((long) v); }    sc_signed& operator = (unsigned int              v) 	{ return operator=((unsigned long) v); }    sc_signed& operator = (double                    v);    sc_signed& operator = (const sc_int_base&        v);    sc_signed& operator = (const sc_uint_base&       v);    sc_signed& operator = ( const sc_bv_base& );    sc_signed& operator = ( const sc_lv_base& );#ifdef SC_INCLUDE_FX    sc_signed& operator = ( const sc_fxval& );    sc_signed& operator = ( const sc_fxval_fast& );    sc_signed& operator = ( const sc_fxnum& );    sc_signed& operator = ( const sc_fxnum_fast& );#endif    // destructor    ~sc_signed() 	{ #ifndef SC_MAX_NBITS	    delete [] digit; #endif	}  // Increment operators.  sc_signed& operator ++ ();  const sc_signed operator ++ (int);  // Decrement operators.  sc_signed& operator -- ();  const sc_signed operator -- (int);    // bit selection    sc_signed_bitref operator [] ( int i )	{ return sc_signed_bitref( *this, i ); }    sc_signed_bitref_r operator [] ( int i ) const	{ return sc_signed_bitref_r( *this, i ); }    sc_signed_bitref bit( int i )	{ return sc_signed_bitref( *this, i ); }    sc_signed_bitref_r bit( int i ) const	{ return sc_signed_bitref_r( *this, i ); }    // part selection    // Subref operators. Help access the range of bits from the ith to    // jth. These indices have arbitrary precedence with respect to each    // other, i.e., we can have i <= j or i > j. Note the equivalence    // between range(i, j) and operator(i, j). Also note that    // operator(i, i) returns a signed number that corresponds to the    // bit operator[i], so these two forms are not the same.    sc_signed_subref range( int i, int j )	{ return sc_signed_subref( *this, i, j ); }    sc_signed_subref_r range( int i, int j ) const	{ return sc_signed_subref_r( *this, i, j ); }    sc_signed_subref operator () ( int i, int j )	{ return sc_signed_subref( *this, i, j ); }    sc_signed_subref_r operator () ( int i, int j ) const	{ return sc_signed_subref_r( *this, i, j ); }      // explicit conversions    int           to_int() const;    unsigned int  to_uint() const;    long          to_long() const;    unsigned long to_ulong() const;    int64         to_int64() const;    uint64        to_uint64() const;    double        to_double() const;#ifdef SC_DT_DEPRECATED    int to_signed() const	{ return to_int(); }    unsigned int to_unsigned() const	{ return to_uint(); }#endif    // explicit conversion to character string    const sc_string to_string( sc_numrep numrep = SC_DEC ) const;    const sc_string to_string( sc_numrep numrep, bool w_prefix ) const;    // Print functions. dump prints the internals of the class.    void print( ostream& os = cout ) const	{ os << to_string(); }    void scan( istream& is = cin );    void dump( ostream& os = cout ) const;  // Functions to find various properties.  int  length() const { return nbits; }  // Bit width.  bool iszero() const;                   // Is the number zero?  bool sign() const;                     // Sign.  // Functions to access individual bits.   bool test(int i) const;      // Is the ith bit 0 or 1?  void set(int i);             // Set the ith bit to 1.  void clear(int i);           // Set the ith bit to 0.  void set(int i, bool v)      // Set the ith bit to v.    { if (v) set(i); else clear(i);  }  void invert(int i)           // Negate the ith bit.    { if (test(i)) clear(i); else set(i);  }  // Make the number equal to its mirror image.  void reverse();  // Get/set a packed bit representation of the number.  void get_packed_rep(unsigned long *buf) const;  void set_packed_rep(unsigned long *buf);  /*    The comparison of the old and new semantics are as follows:    Let s = sc_signed,         u = sc_unsigned,        un = { uint64, unsigned long, unsigned int },        sn = { int64, long, int, char* }, and        OP = { +, -, *, /, % }.    Old semantics:                     New semantics:      u OP u -> u                        u OP u -> u      s OP u -> u                        s OP u -> s      u OP s -> u                        u OP s -> s      s OP s -> s                        s OP s -> s      u OP un = un OP u -> u             u OP un = un OP u -> u      u OP sn = sn OP u -> u             u OP sn = sn OP u -> s      s OP un = un OP s -> s             s OP un = un OP s -> s      s OP sn = sn OP s -> s             s OP sn = sn OP s -> s    In the new semantics, the result is u if both operands are u; the    result is s otherwise. The only exception is subtraction. The result    of a subtraction is always s.    The old semantics is like C/C++ semantics on integer types; the    new semantics is due to the VSIA C/C++ data types standard.   */  // ARITHMETIC OPERATORS:  // ADDition operators:  friend sc_signed operator + (const sc_unsigned&  u, const sc_signed&    v);   friend sc_signed operator + (const sc_signed&    u, const sc_unsigned&  v);   friend sc_signed operator + (const sc_unsigned&  u, int64               v);   friend sc_signed operator + (const sc_unsigned&  u, long                v);   friend sc_signed operator + (const sc_unsigned&  u, int                 v)     { return operator+(u, (long) v); }  friend sc_signed operator + (int64               u, const sc_unsigned&  v);   friend sc_signed operator + (long                u, const sc_unsigned&  v);   friend sc_signed operator + (int                 u, const sc_unsigned&  v)      { return operator+((long) u, v); }   friend sc_signed operator + (const sc_signed&    u, const sc_signed&    v);  friend sc_signed operator + (const sc_signed&    u, int64               v);   friend sc_signed operator + (const sc_signed&    u, uint64              v);   friend sc_signed operator + (const sc_signed&    u, long                v);   friend sc_signed operator + (const sc_signed&    u, unsigned long       v);  friend sc_signed operator + (const sc_signed&    u, int                 v)     { return operator+(u, (long) v); }  friend sc_signed operator + (const sc_signed&    u, unsigned int        v)     { return operator+(u, (unsigned long) v); }  friend sc_signed operator + (int64               u, const sc_signed&    v);   friend sc_signed operator + (uint64              u, const sc_signed&    v);   friend sc_signed operator + (long                u, const sc_signed&    v);   friend sc_signed operator + (unsigned long       u, const sc_signed&    v);  friend sc_signed operator + (int                 u, const sc_signed&    v)      { return operator+((long) u, v); }   friend sc_signed operator + (unsigned int        u, const sc_signed&    v)      { return operator+((unsigned long) u, v); }   sc_signed& operator += (const sc_signed&    v);   sc_signed& operator += (const sc_unsigned&  v);   sc_signed& operator += (int64               v);   sc_signed& operator += (uint64              v);   sc_signed& operator += (long                v);   sc_signed& operator += (unsigned long       v);   sc_signed& operator += (int                 v)     { return operator+=((long) v); }  sc_signed& operator += (unsigned int        v)     { return operator+=((unsigned long) v); }  friend sc_signed operator + (const sc_unsigned&  u, const sc_int_base&  v);  friend sc_signed operator + (const sc_int_base&  u, const sc_unsigned&  v);  friend sc_signed operator + (const sc_signed&    u, const sc_int_base&  v);   friend sc_signed operator + (const sc_signed&    u, const sc_uint_base& v);   friend sc_signed operator + (const sc_int_base&  u, const sc_signed&    v);   friend sc_signed operator + (const sc_uint_base& u, const sc_signed&    v);   sc_signed& operator += (const sc_int_base&  v);  sc_signed& operator += (const sc_uint_base& v);  // SUBtraction operators:     friend sc_signed operator - (const sc_unsigned&  u, const sc_signed&    v);   friend sc_signed operator - (const sc_signed&    u, const sc_unsigned&  v);   friend sc_signed operator - (const sc_unsigned&  u, const sc_unsigned&  v);  friend sc_signed operator - (const sc_unsigned&  u, int64               v);   friend sc_signed operator - (const sc_unsigned&  u, uint64              v);   friend sc_signed operator - (const sc_unsigned&  u, long                v);   friend sc_signed operator - (const sc_unsigned&  u, unsigned long       v);  friend sc_signed operator - (const sc_unsigned&  u, int                v)     { return operator-(u, (long) v); }  friend sc_signed operator - (const sc_unsigned&  u, unsigned int       v)     { return operator-(u, (unsigned long) v); }  friend sc_signed operator - (int64               u, const sc_unsigned&  v);   friend sc_signed operator - (uint64              u, const sc_unsigned&  v);   friend sc_signed operator - (long                u, const sc_unsigned&  v);   friend sc_signed operator - (unsigned long       u, const sc_unsigned&  v);  friend sc_signed operator - (int                 u, const sc_unsigned&  v)      { return operator-((long) u, v); }   friend sc_signed operator - (unsigned int        u, const sc_unsigned& v)      { return operator-((unsigned long) u, v); }   friend sc_signed operator - (const sc_signed&    u, const sc_signed&    v);  friend sc_signed operator - (const sc_signed&    u, int64               v);   friend sc_signed operator - (const sc_signed&    u, uint64              v);   friend sc_signed operator - (const sc_signed&    u, long                v);   friend sc_signed operator - (const sc_signed&    u, unsigned long       v);  friend sc_signed operator - (const sc_signed&    u, int                 v)     { return operator-(u, (long) v); }  friend sc_signed operator - (const sc_signed&    u, unsigned int        v)     { return operator-(u, (unsigned long) v); }  friend sc_signed operator - (int64               u, const sc_signed&    v);   friend sc_signed operator - (uint64              u, const sc_signed&    v);   friend sc_signed operator - (long                u, const sc_signed&    v);   friend sc_signed operator - (unsigned long       u, const sc_signed&    v);  friend sc_signed operator - (int                 u, const sc_signed&    v)      { return operator-((long) u, v); }   friend sc_signed operator - (unsigned int        u, const sc_signed&    v)      { return operator-((unsigned long) u, v); }   sc_signed& operator -= (const sc_signed&    v);   sc_signed& operator -= (const sc_unsigned&  v);   sc_signed& operator -= (int64               v);   sc_signed& operator -= (uint64              v);   sc_signed& operator -= (long                v);   sc_signed& operator -= (unsigned long       v);   sc_signed& operator -= (int                 v)     { return operator -= ((long) v); }  sc_signed& operator -= (unsigned int        v)     { return operator -= ((unsigned long) v); }  friend sc_signed operator - (const sc_unsigned&  u, const sc_int_base&  v);  friend sc_signed operator - (const sc_unsigned&  u, const sc_uint_base& v);  friend sc_signed operator - (const sc_int_base&  u, const sc_unsigned&  v);  friend sc_signed operator - (const sc_uint_base& u, const sc_unsigned&  v);  friend sc_signed operator - (const sc_signed&    u, const sc_int_base&  v);   friend sc_signed operator - (const sc_signed&    u, const sc_uint_base& v);   friend sc_signed operator - (const sc_int_base&  u, const sc_signed&    v);   friend sc_signed operator - (const sc_uint_base& u, const sc_signed&    v);   sc_signed& operator -= (const sc_int_base&  v);  sc_signed& operator -= (const sc_uint_base& v);  // MULtiplication operators:     friend sc_signed operator * (const sc_unsigned&  u, const sc_signed&    v);   friend sc_signed operator * (const sc_signed&    u, const sc_unsigned&  v);   friend sc_signed operator * (const sc_unsigned&  u, int64               v);   friend sc_signed operator * (const sc_unsigned&  u, long                v);   friend sc_signed operator * (const sc_unsigned&  u, int                 v)     { return operator*(u, (long) v); }  friend sc_signed operator * (int64               u, const sc_unsigned&  v);   friend sc_signed operator * (long                u, const sc_unsigned&  v);   friend sc_signed operator * (int                 u, const sc_unsigned&  v)      { return operator*((long) u, v); }   friend sc_signed operator * (const sc_signed&  u, const sc_signed&  v);  friend sc_signed operator * (const sc_signed&  u, int64             v);   friend sc_signed operator * (const sc_signed&  u, uint64            v);   friend sc_signed operator * (const sc_signed&  u, long              v);   friend sc_signed operator * (const sc_signed&  u, unsigned long     v);  friend sc_signed operator * (const sc_signed&  u, int               v)     { return operator*(u, (long) v); }  friend sc_signed operator * (const sc_signed&  u, unsigned int      v)     { return operator*(u, (unsigned long) v); }  friend sc_signed operator * (int64             u, const sc_signed&  v);   friend sc_signed operator * (uint64            u, const sc_signed&  v);   friend sc_signed operator * (long              u, const sc_signed&  v);   friend sc_signed operator * (unsigned long     u, const sc_signed&  v);  friend sc_signed operator * (int               u, const sc_signed&  v)  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?