sc_uint_base.h

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

H
2,628
字号
template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_subref_r,sc_uint_concref_r<T1,T2> >concat( sc_uint_subref_r, sc_uint_concref<T1,T2> );template <class T1, class T2>inlinesc_uint_concref_r<sc_uint_subref_r,sc_uint_concref_r<T1,T2> >concat( sc_uint_subref, sc_uint_concref_r<T1,T2> );inlinesc_uint_concref_r<sc_uint_subref_r,sc_uint_bitref_r>concat( sc_uint_subref_r, sc_uint_bitref );inlinesc_uint_concref_r<sc_uint_subref_r,sc_uint_bitref_r>concat( sc_uint_subref, sc_uint_bitref_r );inlinesc_uint_concref_r<sc_uint_subref_r,sc_uint_subref_r>concat( sc_uint_subref_r, sc_uint_subref );inlinesc_uint_concref_r<sc_uint_subref_r,sc_uint_subref_r>concat( sc_uint_subref, sc_uint_subref_r );inlinesc_uint_concref_r<sc_uint_subref_r,sc_uint_base>concat( sc_uint_subref_r, sc_uint_base& );inlinesc_uint_concref_r<sc_uint_subref_r,sc_uint_base>concat( sc_uint_subref, const sc_uint_base& );inlinesc_uint_concref_r<sc_uint_subref_r,sc_uint_base>concat( sc_uint_subref, bool );inlinesc_uint_concref_r<sc_uint_base,sc_uint_subref_r>concat( bool, sc_uint_subref );#endifinlineostream&operator << ( ostream&, const sc_uint_subref_r& );// ----------------------------------------------------------------------------//  CLASS : sc_uint_subref////  Proxy class for sc_uint part selection (r-value and l-value).// ----------------------------------------------------------------------------class sc_uint_subref    : public sc_uint_subref_r{    friend class sc_uint_base;    // constructor    sc_uint_subref( sc_uint_base& obj_, int left_, int right_ )	: sc_uint_subref_r( obj_, left_, right_ )        {}  public:    // copy constructor    sc_uint_subref( const sc_uint_subref& a )	: sc_uint_subref_r( a )        {}    // cloning    sc_uint_subref* clone() const        { return new sc_uint_subref( *this ); }    // assignment operators    sc_uint_subref& operator = ( uint_type v );    sc_uint_subref& operator = ( const sc_uint_base& a );    sc_uint_subref& operator = ( const sc_uint_subref_r& a )	{ return operator = ( a.operator uint_type() ); }    sc_uint_subref& operator = ( const sc_uint_subref& a )	{ return operator = ( a.operator uint_type() ); }    template <class T1, class T2>    sc_uint_subref& operator = ( const sc_uint_concref_r<T1,T2>& a )        { return operator = ( a.operator uint_type() ); }    sc_uint_subref& operator = ( const char* a );    sc_uint_subref& operator = ( unsigned long a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( long a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( unsigned int a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( int a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( int64 a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( double a )	{ return operator = ( (uint_type) a ); }    sc_uint_subref& operator = ( const sc_signed& );    sc_uint_subref& operator = ( const sc_unsigned& );    sc_uint_subref& operator = ( const sc_bv_base& );    sc_uint_subref& operator = ( const sc_lv_base& );    // other methods    void scan( istream& is = cin );private:    // disabled    sc_uint_subref();};// l-value concatenation operators and functionstemplate <class T1, class T2>inlinesc_uint_concref<sc_uint_subref,sc_uint_concref<T1,T2> >operator , ( sc_uint_subref, sc_uint_concref<T1,T2> );inlinesc_uint_concref<sc_uint_subref,sc_uint_bitref>operator , ( sc_uint_subref, sc_uint_bitref );inlinesc_uint_concref<sc_uint_subref,sc_uint_subref>operator , ( sc_uint_subref, sc_uint_subref );inlinesc_uint_concref<sc_uint_subref,sc_uint_base>operator , ( sc_uint_subref, sc_uint_base& );template <class T1, class T2>inlinesc_uint_concref<sc_uint_subref,sc_uint_concref<T1,T2> >concat( sc_uint_subref, sc_uint_concref<T1,T2> );inlinesc_uint_concref<sc_uint_subref,sc_uint_bitref>concat( sc_uint_subref, sc_uint_bitref );inlinesc_uint_concref<sc_uint_subref,sc_uint_subref>concat( sc_uint_subref, sc_uint_subref );inlinesc_uint_concref<sc_uint_subref,sc_uint_base>concat( sc_uint_subref, sc_uint_base& );inlineistream&operator >> ( istream&, sc_uint_subref& );// ----------------------------------------------------------------------------//  CLASS : sc_uint_base////  Base class for sc_uint.// ----------------------------------------------------------------------------class sc_uint_base{    friend class sc_uint_bitref_r;    friend class sc_uint_bitref;    friend class sc_uint_subref_r;    friend class sc_uint_subref;    // support methods    void invalid_length() const;    void invalid_index( int i ) const;    void invalid_range( int l, int r ) const;    void check_length() const	{ if( m_len <= 0 || m_len > SC_INTWIDTH ) { invalid_length(); } }    void check_index( int i ) const	{ if( i < 0 || i >= m_len ) { invalid_index( i ); } }    void check_range( int l, int r ) const	{ if( r < 0 || l >= m_len || l < r ) { invalid_range( l, r ); } }    void check_value() const;    void extend_sign()	{#ifdef DEBUG_SYSTEMC	    check_value();#endif	    m_val &= ( ~UINT_ZERO >> m_ulen );	}public:    // constructors    explicit sc_uint_base( int w = sc_length_param().len() )	: m_val( 0 ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )	{ check_length(); }    sc_uint_base( uint_type v, int w )	: m_val( v ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )	{ check_length(); extend_sign(); }    sc_uint_base( const sc_uint_base& a )	: m_val( a.m_val ), m_len( a.m_len ), m_ulen( a.m_ulen )	{}    explicit sc_uint_base( const sc_uint_subref_r& a )        : m_val( a ), m_len( a.length() ), m_ulen( SC_INTWIDTH - m_len )        { extend_sign(); }    template <class T1, class T2>    explicit sc_uint_base( const sc_uint_concref_r<T1,T2>& a )        : m_val( a ), m_len( a.length() ), m_ulen( SC_INTWIDTH - m_len )        { extend_sign(); }    explicit sc_uint_base( const sc_signed& a );    explicit sc_uint_base( const sc_unsigned& a );    // destructor    ~sc_uint_base()	{}    // assignment operators    sc_uint_base& operator = ( uint_type v )	{ m_val = v; extend_sign(); return *this; }    sc_uint_base& operator = ( const sc_uint_base& a )	{ m_val = a.m_val; extend_sign(); return *this; }    sc_uint_base& operator = ( const sc_uint_subref_r& a )        { m_val = a; extend_sign(); return *this; }    template <class T1, class T2>    sc_uint_base& operator = ( const sc_uint_concref_r<T1,T2>& a )        { m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( const sc_signed& a );    sc_uint_base& operator = ( const sc_unsigned& a );#ifdef SC_INCLUDE_FX    sc_uint_base& operator = ( const sc_fxval& a );    sc_uint_base& operator = ( const sc_fxval_fast& a );    sc_uint_base& operator = ( const sc_fxnum& a );    sc_uint_base& operator = ( const sc_fxnum_fast& a );#endif    sc_uint_base& operator = ( const sc_bv_base& a );    sc_uint_base& operator = ( const sc_lv_base& a );    sc_uint_base& operator = ( const char* a );    sc_uint_base& operator = ( unsigned long a )	{ m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( long a )	{ m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( unsigned int a )	{ m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( int a )	{ m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( int64 a )	{ m_val = a; extend_sign(); return *this; }    sc_uint_base& operator = ( double a )	{ m_val = (uint_type) a; extend_sign(); return *this; }    // arithmetic assignment operators    sc_uint_base& operator += ( uint_type v )	{ m_val += v; extend_sign(); return *this; }    sc_uint_base& operator -= ( uint_type v )	{ m_val -= v; extend_sign(); return *this; }    sc_uint_base& operator *= ( uint_type v )	{ m_val *= v; extend_sign(); return *this; }    sc_uint_base& operator /= ( uint_type v )	{ m_val /= v; extend_sign(); return *this; }    sc_uint_base& operator %= ( uint_type v )	{ m_val %= v; extend_sign(); return *this; }    // bitwise assignment operators    sc_uint_base& operator &= ( uint_type v )	{ m_val &= v; extend_sign(); return *this; }    sc_uint_base& operator |= ( uint_type v )	{ m_val |= v; extend_sign(); return *this; }    sc_uint_base& operator ^= ( uint_type v )	{ m_val ^= v; extend_sign(); return *this; }    sc_uint_base& operator <<= ( uint_type v )	{ m_val <<= v; extend_sign(); return *this; }    sc_uint_base& operator >>= ( uint_type v )	{ m_val >>= v; /* no sign extension needed */ return *this; }    // prefix and postfix increment and decrement operators    sc_uint_base& operator ++ () // prefix	{ ++ m_val; extend_sign(); return *this; }    const sc_uint_base operator ++ ( int ) // postfix	{ sc_uint_base tmp( *this ); ++ m_val; extend_sign(); return tmp; }    sc_uint_base& operator -- () // prefix	{ -- m_val; extend_sign(); return *this; }    const sc_uint_base operator -- ( int ) // postfix	{ sc_uint_base tmp( *this ); -- m_val; extend_sign(); return tmp; }    // relational operators    friend bool operator == ( const sc_uint_base& a, const sc_uint_base& b )	{ return a.m_val == b.m_val; }    friend bool operator != ( const sc_uint_base& a, const sc_uint_base& b )	{ return a.m_val != b.m_val; }    friend bool operator <  ( const sc_uint_base& a, const sc_uint_base& b )	{ return a.m_val < b.m_val; }    friend bool operator <= ( const sc_uint_base& a, const sc_uint_base& b )	{ return a.m_val <= b.m_val; }    friend bool operator >  ( const sc_uint_base& a, const sc_uint_base& b )	{ return a.m_val > b.m_val; }    friend bool operator >= ( const sc_uint_base& a, const sc_uint_base& b )	{ return a.m_val >= b.m_val; }    // bit selection      sc_uint_bitref   operator [] ( int i );    sc_uint_bitref_r operator [] ( int i ) const;    sc_uint_bitref   bit( int i );    sc_uint_bitref_r bit( int i ) const;    // part selection    sc_uint_subref   operator () ( int left, int right );    sc_uint_subref_r operator () ( int left, int right ) const;    sc_uint_subref   range( int left, int right );    sc_uint_subref_r range( int left, int right ) const;    // bit access, without bounds checking or sign extension      bool test( int i ) const	{ return ( 0 != (m_val & (UINT_ONE << i)) ); }    void set( int i )	{ m_val |= (UINT_ONE << i); }    void set( int i, bool v )	{ v ? m_val |= (UINT_ONE << i) : m_val &= ~(UINT_ONE << i); }    // capacity    int length() const	{ return m_len; }#ifdef SC_DT_DEPRECATED    int bitwidth() const	{ return length(); }#endif    // reduce methods    bool and_reduce() const;    bool nand_reduce() const	{ return ( ! and_reduce() ); }    bool or_reduce() const;    bool nor_reduce() const	{ return ( ! or_reduce() ); }    bool xor_reduce() const;    bool xnor_reduce() const	{ return ( ! xor_reduce() ); }    // implicit conversion to uint_type    operator uint_type() const	{ return m_val; }    // explicit conversions    uint_type value() const	{ return operator uint_type(); }    int to_int() const	{ return (int) m_val; }    unsigned int to_uint() const	{ return (unsigned int) m_val; }    long to_long() const	{ return (long) m_val; }    unsigned long to_ulong() const	{ return (unsigned long) m_val; }    int64 to_int64() const	{ return (int64) m_val; }    uint64 to_uint64() const	{ return (uint64) m_val; }    double to_double() const        { return uint64_to_double( m_val ); }#ifndef _32BIT_    long long_low() const 	{ return (long) (m_val & UINT64_32ONES); }    long long_high() const 	{ return (long) ((m_val >> 32) & UINT64_32ONES); }#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;    // other methods    void print( ostream& os = cout ) const	{ os << to_string(); }    void scan( istream& is = cin );protected:    uint_type m_val;   // value    int       m_len;   // length    int       m_ulen;  // unused length};// r-value concatenation operators and functionstemplate <class T1, class T2>inlinesc_uint_concref_r<sc_uint_base,sc_uint_concref_r<T1,T2> >operator , ( const sc_uint_base&, sc_uint_concref_r<T1,T2> );inlinesc_uint_concref_r<sc_uint_base,sc_uint_bitref_r>operator , ( const sc_uint_base&, sc_uint_bitref_r );inlinesc_uint_concref_r<sc_uint_base,sc_uint_subref_r>operator , ( const sc_uint_base&, sc_uint_subref_r );inlinesc_uint_concref_r<sc_uint_base,sc_uint_base>operator , ( const sc_uint_base&, const sc_uint_base& );inlinesc_uint_concref_r<sc_uint_base,sc_uint_base>operator , ( const sc_uint_base&, bool );inlinesc_uint_concref_r<sc_uint_base,sc_uint_base>operator , ( bool, const sc_uint_base& );

⌨️ 快捷键说明

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