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-2006 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 // $Log: sc_bv_base.h,v $
00037 // Revision 1.1.1.1  2006/12/15 20:31:36  acg
00038 // SystemC 2.2
00039 //
00040 // Revision 1.3  2006/01/13 18:53:53  acg
00041 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
00042 // the source.
00043 //
00044 
00045 #ifndef SC_BV_BASE_H
00046 #define SC_BV_BASE_H
00047 
00048 
00049 #include "sysc/datatypes/bit/sc_bit_ids.h"
00050 #include "sysc/datatypes/bit/sc_bit_proxies.h"
00051 #include "sysc/datatypes/bit/sc_proxy.h"
00052 #include "sysc/datatypes/int/sc_length_param.h"
00053 
00054 
00055 namespace sc_dt
00056 {
00057 
00058 // classes defined in this module
00059 class sc_bv_base;
00060 
00061 
00062 // ----------------------------------------------------------------------------
00063 //  CLASS : sc_bv_base
00064 //
00065 //  Arbitrary size bit vector base class.
00066 // ----------------------------------------------------------------------------
00067 
00068 class sc_bv_base
00069     : public sc_proxy<sc_bv_base>
00070 {
00071     friend class sc_lv_base;
00072 
00073 
00074     void init( int length_, bool init_value = false );
00075 
00076     void assign_from_string( const std::string& );
00077   
00078 public:
00079 
00080     // typedefs
00081 
00082     typedef sc_proxy<sc_bv_base> base_type;
00083 
00084 
00085     // constructors
00086 
00087     explicit sc_bv_base( int length_ = sc_length_param().len() )
00088     : m_len( 0 ), m_size( 0 ), m_data( 0 )
00089     { init( length_ ); }
00090 
00091     explicit sc_bv_base( bool a,
00092              int length_ = sc_length_param().len() )
00093     : m_len( 0 ), m_size( 0 ), m_data( 0 )
00094     { init( length_, a ); }
00095 
00096     sc_bv_base( const char* a );
00097 
00098     sc_bv_base( const char* a, int length_ );
00099 
00100     template <class X>
00101     sc_bv_base( const sc_proxy<X>& a )
00102     : m_len( 0 ), m_size( 0 ), m_data( 0 )
00103     { init( a.back_cast().length() ); base_type::assign_( a ); }
00104 
00105     sc_bv_base( const sc_bv_base& a );
00106 
00107 #ifdef SC_DT_DEPRECATED
00108 
00109     explicit sc_bv_base( const sc_unsigned& a )
00110     : m_len( 0 ), m_size( 0 ), m_data( 0 )
00111     { init( a.length() ); base_type::assign_( a ); }
00112 
00113     explicit sc_bv_base( const sc_signed& a )
00114     : m_len( 0 ), m_size( 0 ), m_data( 0 )
00115     { init( a.length() ); base_type::assign_( a ); }
00116 
00117     explicit sc_bv_base( const sc_uint_base& a)
00118     : m_len( 0 ), m_size( 0 ), m_data( 0 )
00119     { init( a.length() ); base_type::assign_( a ); }
00120 
00121     explicit sc_bv_base( const sc_int_base& a)
00122     : m_len( 0 ), m_size( 0 ), m_data( 0 )
00123     { init( a.length() ); base_type::assign_( a ); }
00124 
00125 #endif
00126 
00127 
00128     // destructor
00129 
00130     virtual ~sc_bv_base()
00131     { if( m_data != 0 ) delete [] m_data; }
00132 
00133 
00134     // assignment operators
00135 
00136     template <class X>
00137     sc_bv_base& operator = ( const sc_proxy<X>& a )
00138     { assign_p_( *this, a ); return *this; }
00139 
00140     sc_bv_base& operator = ( const sc_bv_base& a )
00141     { assign_p_( *this, a ); return *this; }
00142 
00143     sc_bv_base& operator = ( const char* a );
00144 
00145     sc_bv_base& operator = ( const bool* a )
00146     { base_type::assign_( a ); return *this; }
00147 
00148     sc_bv_base& operator = ( const sc_logic* a )
00149     { base_type::assign_( a ); return *this; }
00150 
00151     sc_bv_base& operator = ( const sc_unsigned& a )
00152     { base_type::assign_( a ); return *this; }
00153 
00154     sc_bv_base& operator = ( const sc_signed& a )
00155     { base_type::assign_( a ); return *this; }
00156 
00157     sc_bv_base& operator = ( const sc_uint_base& a )
00158     { base_type::assign_( a ); return *this; }
00159 
00160     sc_bv_base& operator = ( const sc_int_base& a )
00161     { base_type::assign_( a ); return *this; }
00162 
00163     sc_bv_base& operator = ( unsigned long a )
00164     { base_type::assign_( a ); return *this; }
00165 
00166     sc_bv_base& operator = ( long a )
00167     { base_type::assign_( a ); return *this; }
00168 
00169     sc_bv_base& operator = ( unsigned int a )
00170     { base_type::assign_( a ); return *this; }
00171 
00172     sc_bv_base& operator = ( int a )
00173     { base_type::assign_( a ); return *this; }
00174 
00175     sc_bv_base& operator = ( uint64 a )
00176     { base_type::assign_( a ); return *this; }
00177 
00178     sc_bv_base& operator = ( int64 a )
00179     { base_type::assign_( a ); return *this; }
00180 
00181 
00182 #if 0
00183 
00184     // bitwise complement
00185 
00186     sc_bv_base& b_not();
00187 
00188     const sc_bv_base operator ~ () const
00189     { sc_bv_base a( *this ); return a.b_not(); }
00190 
00191 
00192     // bitwise left shift
00193 
00194     sc_bv_base& operator <<= ( int n );
00195 
00196     const sc_bv_base operator << ( int n ) const
00197     { sc_bv_base a( *this ); return ( a <<= n ); }
00198 
00199 
00200     // bitwise right shift
00201 
00202     sc_bv_base& operator >>= ( int n );
00203 
00204     const sc_bv_base operator >> ( int n ) const
00205     { sc_bv_base a( *this ); return ( a >>= n ); }
00206 
00207 
00208     // bitwise left rotate
00209 
00210     sc_bv_base& lrotate( int n );
00211 
00212 
00213     // bitwise right rotate
00214 
00215     sc_bv_base& rrotate( int n );
00216 
00217 #endif
00218 
00219 
00220     // common methods
00221 
00222     int length() const
00223     { return m_len; }
00224 
00225     int size() const
00226     { return m_size; }
00227 
00228     sc_logic_value_t get_bit( int i ) const;
00229     void set_bit( int i, sc_logic_value_t value );
00230 
00231     sc_digit get_word( int i ) const
00232     { return m_data[i]; }
00233 
00234     void set_word( int i, sc_digit w )
00235     { m_data[i] = w; }
00236 
00237     sc_digit get_cword( int i ) const
00238     { return SC_DIGIT_ZERO; }
00239 
00240     void set_cword( int i, sc_digit w );
00241 
00242     void clean_tail();
00243 
00244 
00245     // other methods
00246 
00247     bool is_01() const
00248     { return true; }
00249 
00250 protected:
00251 
00252     int     m_len;  // length in bits
00253     int     m_size; // size of data array
00254     sc_digit* m_data; // data array
00255 };
00256 
00257 
00258 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00259 
00260 #if 0
00261 
00262 // bitwise left rotate
00263 
00264 inline
00265 const sc_bv_base
00266 lrotate( const sc_bv_base& x, int n )
00267 {
00268     sc_bv_base a( x );
00269     return a.lrotate( n );
00270 }
00271 
00272 
00273 // bitwise right rotate
00274 
00275 inline
00276 const sc_bv_base
00277 rrotate( const sc_bv_base& x, int n )
00278 {
00279     sc_bv_base a( x );
00280     return a.rrotate( n );
00281 }
00282 
00283 #endif
00284 
00285 
00286 // common methods
00287 
00288 inline
00289 sc_logic_value_t
00290 sc_bv_base::get_bit( int i ) const
00291 {
00292     int wi = i / SC_DIGIT_SIZE;
00293     int bi = i % SC_DIGIT_SIZE;
00294     return sc_logic_value_t( m_data[wi] >> bi & SC_DIGIT_ONE );
00295 }
00296 
00297 inline
00298 void
00299 sc_bv_base::set_bit( int i, sc_logic_value_t value )
00300 {
00301     int wi = i / SC_DIGIT_SIZE;
00302     int bi = i % SC_DIGIT_SIZE;
00303     sc_digit mask = SC_DIGIT_ONE << bi;
00304     m_data[wi] |= mask; // set bit to 1
00305     m_data[wi] &= value << bi | ~mask;
00306 }
00307 
00308 
00309 inline
00310 void
00311 sc_bv_base::set_cword( int i, sc_digit w )
00312 {
00313     if( w ) {
00314     SC_REPORT_WARNING( sc_core::SC_ID_SC_BV_CANNOT_CONTAIN_X_AND_Z_, 0 );
00315     }
00316 }
00317 
00318 
00319 inline
00320 void
00321 sc_bv_base::clean_tail()
00322 {
00323     int wi = m_size - 1;
00324     int bi = m_len % SC_DIGIT_SIZE;
00325     if ( bi != 0 ) m_data[wi] &= ~SC_DIGIT_ZERO >> (SC_DIGIT_SIZE - bi);
00326 }
00327 
00328 } // namespace sc_dt
00329 
00330 
00331 #endif

Generated on Wed Jan 21 15:32:07 2009 for SystemC by  doxygen 1.5.5