SystemC  2.3.1
Accellera SystemC proof-of-concept library
sc_bv_base.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_bv_base.h -- Arbitrary size bit vector class.
21 
22  Original Author: Gene Bushuyev, Synopsys, Inc.
23 
24  *****************************************************************************/
25 
26 /*****************************************************************************
27 
28  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
29  changes you are making here.
30 
31  Name, Affiliation, Date:
32  Description of Modification:
33 
34  *****************************************************************************/
35 
36 // $Log: sc_bv_base.h,v $
37 // Revision 1.3 2011/08/26 22:32:00 acg
38 // Torsten Maehne: added parentheses to make opearator ordering more obvious.
39 //
40 // Revision 1.2 2011/08/15 16:43:24 acg
41 // Torsten Maehne: changes to remove unused argument warnings.
42 //
43 // Revision 1.1.1.1 2006/12/15 20:20:04 acg
44 // SystemC 2.3
45 //
46 // Revision 1.3 2006/01/13 18:53:53 acg
47 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
48 // the source.
49 //
50 
51 #ifndef SC_BV_BASE_H
52 #define SC_BV_BASE_H
53 
54 
59 
60 
61 namespace sc_dt
62 {
63 
64 // classes defined in this module
65 class sc_bv_base;
66 
67 
68 // ----------------------------------------------------------------------------
69 // CLASS : sc_bv_base
70 //
71 // Arbitrary size bit vector base class.
72 // ----------------------------------------------------------------------------
73 
75  : public sc_proxy<sc_bv_base>
76 {
77  friend class sc_lv_base;
78 
79 
80  void init( int length_, bool init_value = false );
81 
82  void assign_from_string( const std::string& );
83 
84 public:
85 
86  // typedefs
87 
89 
90 
91  // constructors
92 
93  explicit sc_bv_base( int length_ = sc_length_param().len() )
94  : m_len( 0 ), m_size( 0 ), m_data( 0 )
95  { init( length_ ); }
96 
97  explicit sc_bv_base( bool a,
98  int length_ = sc_length_param().len() )
99  : m_len( 0 ), m_size( 0 ), m_data( 0 )
100  { init( length_, a ); }
101 
102  sc_bv_base( const char* a );
103 
104  sc_bv_base( const char* a, int length_ );
105 
106  template <class X>
108  : m_len( 0 ), m_size( 0 ), m_data( 0 )
109  { init( a.back_cast().length() ); base_type::assign_( a ); }
110 
111  sc_bv_base( const sc_bv_base& a );
112 
113 #ifdef SC_DT_DEPRECATED
114 
115  explicit sc_bv_base( const sc_unsigned& a )
116  : m_len( 0 ), m_size( 0 ), m_data( 0 )
117  { init( a.length() ); base_type::assign_( a ); }
118 
119  explicit sc_bv_base( const sc_signed& a )
120  : m_len( 0 ), m_size( 0 ), m_data( 0 )
121  { init( a.length() ); base_type::assign_( a ); }
122 
123  explicit sc_bv_base( const sc_uint_base& a)
124  : m_len( 0 ), m_size( 0 ), m_data( 0 )
125  { init( a.length() ); base_type::assign_( a ); }
126 
127  explicit sc_bv_base( const sc_int_base& a)
128  : m_len( 0 ), m_size( 0 ), m_data( 0 )
129  { init( a.length() ); base_type::assign_( a ); }
130 
131 #endif
132 
133 
134  // destructor
135 
136  virtual ~sc_bv_base()
137  { delete [] m_data; }
138 
139 
140  // assignment operators
141 
142  template <class X>
144  { assign_p_( *this, a ); return *this; }
145 
147  { assign_p_( *this, a ); return *this; }
148 
149  sc_bv_base& operator = ( const char* a );
150 
151  sc_bv_base& operator = ( const bool* a )
152  { base_type::assign_( a ); return *this; }
153 
155  { base_type::assign_( a ); return *this; }
156 
158  { base_type::assign_( a ); return *this; }
159 
161  { base_type::assign_( a ); return *this; }
162 
164  { base_type::assign_( a ); return *this; }
165 
167  { base_type::assign_( a ); return *this; }
168 
169  sc_bv_base& operator = ( unsigned long a )
170  { base_type::assign_( a ); return *this; }
171 
173  { base_type::assign_( a ); return *this; }
174 
175  sc_bv_base& operator = ( unsigned int a )
176  { base_type::assign_( a ); return *this; }
177 
179  { base_type::assign_( a ); return *this; }
180 
182  { base_type::assign_( a ); return *this; }
183 
185  { base_type::assign_( a ); return *this; }
186 
187 
188 #if 0
189 
190  // bitwise complement
191 
192  sc_bv_base& b_not();
193 
194  const sc_bv_base operator ~ () const
195  { sc_bv_base a( *this ); return a.b_not(); }
196 
197 
198  // bitwise left shift
199 
200  sc_bv_base& operator <<= ( int n );
201 
202  const sc_bv_base operator << ( int n ) const
203  { sc_bv_base a( *this ); return ( a <<= n ); }
204 
205 
206  // bitwise right shift
207 
208  sc_bv_base& operator >>= ( int n );
209 
210  const sc_bv_base operator >> ( int n ) const
211  { sc_bv_base a( *this ); return ( a >>= n ); }
212 
213 
214  // bitwise left rotate
215 
216  sc_bv_base& lrotate( int n );
217 
218 
219  // bitwise right rotate
220 
221  sc_bv_base& rrotate( int n );
222 
223 #endif
224 
225 
226  // common methods
227 
228  int length() const
229  { return m_len; }
230 
231  int size() const
232  { return m_size; }
233 
234  sc_logic_value_t get_bit( int i ) const;
235  void set_bit( int i, sc_logic_value_t value );
236 
237  sc_digit get_word( int i ) const
238  { return m_data[i]; }
239 
240  void set_word( int i, sc_digit w )
241  { m_data[i] = w; }
242 
243  sc_digit get_cword( int /*i*/ ) const
244  { return SC_DIGIT_ZERO; }
245 
246  void set_cword( int i, sc_digit w );
247 
248  void clean_tail();
249 
250 
251  // other methods
252 
253  bool is_01() const
254  { return true; }
255 
256 protected:
257 
258  int m_len; // length in bits
259  int m_size; // size of data array
260  sc_digit* m_data; // data array
261 };
262 
263 
264 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
265 
266 #if 0
267 
268 // bitwise left rotate
269 
270 inline
271 const sc_bv_base
272 lrotate( const sc_bv_base& x, int n )
273 {
274  sc_bv_base a( x );
275  return a.lrotate( n );
276 }
277 
278 
279 // bitwise right rotate
280 
281 inline
282 const sc_bv_base
283 rrotate( const sc_bv_base& x, int n )
284 {
285  sc_bv_base a( x );
286  return a.rrotate( n );
287 }
288 
289 #endif
290 
291 
292 // common methods
293 
294 inline
296 sc_bv_base::get_bit( int i ) const
297 {
298  int wi = i / SC_DIGIT_SIZE;
299  int bi = i % SC_DIGIT_SIZE;
300  return sc_logic_value_t( (m_data[wi] >> bi) & SC_DIGIT_ONE );
301 }
302 
303 inline
304 void
306 {
307  int wi = i / SC_DIGIT_SIZE;
308  int bi = i % SC_DIGIT_SIZE;
309  sc_digit mask = SC_DIGIT_ONE << bi;
310  m_data[wi] |= mask; // set bit to 1
311  m_data[wi] &= value << bi | ~mask;
312 }
313 
314 
315 inline
316 void
318 {
319  if( w ) {
320  SC_REPORT_WARNING( sc_core::SC_ID_SC_BV_CANNOT_CONTAIN_X_AND_Z_, 0 );
321  }
322 }
323 
324 
325 inline
326 void
328 {
329  int wi = m_size - 1;
330  int bi = m_len % SC_DIGIT_SIZE;
331  if ( bi != 0 ) m_data[wi] &= ~SC_DIGIT_ZERO >> (SC_DIGIT_SIZE - bi);
332 }
333 
334 } // namespace sc_dt
335 
336 
337 #endif
const sc_lv_base rrotate(const sc_proxy< X > &x, int n)
Definition: sc_lv_base.h:776
sc_bv_base & assign_(const sc_proxy< Y > &a)
Definition: sc_proxy.h:218
sc_bv_base & operator=(const sc_proxy< X > &a)
Definition: sc_bv_base.h:143
const sc_lv_base operator~() const
unsigned int sc_digit
Definition: sc_nbdefs.h:173
const sc_digit SC_DIGIT_ONE
Definition: sc_proxy.h:95
uint64_t uint64
Definition: sc_nbdefs.h:183
const int SC_DIGIT_SIZE
Definition: sc_proxy.h:92
void set_bit(int i, sc_logic_value_t value)
Definition: sc_bv_base.h:305
sc_clock period is zero sc_clock low time is zero sc_fifo< T > cannot have more than one writer bind interface to port failed complete binding failed remove port failed insert primitive channel failed sc_signal< T > cannot have more than one driver resolved port not bound to resolved signal sc_semaphore requires an initial value
#define SC_REPORT_WARNING(msg_type, msg)
Definition: sc_report.h:209
const sc_lv_base lrotate(const sc_proxy< X > &x, int n)
Definition: sc_lv_base.h:737
int length() const
Definition: sc_bv_base.h:228
int64_t int64
Definition: sc_nbdefs.h:182
sc_bv_base(bool a, int length_=sc_length_param().len())
Definition: sc_bv_base.h:97
const sc_lv_base operator<<(int n) const
void set_cword(int i, sc_digit w)
Definition: sc_bv_base.h:317
sc_bv_base & operator>>=(int n)
void assign_p_(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_proxy.h:742
sc_bv_base & operator<<=(int n)
sc_logic_value_t
Definition: sc_logic.h:85
void set_word(int i, sc_digit w)
Definition: sc_bv_base.h:240
const sc_lv_base operator>>(int n) const
sc_digit get_cword(int) const
Definition: sc_bv_base.h:243
int length() const
Definition: sc_unsigned.h:1226
sc_bv_base & lrotate(int n)
bool is_01() const
Definition: sc_bv_base.h:253
sc_digit get_word(int i) const
Definition: sc_bv_base.h:237
sc_bv_base & rrotate(int n)
int size() const
Definition: sc_bv_base.h:231
virtual ~sc_bv_base()
Definition: sc_bv_base.h:136
sc_proxy< sc_bv_base > base_type
Definition: sc_bv_base.h:88
X & back_cast()
Definition: sc_proxy.h:208
sc_bv_base(int length_=sc_length_param().len())
Definition: sc_bv_base.h:93
sc_bv_base(const sc_proxy< X > &a)
Definition: sc_bv_base.h:107
sc_digit * m_data
Definition: sc_bv_base.h:260
const sc_digit SC_DIGIT_ZERO
Definition: sc_proxy.h:94
sc_logic_value_t get_bit(int i) const
Definition: sc_bv_base.h:296