sc_unsigned.h
来自「基于4个mips核的noc设计」· C头文件 代码 · 共 1,850 行 · 第 1/5 页
H
1,850 行
operator , ( sc_unsigned_concref<T1,T2>, sc_unsigned_bitref );template <class T1, class T2>inlinesc_unsigned_concref<sc_unsigned_concref<T1,T2>,sc_unsigned_subref>operator , ( sc_unsigned_concref<T1,T2>, sc_unsigned_subref );template <class T1, class T2>inlinesc_unsigned_concref<sc_unsigned_concref<T1,T2>,sc_unsigned>operator , ( sc_unsigned_concref<T1,T2>, sc_unsigned& );template <class T1, class T2, class T3, class T4>inlinesc_unsigned_concref<sc_unsigned_concref<T1,T2>,sc_unsigned_concref<T3,T4> >concat( sc_unsigned_concref<T1,T2>, sc_unsigned_concref<T3,T4> );template <class T1, class T2>inlinesc_unsigned_concref<sc_unsigned_concref<T1,T2>,sc_unsigned_bitref>concat( sc_unsigned_concref<T1,T2>, sc_unsigned_bitref );template <class T1, class T2>inlinesc_unsigned_concref<sc_unsigned_concref<T1,T2>,sc_unsigned_subref>concat( sc_unsigned_concref<T1,T2>, sc_unsigned_subref );template <class T1, class T2>inlinesc_unsigned_concref<sc_unsigned_concref<T1,T2>,sc_unsigned>concat( sc_unsigned_concref<T1,T2>, sc_unsigned& );template <class T1, class T2>inlineistream&operator >> ( istream&, sc_unsigned_concref<T1,T2>& );// ----------------------------------------------------------------------------// CLASS : sc_unsigned//// Arbitrary precision unsigned number.// ----------------------------------------------------------------------------class sc_unsigned{ friend class sc_unsigned_bitref_r; friend class sc_unsigned_bitref; friend class sc_unsigned_subref_r; friend class sc_unsigned_subref; friend class sc_signed; friend class sc_signed_subref; // Needed for types using sc_unsigned. typedef bool elemtype;public: // constructors explicit sc_unsigned( int nb = sc_length_param().len() ); sc_unsigned( const sc_unsigned& v ); sc_unsigned( const sc_signed& v ); // assignment operators sc_unsigned& operator = (const sc_unsigned& v); sc_unsigned& operator = (const sc_unsigned_subref_r& a ); template <class T1, class T2> sc_unsigned& operator = ( const sc_unsigned_concref_r<T1,T2>& a ) { NOT_YET_IMPLEMENTED; return *this; } sc_unsigned& operator = (const sc_signed& v); sc_unsigned& operator = (const sc_signed_subref_r& a ); template <class T1, class T2> sc_unsigned& operator = ( const sc_signed_concref_r<T1,T2>& a ) { NOT_YET_IMPLEMENTED; return *this; } sc_unsigned& operator = ( const char* v); sc_unsigned& operator = ( int64 v); sc_unsigned& operator = ( uint64 v); sc_unsigned& operator = ( long v); sc_unsigned& operator = ( unsigned long v); sc_unsigned& operator = ( int v) { return operator=((long) v); } sc_unsigned& operator = ( unsigned int v) { return operator=((unsigned long) v); } sc_unsigned& operator = ( double v); sc_unsigned& operator = ( const sc_int_base& v); sc_unsigned& operator = ( const sc_uint_base& v); sc_unsigned& operator = ( const sc_bv_base& ); sc_unsigned& operator = ( const sc_lv_base& );#ifdef SC_INCLUDE_FX sc_unsigned& operator = ( const sc_fxval& ); sc_unsigned& operator = ( const sc_fxval_fast& ); sc_unsigned& operator = ( const sc_fxnum& ); sc_unsigned& operator = ( const sc_fxnum_fast& );#endif // destructor ~sc_unsigned() {#ifndef SC_MAX_NBITS delete [] digit;#endif } // Increment operators. sc_unsigned& operator ++ (); const sc_unsigned operator ++ (int); // Decrement operators. sc_unsigned& operator -- (); const sc_unsigned operator -- (int); // bit selection sc_unsigned_bitref operator [] ( int i ) { return sc_unsigned_bitref( *this, i ); } sc_unsigned_bitref_r operator [] ( int i ) const { return sc_unsigned_bitref_r( *this, i ); } sc_unsigned_bitref bit( int i ) { return sc_unsigned_bitref( *this, i ); } sc_unsigned_bitref_r bit( int i ) const { return sc_unsigned_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 an unsigned number that corresponds to the // bit operator [i], so these two forms are not the same. sc_unsigned_subref range( int i, int j ) { return sc_unsigned_subref( *this, i, j ); } sc_unsigned_subref_r range( int i, int j ) const { return sc_unsigned_subref_r( *this, i, j ); } sc_unsigned_subref operator () ( int i, int j ) { return sc_unsigned_subref( *this, i, j ); } sc_unsigned_subref_r operator () ( int i, int j ) const { return sc_unsigned_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 - 1; } // Bit width. bool iszero() const; // Is the number zero? bool sign() const { return 0; } // 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_unsigned operator + (const sc_unsigned& u, const sc_unsigned& v); friend sc_signed operator + (const sc_unsigned& u, int64 v); friend sc_unsigned operator + (const sc_unsigned& u, uint64 v); friend sc_signed operator + (const sc_unsigned& u, long v); friend sc_unsigned operator + (const sc_unsigned& u, unsigned long v); friend sc_signed operator + (const sc_unsigned& u, int v); friend sc_unsigned 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_unsigned operator + (uint64 u, const sc_unsigned& v); friend sc_signed operator + (long u, const sc_unsigned& v); friend sc_unsigned operator + (unsigned long u, const sc_unsigned& v); friend sc_signed operator + (int u, const sc_unsigned& v); friend sc_unsigned operator + (unsigned int u, const sc_unsigned& v) { return operator+((unsigned long) u, v); } sc_unsigned& operator += (const sc_signed& v); sc_unsigned& operator += (const sc_unsigned& v); sc_unsigned& operator += (int64 v); sc_unsigned& operator += (uint64 v); sc_unsigned& operator += (long v); sc_unsigned& operator += (unsigned long v); sc_unsigned& operator += (int v) { return operator+=((long) v); } sc_unsigned& operator += (unsigned int v) { return operator+=((unsigned long) v); } friend sc_unsigned operator + (const sc_unsigned& u, const sc_uint_base& v); friend sc_signed operator + (const sc_unsigned& u, const sc_int_base& v); friend sc_unsigned operator + (const sc_uint_base& u, const sc_unsigned& v); friend sc_signed operator + (const sc_int_base& u, const sc_unsigned& v); sc_unsigned& operator += (const sc_int_base& v); sc_unsigned& 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); friend sc_signed operator - (const sc_unsigned& u, unsigned int 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); friend sc_signed operator - (unsigned int u, const sc_unsigned& v); sc_unsigned& operator -= (const sc_signed& v); sc_unsigned& operator -= (const sc_unsigned& v); sc_unsigned& operator -= (int64 v); sc_unsigned& operator -= (uint64 v); sc_unsigned& operator -= (long v); sc_unsigned& operator -= (unsigned long v); sc_unsigned& operator -= (int v) { return operator-=((long) v); } sc_unsigned& operator -= (unsigned int v) { return operator-=((unsigned long) v); } friend sc_signed operator - (const sc_unsigned& u, const sc_uint_base& v); friend sc_signed operator - (const sc_unsigned& u, const sc_int_base& v); friend sc_signed operator - (const sc_uint_base& u, const sc_unsigned& v); friend sc_signed operator - (const sc_int_base& u, const sc_unsigned& v); sc_unsigned& operator -= (const sc_int_base& v); sc_unsigned& 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_unsigned operator * (const sc_unsigned& u, const sc_unsigned& v); friend sc_signed operator * (const sc_unsigned& u, int64 v); friend sc_unsigned operator * (const sc_unsigned& u, uint64 v); friend sc_signed operator * (const sc_unsigned& u, long v); friend sc_unsigned operator * (const sc_unsigned& u, unsigned long v); friend sc_signed operator * (const sc_unsigned& u, int v); friend sc_unsigned 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_unsigned operator * (uint64 u, const sc_unsigned& v); friend sc_signed operator * (long u, const sc_unsigned& v); friend sc_unsigned operator * (unsigned long u, const sc_unsigned& v); friend sc_signed operator * (int u, const sc_unsigned& v); friend sc_unsigned operator * (unsigned int u, const sc_unsigned& v) { return operator*((unsigned long) u, v); } sc_unsigned& operator *= (const sc_signed& v); sc_unsigned& operator *= (const sc_unsigned& v); sc_unsigned& operator *= (int64 v); sc_unsigned& operator *= (uint64 v); sc_unsigned& operator *= (long v); sc_unsigned& operator *= (unsigned long v); sc_unsigned& operator *= (int v) { return operator*=((long) v); } sc_unsigned& operator *= (unsigned int v) { return operator*=((unsigned long) v); } friend sc_unsigned operator * (const sc_unsigned& u, const sc_uint_base& v); friend sc_signed operator * (const sc_unsigned& u, const sc_int_base& v); friend sc_unsigned operator * (const sc_uint_base& u, const sc_unsigned& v); friend sc_signed operator * (const sc_int_base& u, const sc_unsigned& v); sc_unsigned& operator *= (const sc_int_base& v); sc_unsigned& operator *= (const sc_uint_base& v);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?