00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef SC_BV_BASE_H
00052 #define SC_BV_BASE_H
00053
00054
00055 #include "sysc/datatypes/bit/sc_bit_ids.h"
00056 #include "sysc/datatypes/bit/sc_bit_proxies.h"
00057 #include "sysc/datatypes/bit/sc_proxy.h"
00058 #include "sysc/datatypes/int/sc_length_param.h"
00059
00060
00061 namespace sc_dt
00062 {
00063
00064
00065 class sc_bv_base;
00066
00067
00068
00069
00070
00071
00072
00073
00074 class sc_bv_base
00075 : public sc_proxy<sc_bv_base>
00076 {
00077 friend class sc_lv_base;
00078
00079
00080 void init( int length_, bool init_value = false );
00081
00082 void assign_from_string( const std::string& );
00083
00084 public:
00085
00086
00087
00088 typedef sc_proxy<sc_bv_base> base_type;
00089
00090
00091
00092
00093 explicit sc_bv_base( int length_ = sc_length_param().len() )
00094 : m_len( 0 ), m_size( 0 ), m_data( 0 )
00095 { init( length_ ); }
00096
00097 explicit sc_bv_base( bool a,
00098 int length_ = sc_length_param().len() )
00099 : m_len( 0 ), m_size( 0 ), m_data( 0 )
00100 { init( length_, a ); }
00101
00102 sc_bv_base( const char* a );
00103
00104 sc_bv_base( const char* a, int length_ );
00105
00106 template <class X>
00107 sc_bv_base( const sc_proxy<X>& a )
00108 : m_len( 0 ), m_size( 0 ), m_data( 0 )
00109 { init( a.back_cast().length() ); base_type::assign_( a ); }
00110
00111 sc_bv_base( const sc_bv_base& a );
00112
00113 #ifdef SC_DT_DEPRECATED
00114
00115 explicit sc_bv_base( const sc_unsigned& a )
00116 : m_len( 0 ), m_size( 0 ), m_data( 0 )
00117 { init( a.length() ); base_type::assign_( a ); }
00118
00119 explicit sc_bv_base( const sc_signed& a )
00120 : m_len( 0 ), m_size( 0 ), m_data( 0 )
00121 { init( a.length() ); base_type::assign_( a ); }
00122
00123 explicit sc_bv_base( const sc_uint_base& a)
00124 : m_len( 0 ), m_size( 0 ), m_data( 0 )
00125 { init( a.length() ); base_type::assign_( a ); }
00126
00127 explicit sc_bv_base( const sc_int_base& a)
00128 : m_len( 0 ), m_size( 0 ), m_data( 0 )
00129 { init( a.length() ); base_type::assign_( a ); }
00130
00131 #endif
00132
00133
00134
00135
00136 virtual ~sc_bv_base()
00137 { delete [] m_data; }
00138
00139
00140
00141
00142 template <class X>
00143 sc_bv_base& operator = ( const sc_proxy<X>& a )
00144 { assign_p_( *this, a ); return *this; }
00145
00146 sc_bv_base& operator = ( const sc_bv_base& a )
00147 { assign_p_( *this, a ); return *this; }
00148
00149 sc_bv_base& operator = ( const char* a );
00150
00151 sc_bv_base& operator = ( const bool* a )
00152 { base_type::assign_( a ); return *this; }
00153
00154 sc_bv_base& operator = ( const sc_logic* a )
00155 { base_type::assign_( a ); return *this; }
00156
00157 sc_bv_base& operator = ( const sc_unsigned& a )
00158 { base_type::assign_( a ); return *this; }
00159
00160 sc_bv_base& operator = ( const sc_signed& a )
00161 { base_type::assign_( a ); return *this; }
00162
00163 sc_bv_base& operator = ( const sc_uint_base& a )
00164 { base_type::assign_( a ); return *this; }
00165
00166 sc_bv_base& operator = ( const sc_int_base& a )
00167 { base_type::assign_( a ); return *this; }
00168
00169 sc_bv_base& operator = ( unsigned long a )
00170 { base_type::assign_( a ); return *this; }
00171
00172 sc_bv_base& operator = ( long a )
00173 { base_type::assign_( a ); return *this; }
00174
00175 sc_bv_base& operator = ( unsigned int a )
00176 { base_type::assign_( a ); return *this; }
00177
00178 sc_bv_base& operator = ( int a )
00179 { base_type::assign_( a ); return *this; }
00180
00181 sc_bv_base& operator = ( uint64 a )
00182 { base_type::assign_( a ); return *this; }
00183
00184 sc_bv_base& operator = ( int64 a )
00185 { base_type::assign_( a ); return *this; }
00186
00187
00188 #if 0
00189
00190
00191
00192 sc_bv_base& b_not();
00193
00194 const sc_bv_base operator ~ () const
00195 { sc_bv_base a( *this ); return a.b_not(); }
00196
00197
00198
00199
00200 sc_bv_base& operator <<= ( int n );
00201
00202 const sc_bv_base operator << ( int n ) const
00203 { sc_bv_base a( *this ); return ( a <<= n ); }
00204
00205
00206
00207
00208 sc_bv_base& operator >>= ( int n );
00209
00210 const sc_bv_base operator >> ( int n ) const
00211 { sc_bv_base a( *this ); return ( a >>= n ); }
00212
00213
00214
00215
00216 sc_bv_base& lrotate( int n );
00217
00218
00219
00220
00221 sc_bv_base& rrotate( int n );
00222
00223 #endif
00224
00225
00226
00227
00228 int length() const
00229 { return m_len; }
00230
00231 int size() const
00232 { return m_size; }
00233
00234 sc_logic_value_t get_bit( int i ) const;
00235 void set_bit( int i, sc_logic_value_t value );
00236
00237 sc_digit get_word( int i ) const
00238 { return m_data[i]; }
00239
00240 void set_word( int i, sc_digit w )
00241 { m_data[i] = w; }
00242
00243 sc_digit get_cword( int ) const
00244 { return SC_DIGIT_ZERO; }
00245
00246 void set_cword( int i, sc_digit w );
00247
00248 void clean_tail();
00249
00250
00251
00252
00253 bool is_01() const
00254 { return true; }
00255
00256 protected:
00257
00258 int m_len;
00259 int m_size;
00260 sc_digit* m_data;
00261 };
00262
00263
00264
00265
00266 #if 0
00267
00268
00269
00270 inline
00271 const sc_bv_base
00272 lrotate( const sc_bv_base& x, int n )
00273 {
00274 sc_bv_base a( x );
00275 return a.lrotate( n );
00276 }
00277
00278
00279
00280
00281 inline
00282 const sc_bv_base
00283 rrotate( const sc_bv_base& x, int n )
00284 {
00285 sc_bv_base a( x );
00286 return a.rrotate( n );
00287 }
00288
00289 #endif
00290
00291
00292
00293
00294 inline
00295 sc_logic_value_t
00296 sc_bv_base::get_bit( int i ) const
00297 {
00298 int wi = i / SC_DIGIT_SIZE;
00299 int bi = i % SC_DIGIT_SIZE;
00300 return sc_logic_value_t( (m_data[wi] >> bi) & SC_DIGIT_ONE );
00301 }
00302
00303 inline
00304 void
00305 sc_bv_base::set_bit( int i, sc_logic_value_t value )
00306 {
00307 int wi = i / SC_DIGIT_SIZE;
00308 int bi = i % SC_DIGIT_SIZE;
00309 sc_digit mask = SC_DIGIT_ONE << bi;
00310 m_data[wi] |= mask;
00311 m_data[wi] &= value << bi | ~mask;
00312 }
00313
00314
00315 inline
00316 void
00317 sc_bv_base::set_cword( int , sc_digit w )
00318 {
00319 if( w ) {
00320 SC_REPORT_WARNING( sc_core::SC_ID_SC_BV_CANNOT_CONTAIN_X_AND_Z_, 0 );
00321 }
00322 }
00323
00324
00325 inline
00326 void
00327 sc_bv_base::clean_tail()
00328 {
00329 int wi = m_size - 1;
00330 int bi = m_len % SC_DIGIT_SIZE;
00331 if ( bi != 0 ) m_data[wi] &= ~SC_DIGIT_ZERO >> (SC_DIGIT_SIZE - bi);
00332 }
00333
00334 }
00335
00336
00337 #endif