📄 sc_lv_base.h
字号:
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2006 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.4 (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: Andy Goodrich, Forte Design Systems Fixed bug in clean_tail for sizes that are modulo 32, which caused zeroing of values. *****************************************************************************/// $Log: sc_lv_base.h,v $// Revision 1.2 2007/03/14 17:47:49 acg// Andy Goodrich: Formatting.//// Revision 1.1.1.1 2006/12/15 20:31:36 acg// SystemC 2.2//// Revision 1.3 2006/01/13 18:53:53 acg// Andy Goodrich: added $Log command so that CVS comments are reproduced in// the source.//#ifndef SC_LV_BASE_H#define SC_LV_BASE_H#include "sysc/datatypes/bit/sc_bit_ids.h"#include "sysc/datatypes/bit/sc_bv_base.h"#include "sysc/datatypes/bit/sc_logic.h"#include "sysc/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 std::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 ); sc_digit get_word( int wi ) const { return m_data[wi]; } // note the test for out of range access here. this is necessary // because of the hair-brained way concatenations are set up. // an extend_sign on a concatenation uses the whole length of // the concatenation to determine how many words to set. void set_word( int wi, sc_digit w ) { assert ( wi < m_size ); m_data[wi] = w; } sc_digit get_cword( int wi ) const { return m_ctrl[wi]; } void set_cword( int wi, sc_digit w ) { assert ( wi < m_size ); 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 sc_digit* m_data; // data array sc_digit* 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 / SC_DIGIT_SIZE; int bi = i % SC_DIGIT_SIZE; return sc_logic_value_t( m_data[wi] >> bi & SC_DIGIT_ONE | m_ctrl[wi] >> bi << 1 & SC_DIGIT_TWO );}inlinevoidsc_lv_base::set_bit( int i, sc_logic_value_t value ){ int wi = i / SC_DIGIT_SIZE; // word index int bi = i % SC_DIGIT_SIZE; // bit index sc_digit mask = SC_DIGIT_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 % SC_DIGIT_SIZE; sc_digit mask = ~SC_DIGIT_ZERO >> (SC_DIGIT_SIZE - bi); if ( mask ) { 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&)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -