sc_bv_base.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2005 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_bv_base.h -- Arbitrary size bit vector class.
00021 
00022   Original Author: Gene Bushuyev, Synopsys, Inc.
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033 
00034  *****************************************************************************/
00035 
00036 #ifndef SC_BV_BASE_H
00037 #define SC_BV_BASE_H
00038 
00039 
00040 #include "sysc/datatypes/bit/sc_bit_ids.h"
00041 #include "sysc/datatypes/bit/sc_bit_proxies.h"
00042 #include "sysc/datatypes/bit/sc_proxy.h"
00043 #include "sysc/datatypes/int/sc_length_param.h"
00044 
00045 
00046 namespace sc_dt
00047 {
00048 
00049 // classes defined in this module
00050 class sc_bv_base;
00051 
00052 
00053 // ----------------------------------------------------------------------------
00054 //  CLASS : sc_bv_base
00055 //
00056 //  Arbitrary size bit vector base class.
00057 // ----------------------------------------------------------------------------
00058 
00059 class sc_bv_base
00060     : public sc_proxy<sc_bv_base>
00061 {
00062     friend class sc_lv_base;
00063 
00064 
00065     void init( int length_, bool init_value = false );
00066 
00067     void assign_from_string( const std::string& );
00068   
00069 public:
00070 
00071     // typedefs
00072 
00073     typedef sc_proxy<sc_bv_base> base_type;
00074 
00075 
00076     // constructors
00077 
00078     explicit sc_bv_base( int length_ = sc_length_param().len() )
00079         : m_len( 0 ), m_size( 0 ), m_data( 0 )
00080         { init( length_ ); }
00081 
00082     explicit sc_bv_base( bool a,
00083                          int length_ = sc_length_param().len() )
00084         : m_len( 0 ), m_size( 0 ), m_data( 0 )
00085         { init( length_, a ); }
00086 
00087     sc_bv_base( const char* a );
00088 
00089     sc_bv_base( const char* a, int length_ );
00090 
00091     template <class X>
00092     sc_bv_base( const sc_proxy<X>& a )
00093         : m_len( 0 ), m_size( 0 ), m_data( 0 )
00094         { init( a.back_cast().length() ); base_type::assign_( a ); }
00095 
00096     sc_bv_base( const sc_bv_base& a );
00097 
00098 #ifdef SC_DT_DEPRECATED
00099 
00100     explicit sc_bv_base( const sc_unsigned& a )
00101         : m_len( 0 ), m_size( 0 ), m_data( 0 )
00102         { init( a.length() ); base_type::assign_( a ); }
00103 
00104     explicit sc_bv_base( const sc_signed& a )
00105         : m_len( 0 ), m_size( 0 ), m_data( 0 )
00106         { init( a.length() ); base_type::assign_( a ); }
00107 
00108     explicit sc_bv_base( const sc_uint_base& a)
00109         : m_len( 0 ), m_size( 0 ), m_data( 0 )
00110         { init( a.length() ); base_type::assign_( a ); }
00111 
00112     explicit sc_bv_base( const sc_int_base& a)
00113         : m_len( 0 ), m_size( 0 ), m_data( 0 )
00114         { init( a.length() ); base_type::assign_( a ); }
00115 
00116 #endif
00117 
00118 
00119     // destructor
00120 
00121     virtual ~sc_bv_base()
00122         { if( m_data != 0 ) delete [] m_data; }
00123 
00124 
00125     // assignment operators
00126 
00127     template <class X>
00128     sc_bv_base& operator = ( const sc_proxy<X>& a )
00129         { assign_p_( *this, a ); return *this; }
00130 
00131     sc_bv_base& operator = ( const sc_bv_base& a )
00132         { assign_p_( *this, a ); return *this; }
00133 
00134     sc_bv_base& operator = ( const char* a );
00135 
00136     sc_bv_base& operator = ( const bool* a )
00137         { base_type::assign_( a ); return *this; }
00138 
00139     sc_bv_base& operator = ( const sc_logic* a )
00140         { base_type::assign_( a ); return *this; }
00141 
00142     sc_bv_base& operator = ( const sc_unsigned& a )
00143         { base_type::assign_( a ); return *this; }
00144 
00145     sc_bv_base& operator = ( const sc_signed& a )
00146         { base_type::assign_( a ); return *this; }
00147 
00148     sc_bv_base& operator = ( const sc_uint_base& a )
00149         { base_type::assign_( a ); return *this; }
00150 
00151     sc_bv_base& operator = ( const sc_int_base& a )
00152         { base_type::assign_( a ); return *this; }
00153 
00154     sc_bv_base& operator = ( unsigned long a )
00155         { base_type::assign_( a ); return *this; }
00156 
00157     sc_bv_base& operator = ( long a )
00158         { base_type::assign_( a ); return *this; }
00159 
00160     sc_bv_base& operator = ( unsigned int a )
00161         { base_type::assign_( a ); return *this; }
00162 
00163     sc_bv_base& operator = ( int a )
00164         { base_type::assign_( a ); return *this; }
00165 
00166     sc_bv_base& operator = ( uint64 a )
00167         { base_type::assign_( a ); return *this; }
00168 
00169     sc_bv_base& operator = ( int64 a )
00170         { base_type::assign_( a ); return *this; }
00171 
00172 
00173 #if 0
00174 
00175     // bitwise complement
00176 
00177     sc_bv_base& b_not();
00178 
00179     const sc_bv_base operator ~ () const
00180         { sc_bv_base a( *this ); return a.b_not(); }
00181 
00182 
00183     // bitwise left shift
00184 
00185     sc_bv_base& operator <<= ( int n );
00186 
00187     const sc_bv_base operator << ( int n ) const
00188         { sc_bv_base a( *this ); return ( a <<= n ); }
00189 
00190 
00191     // bitwise right shift
00192 
00193     sc_bv_base& operator >>= ( int n );
00194 
00195     const sc_bv_base operator >> ( int n ) const
00196         { sc_bv_base a( *this ); return ( a >>= n ); }
00197 
00198 
00199     // bitwise left rotate
00200 
00201     sc_bv_base& lrotate( int n );
00202 
00203 
00204     // bitwise right rotate
00205 
00206     sc_bv_base& rrotate( int n );
00207 
00208 #endif
00209 
00210 
00211     // common methods
00212 
00213     int length() const
00214         { return m_len; }
00215 
00216     int size() const
00217         { return m_size; }
00218 
00219     sc_logic_value_t get_bit( int i ) const;
00220     void set_bit( int i, sc_logic_value_t value );
00221 
00222     unsigned long get_word( int i ) const
00223         { return m_data[i]; }
00224 
00225     void set_word( int i, unsigned long w )
00226         { m_data[i] = w; }
00227 
00228     unsigned long get_cword( int i ) const
00229         { return UL_ZERO; }
00230 
00231     void set_cword( int i, unsigned long w );
00232 
00233     void clean_tail();
00234 
00235 
00236     // other methods
00237 
00238     bool is_01() const
00239         { return true; }
00240 
00241 protected:
00242 
00243     int            m_len;  // length in bits
00244     int            m_size; // size of data array
00245     unsigned long* m_data; // data array
00246 };
00247 
00248 
00249 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00250 
00251 #if 0
00252 
00253 // bitwise left rotate
00254 
00255 inline
00256 const sc_bv_base
00257 lrotate( const sc_bv_base& x, int n )
00258 {
00259     sc_bv_base a( x );
00260     return a.lrotate( n );
00261 }
00262 
00263 
00264 // bitwise right rotate
00265 
00266 inline
00267 const sc_bv_base
00268 rrotate( const sc_bv_base& x, int n )
00269 {
00270     sc_bv_base a( x );
00271     return a.rrotate( n );
00272 }
00273 
00274 #endif
00275 
00276 
00277 // common methods
00278 
00279 inline
00280 sc_logic_value_t
00281 sc_bv_base::get_bit( int i ) const
00282 {
00283     int wi = i / UL_SIZE;
00284     int bi = i % UL_SIZE;
00285     return sc_logic_value_t( m_data[wi] >> bi & UL_ONE );
00286 }
00287 
00288 inline
00289 void
00290 sc_bv_base::set_bit( int i, sc_logic_value_t value )
00291 {
00292     int wi = i / UL_SIZE;
00293     int bi = i % UL_SIZE;
00294     unsigned long mask = UL_ONE << bi;
00295     m_data[wi] |= mask; // set bit to 1
00296     m_data[wi] &= value << bi | ~mask;
00297 }
00298 
00299 
00300 inline
00301 void
00302 sc_bv_base::set_cword( int i, unsigned long w )
00303 {
00304     if( w ) {
00305         SC_REPORT_WARNING( sc_core::SC_ID_SC_BV_CANNOT_CONTAIN_X_AND_Z_, 0 );
00306     }
00307 }
00308 
00309 
00310 inline
00311 void
00312 sc_bv_base::clean_tail()
00313 {
00314     int wi = m_size - 1;
00315     int bi = m_len % UL_SIZE;
00316         if ( bi != 0 ) m_data[wi] &= ~UL_ZERO >> (UL_SIZE - bi);
00317 }
00318 
00319 } // namespace sc_dt
00320 
00321 
00322 #endif
Generated by
Matthieu Moy <Matthieu.Moy@st.com>
Back to Pinapa Home Page