sc_lv_base.h

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

H
1,791
字号
/*****************************************************************************  The following code is derived, directly or indirectly, from the SystemC  source code Copyright (c) 1996-2002 by all Contributors.  All Rights reserved.  The contents of this file are subject to the restrictions and limitations  set forth in the SystemC Open Source License Version 2.3 (the "License");  You may not use this file except in compliance with such restrictions and  limitations. You may obtain instructions on how to receive a copy of the  License at http://www.systemc.org/. Software distributed by Contributors  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF  ANY KIND, either express or implied. See the License for the specific  language governing rights and limitations under the License. *****************************************************************************//*****************************************************************************  sc_lv_base.h -- Arbitrary size logic vector class.  Original Author: Gene Bushuyev, Synopsys, Inc. *****************************************************************************//*****************************************************************************  MODIFICATION LOG - modifiers, enter your name, affiliation, date and  changes you are making here.      Name, Affiliation, Date:  Description of Modification: *****************************************************************************/#ifndef SC_LV_BASE_H#define SC_LV_BASE_H#include "systemc/datatypes/bit/sc_bit_ids.h"#include "systemc/datatypes/bit/sc_bv_base.h"#include "systemc/datatypes/bit/sc_logic.h"#include "systemc/datatypes/int/sc_length_param.h"namespace sc_dt{// classes defined in this moduleclass sc_lv_base;// ----------------------------------------------------------------------------//  CLASS : sc_lv_base////  Arbitrary size logic vector base class.// ----------------------------------------------------------------------------class sc_lv_base    : public sc_proxy<sc_lv_base>{    friend class sc_bv_base;    void init( int length_, const sc_logic& init_value = SC_LOGIC_X );    void assign_from_string( const sc_string& );public:    // typedefs    typedef sc_proxy<sc_lv_base> base_type;    // constructors    explicit sc_lv_base( int length_ = sc_length_param().len() )	: m_len( 0 ), m_size( 0 ), m_data( 0 ), m_ctrl( 0 )	{ init( length_ ); }    explicit sc_lv_base( const sc_logic& a,			 int length_ = sc_length_param().len()  )	: m_len( 0 ), m_size( 0 ), m_data( 0 ), m_ctrl( 0 )	{ init( length_, a ); }    sc_lv_base( const char* a );    sc_lv_base( const char* a, int length_ );    template <class X>    sc_lv_base( const sc_proxy<X>& a )	: m_len( 0 ), m_size( 0 ), m_data( 0 ), m_ctrl( 0 )	{ init( a.back_cast().length() ); base_type::assign_( a ); }    sc_lv_base( const sc_lv_base& a );#ifdef SC_DT_DEPRECATED    explicit sc_lv_base( const sc_unsigned& a )	: m_len( 0 ), m_size( 0 ), m_data( 0 ), m_ctrl( 0 )	{ init( a.length() ); base_type::assign_( a ); }    explicit sc_lv_base( const sc_signed& a )	: m_len( 0 ), m_size( 0 ), m_data( 0 ), m_ctrl( 0 )	{ init( a.length() ); base_type::assign_( a ); }    explicit sc_lv_base( const sc_uint_base& a )	: m_len( 0 ), m_size( 0 ), m_data( 0 ), m_ctrl( 0 )	{ init( a.length() ); base_type::assign_( a ); }    explicit sc_lv_base( const sc_int_base& a )	: m_len( 0 ), m_size( 0 ), m_data( 0 ), m_ctrl( 0 )	{ init( a.length() ); base_type::assign_( a ); }#endif    // destructor    virtual ~sc_lv_base()	{ if( m_data != 0 ) delete [] m_data; }    // assignment operators    template <class X>    sc_lv_base& operator = ( const sc_proxy<X>& a )	{ assign_p_( *this, a ); return *this; }    sc_lv_base& operator = ( const sc_lv_base& a )	{ assign_p_( *this, a ); return *this; }    sc_lv_base& operator = ( const char* a );    sc_lv_base& operator = ( const bool* a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( const sc_logic* a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( const sc_unsigned& a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( const sc_signed& a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( const sc_uint_base& a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( const sc_int_base& a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( unsigned long a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( long a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( unsigned int a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( int a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( uint64 a )	{ base_type::assign_( a ); return *this; }    sc_lv_base& operator = ( int64 a )	{ base_type::assign_( a ); return *this; }#if 0    // bitwise complement    sc_lv_base& b_not()	{ return sc_proxy<sc_lv_base>::b_not(); }    const sc_lv_base operator ~ () const	{ sc_lv_base a( *this ); return a.b_not(); }    // bitwise left shift    sc_lv_base& operator <<= ( int n )	{ return sc_proxy<sc_lv_base>::operator <<= ( n ); }    const sc_lv_base operator << ( int n ) const	{ sc_lv_base a( *this ); return ( a <<= n ); }    // bitwise right shift    sc_lv_base& operator >>= ( int n )	{ return sc_proxy<sc_lv_base>::operator >>= ( n ); }    const sc_lv_base operator >> ( int n ) const	{ sc_lv_base a( *this ); return ( a >>= n ); }    // bitwise left rotate    sc_lv_base& lrotate( int n )	{ return sc_proxy<sc_lv_base>::lrotate( n ); }    // bitwise right rotate    sc_lv_base& rrotate( int n )	{ return sc_proxy<sc_lv_base>::rrotate( n ); }#endif    // common methods    int length() const	{ return m_len; }    int size() const	{ return m_size; }    sc_logic_value_t get_bit( int i ) const;    void set_bit( int i, sc_logic_value_t value );    unsigned long get_word( int wi ) const	{ return m_data[wi]; }    void set_word( int wi, unsigned long w )	{ m_data[wi] = w; }    unsigned long get_cword( int wi ) const	{ return m_ctrl[wi]; }    void set_cword( int wi, unsigned long w )	{ m_ctrl[wi] = w; }    void clean_tail();    // other methods    bool is_01() const;protected:    int            m_len;   // length in bits    int            m_size;  // size of the data array    unsigned long* m_data;  // data array    unsigned long* m_ctrl;  // dito (control part)};// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII#if 0// bitwise left rotateinlineconst sc_lv_baselrotate( const sc_lv_base& x, int n ){    sc_lv_base a( x );    return a.lrotate( n );}// bitwise right rotateinlineconst sc_lv_baserrotate( const sc_lv_base& x, int n ){    sc_lv_base a( x );    return a.rrotate( n );}#endifinlinesc_logic_value_tsc_lv_base::get_bit( int i ) const{    int wi = i / UL_SIZE;    int bi = i % UL_SIZE;    return sc_logic_value_t( m_data[wi] >> bi & UL_ONE |			     m_ctrl[wi] >> bi << 1 & UL_TWO );}inlinevoidsc_lv_base::set_bit( int i, sc_logic_value_t value ){    int wi = i / UL_SIZE; // word index    int bi = i % UL_SIZE; // bit index    unsigned long mask = UL_ONE << bi;    m_data[wi] |= mask; // set bit to 1    m_ctrl[wi] |= mask; // set bit to 1    m_data[wi] &= value << bi | ~mask;    m_ctrl[wi] &= value >> 1 << bi | ~mask;}inlinevoidsc_lv_base::clean_tail(){    int wi = m_size - 1;    int bi = m_len % UL_SIZE;    unsigned long mask = ~UL_ZERO >> (UL_SIZE - bi);    m_data[wi] &= mask;    m_ctrl[wi] &= mask;}// ----------------------------------------------------------------------------//  CLASS TEMPLATE : sc_proxy////  Base class template for bit/logic vector classes.//  (Barton/Nackmann implementation)// ----------------------------------------------------------------------------// bitwise operators and functions// bitwise complementtemplate <class X>inlineconst sc_lv_basesc_proxy<X>::operator ~ () const{    sc_lv_base a( back_cast() );    return a.b_not();}// bitwise andtemplate <class X, class Y>inlineX&operator &= ( sc_proxy<X>& px, const sc_proxy<Y>& py ){    X& x = px.back_cast();    sc_lv_base a( x.length() );    a = py.back_cast();    return b_and_assign_( x, a );}#define DEFN_BITWISE_AND_ASN_OP_T(tp)                                         \template <class X>                                                            \inline                                                                        \X&                                                                            \sc_proxy<X>::operator &= ( tp b )                                             \{                                                                             \    X& x = back_cast();                                                       \    sc_lv_base a( x.length() );                                               \    a = b;                                                                    \    return b_and_assign_( x, a );                                             \}DEFN_BITWISE_AND_ASN_OP_T(const char*)DEFN_BITWISE_AND_ASN_OP_T(const bool*)DEFN_BITWISE_AND_ASN_OP_T(const sc_logic*)DEFN_BITWISE_AND_ASN_OP_T(const sc_unsigned&)DEFN_BITWISE_AND_ASN_OP_T(const sc_signed&)DEFN_BITWISE_AND_ASN_OP_T(unsigned long)DEFN_BITWISE_AND_ASN_OP_T(long)DEFN_BITWISE_AND_ASN_OP_T(uint64)DEFN_BITWISE_AND_ASN_OP_T(int64)#undef DEFN_BITWISE_AND_ASN_OP_Ttemplate <class X, class Y>inlineconst sc_lv_baseoperator & ( const sc_proxy<X>& px, const sc_proxy<Y>& py ){    sc_lv_base a( px.back_cast() );    return ( a &= py.back_cast() );}#define DEFN_BITWISE_AND_OP_T_A(tp)                                           \template <class X>                                                            \inline                                                                        \const sc_lv_base                                                              \sc_proxy<X>::operator & ( tp b ) const                                        \{                                                                             \    sc_lv_base a( back_cast() );                                              \    return ( a &= b );                                                        \}DEFN_BITWISE_AND_OP_T_A(const char*)DEFN_BITWISE_AND_OP_T_A(const bool*)DEFN_BITWISE_AND_OP_T_A(const sc_logic*)DEFN_BITWISE_AND_OP_T_A(const sc_unsigned&)DEFN_BITWISE_AND_OP_T_A(const sc_signed&)DEFN_BITWISE_AND_OP_T_A(const sc_uint_base&)DEFN_BITWISE_AND_OP_T_A(const sc_int_base&)DEFN_BITWISE_AND_OP_T_A(unsigned long)DEFN_BITWISE_AND_OP_T_A(long)DEFN_BITWISE_AND_OP_T_A(unsigned int)DEFN_BITWISE_AND_OP_T_A(int)DEFN_BITWISE_AND_OP_T_A(uint64)DEFN_BITWISE_AND_OP_T_A(int64)#undef DEFN_BITWISE_AND_OP_T_A#define DEFN_BITWISE_AND_OP_T_B(tp)                                           \template <class X>                                                            \inline                                                                        \const sc_lv_base                                                              \operator & ( tp b, const sc_proxy<X>& px )                                    \{                                                                             \    return ( px & b );                                                        \}DEFN_BITWISE_AND_OP_T_B(const char*)DEFN_BITWISE_AND_OP_T_B(const bool*)DEFN_BITWISE_AND_OP_T_B(const sc_logic*)DEFN_BITWISE_AND_OP_T_B(const sc_unsigned&)DEFN_BITWISE_AND_OP_T_B(const sc_signed&)DEFN_BITWISE_AND_OP_T_B(const sc_uint_base&)DEFN_BITWISE_AND_OP_T_B(const sc_int_base&)DEFN_BITWISE_AND_OP_T_B(unsigned long)DEFN_BITWISE_AND_OP_T_B(long)DEFN_BITWISE_AND_OP_T_B(unsigned int)DEFN_BITWISE_AND_OP_T_B(int)DEFN_BITWISE_AND_OP_T_B(uint64)DEFN_BITWISE_AND_OP_T_B(int64)#undef DEFN_BITWISE_AND_OP_T_B// bitwise ortemplate <class X, class Y>inlineX&operator |= ( sc_proxy<X>& px, const sc_proxy<Y>& py ){

⌨️ 快捷键说明

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