sc_int_base.h

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

H
2,692
字号
concat( sc_int_subref, sc_int_subref_r );inlinesc_int_concref_r<sc_int_subref_r,sc_int_base>concat( sc_int_subref_r, sc_int_base& );inlinesc_int_concref_r<sc_int_subref_r,sc_int_base>concat( sc_int_subref, const sc_int_base& );inlinesc_int_concref_r<sc_int_subref_r,sc_int_base>concat( sc_int_subref, bool );inlinesc_int_concref_r<sc_int_base,sc_int_subref_r>concat( bool, sc_int_subref );#endifinlineostream&operator << ( ostream&, const sc_int_subref_r& );// ----------------------------------------------------------------------------//  CLASS : sc_int_subref////  Proxy class for sc_int part selection (r-value and l-value).// ----------------------------------------------------------------------------class sc_int_subref    : public sc_int_subref_r{    friend class sc_int_base;    // constructor    sc_int_subref( sc_int_base& obj_, int left_, int right_ )	: sc_int_subref_r( obj_, left_, right_ )        {}  public:    // copy constructor    sc_int_subref( const sc_int_subref& a )	: sc_int_subref_r( a )        {}    // cloning    sc_int_subref* clone() const        { return new sc_int_subref( *this ); }    // assignment operators    sc_int_subref& operator = ( int_type v );    sc_int_subref& operator = ( const sc_int_base& a );    sc_int_subref& operator = ( const sc_int_subref_r& a )	{ return operator = ( a.operator int_type() ); }    sc_int_subref& operator = ( const sc_int_subref& a )	{ return operator = ( a.operator int_type() ); }    template <class T1, class T2>    sc_int_subref& operator = ( const sc_int_concref_r<T1,T2>& a )        { return operator = ( a.operator int_type() ); }    sc_int_subref& operator = ( const char* a );    sc_int_subref& operator = ( unsigned long a )	{ return operator = ( (int_type) a ); }    sc_int_subref& operator = ( long a )	{ return operator = ( (int_type) a ); }    sc_int_subref& operator = ( unsigned int a )	{ return operator = ( (int_type) a ); }    sc_int_subref& operator = ( int a )	{ return operator = ( (int_type) a ); }    sc_int_subref& operator = ( uint64 a )	{ return operator = ( (int_type) a ); }    sc_int_subref& operator = ( double a )	{ return operator = ( (int_type) a ); }    sc_int_subref& operator = ( const sc_signed& );    sc_int_subref& operator = ( const sc_unsigned& );    sc_int_subref& operator = ( const sc_bv_base& );    sc_int_subref& operator = ( const sc_lv_base& );    // other methods    void scan( istream& is = cin );private:    // disabled    sc_int_subref();};// l-value concatenation operators and functionstemplate <class T1, class T2>inlinesc_int_concref<sc_int_subref,sc_int_concref<T1,T2> >operator , ( sc_int_subref, sc_int_concref<T1,T2> );inlinesc_int_concref<sc_int_subref,sc_int_bitref>operator , ( sc_int_subref, sc_int_bitref );inlinesc_int_concref<sc_int_subref,sc_int_subref>operator , ( sc_int_subref, sc_int_subref );inlinesc_int_concref<sc_int_subref,sc_int_base>operator , ( sc_int_subref, sc_int_base& );template <class T1, class T2>inlinesc_int_concref<sc_int_subref,sc_int_concref<T1,T2> >concat( sc_int_subref, sc_int_concref<T1,T2> );inlinesc_int_concref<sc_int_subref,sc_int_bitref>concat( sc_int_subref, sc_int_bitref );inlinesc_int_concref<sc_int_subref,sc_int_subref>concat( sc_int_subref, sc_int_subref );inlinesc_int_concref<sc_int_subref,sc_int_base>concat( sc_int_subref, sc_int_base& );inlineistream&operator >> ( istream&, sc_int_subref& );// ----------------------------------------------------------------------------//  CLASS : sc_int_base////  Base class for sc_int.// ----------------------------------------------------------------------------class sc_int_base{    friend class sc_int_bitref_r;    friend class sc_int_bitref;    friend class sc_int_subref_r;    friend class sc_int_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 = ( m_val << m_ulen >> m_ulen );	}public:    // constructors    explicit sc_int_base( int w = sc_length_param().len() )	: m_val( 0 ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )	{ check_length(); }    sc_int_base( int_type v, int w )	: m_val( v ), m_len( w ), m_ulen( SC_INTWIDTH - m_len )	{ check_length(); extend_sign(); }    sc_int_base( const sc_int_base& a )	: m_val( a.m_val ), m_len( a.m_len ), m_ulen( a.m_ulen )	{}    explicit sc_int_base( const sc_int_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_int_base( const sc_int_concref_r<T1,T2>& a )        : m_val( a ), m_len( a.length() ), m_ulen( SC_INTWIDTH - m_len )        { extend_sign(); }    explicit sc_int_base( const sc_signed& a );    explicit sc_int_base( const sc_unsigned& a );    // destructor    ~sc_int_base()	{}    // assignment operators    sc_int_base& operator = ( int_type v )	{ m_val = v; extend_sign(); return *this; }    sc_int_base& operator = ( const sc_int_base& a )	{ m_val = a.m_val; extend_sign(); return *this; }    sc_int_base& operator = ( const sc_int_subref_r& a )        { m_val = a; extend_sign(); return *this; }    template <class T1, class T2>    sc_int_base& operator = ( const sc_int_concref_r<T1,T2>& a )        { m_val = a; extend_sign(); return *this; }    sc_int_base& operator = ( const sc_signed& a );    sc_int_base& operator = ( const sc_unsigned& a );#ifdef SC_INCLUDE_FX    sc_int_base& operator = ( const sc_fxval& a );    sc_int_base& operator = ( const sc_fxval_fast& a );    sc_int_base& operator = ( const sc_fxnum& a );    sc_int_base& operator = ( const sc_fxnum_fast& a );#endif    sc_int_base& operator = ( const sc_bv_base& a );    sc_int_base& operator = ( const sc_lv_base& a );    sc_int_base& operator = ( const char* a );    sc_int_base& operator = ( unsigned long a )	{ m_val = a; extend_sign(); return *this; }    sc_int_base& operator = ( long a )	{ m_val = a; extend_sign(); return *this; }    sc_int_base& operator = ( unsigned int a )	{ m_val = a; extend_sign(); return *this; }    sc_int_base& operator = ( int a )	{ m_val = a; extend_sign(); return *this; }    sc_int_base& operator = ( uint64 a )	{ m_val = a; extend_sign(); return *this; }    sc_int_base& operator = ( double a )	{ m_val = (int_type) a; extend_sign(); return *this; }    // arithmetic assignment operators    sc_int_base& operator += ( int_type v )	{ m_val += v; extend_sign(); return *this; }    sc_int_base& operator -= ( int_type v )	{ m_val -= v; extend_sign(); return *this; }    sc_int_base& operator *= ( int_type v )	{ m_val *= v; extend_sign(); return *this; }    sc_int_base& operator /= ( int_type v )	{ m_val /= v; extend_sign(); return *this; }    sc_int_base& operator %= ( int_type v )	{ m_val %= v; extend_sign(); return *this; }    // bitwise assignment operators    sc_int_base& operator &= ( int_type v )	{ m_val &= v; extend_sign(); return *this; }    sc_int_base& operator |= ( int_type v )	{ m_val |= v; extend_sign(); return *this; }    sc_int_base& operator ^= ( int_type v )	{ m_val ^= v; extend_sign(); return *this; }    sc_int_base& operator <<= ( int_type v )	{ m_val <<= v; extend_sign(); return *this; }    sc_int_base& operator >>= ( int_type v )	{ m_val >>= v; /* no sign extension needed */ return *this; }    // prefix and postfix increment and decrement operators    sc_int_base& operator ++ () // prefix	{ ++ m_val; extend_sign(); return *this; }    const sc_int_base operator ++ ( int ) // postfix	{ sc_int_base tmp( *this ); ++ m_val; extend_sign(); return tmp; }     sc_int_base& operator -- () // prefix	{ -- m_val; extend_sign(); return *this; }    const sc_int_base operator -- ( int ) // postfix	{ sc_int_base tmp( *this ); -- m_val; extend_sign(); return tmp; }    // relational operators    friend bool operator == ( const sc_int_base& a, const sc_int_base& b )	{ return a.m_val == b.m_val; }    friend bool operator != ( const sc_int_base& a, const sc_int_base& b )	{ return a.m_val != b.m_val; }    friend bool operator <  ( const sc_int_base& a, const sc_int_base& b )	{ return a.m_val < b.m_val; }    friend bool operator <= ( const sc_int_base& a, const sc_int_base& b )	{ return a.m_val <= b.m_val; }    friend bool operator >  ( const sc_int_base& a, const sc_int_base& b )	{ return a.m_val > b.m_val; }    friend bool operator >= ( const sc_int_base& a, const sc_int_base& b )	{ return a.m_val >= b.m_val; }    // bit selection    sc_int_bitref   operator [] ( int i );    sc_int_bitref_r operator [] ( int i ) const;    sc_int_bitref   bit( int i );    sc_int_bitref_r bit( int i ) const;    // part selection    sc_int_subref   operator () ( int left, int right );    sc_int_subref_r operator () ( int left, int right ) const;    sc_int_subref   range( int left, int right );    sc_int_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 int_type    operator int_type() const	{ return m_val; }    // explicit conversions    int_type value() const	{ return operator int_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 (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:    int_type m_val;   // value    int      m_len;   // length    int      m_ulen;  // unused length};// r-value concatenation operators and functionstemplate <class T1, class T2>inlinesc_int_concref_r<sc_int_base,sc_int_concref_r<T1,T2> >operator , ( const sc_int_base&, sc_int_concref_r<T1,T2> );inlinesc_int_concref_r<sc_int_base,sc_int_bitref_r>operator , ( const sc_int_base&, sc_int_bitref_r );inlinesc_int_concref_r<sc_int_base,sc_int_subref_r>operator , ( const sc_int_base&, sc_int_subref_r );inlinesc_int_concref_r<sc_int_base,sc_int_base>operator , ( const sc_int_base&, const sc_int_base& );inlinesc_int_concref_r<sc_int_base,sc_int_base>operator , ( const sc_int_base&, bool );inlinesc_int_concref_r<sc_int_base,sc_int_base>operator , ( bool, const sc_int_base& );template <class T1, class T2>inlinesc_int_concref_r<sc_int_base,sc_int_concref_r<T1,T2> >concat( const sc_int_base&, sc_int_concref_r<T1,T2> );inlinesc_int_concref_r<sc_int_base,sc_int_bitref_r>concat( const sc_int_base&, sc_int_bitref_r );inlinesc_int_concref_r<sc_int_base,sc_int_subref_r>concat( const sc_int_base&, sc_int_subref_r );inlinesc_int_concref_r<sc_int_base,sc_int_base>concat( const sc_int_base&, const sc_int_base& );inlinesc_int_concref_r<sc_int_base,sc_int_base>concat( const sc_int_base&, bool );inlinesc_int_concref_r<sc_int_base,sc_int_base>concat( bool, const sc_int_base& );#ifdef SC_DT_MIXED_COMMA_OPERATORStemplate <class T1, class T2>inlinesc_int_concref_r<sc_int_base,sc_int_concref_r<T1,T2> >operator , ( const sc_int_base&, sc_int_concref<T1,T2> );template <class T1, class T2>inlinesc_int_concref_r<sc_int_base,sc_int_concref_r<T1,T2> >operator , ( sc_int_base&, sc_int_concref_r<T1,T2> );

⌨️ 快捷键说明

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