SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_bv_base.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_bv_base.h -- Arbitrary size bit vector class.
23 */
32 /*****************************************************************************
33 
34  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
35  changes you are making here.
36 
37  Name, Affiliation, Date:
38  Description of Modification:
39 
40  *****************************************************************************/
41 
42 // $Log: sc_bv_base.h,v $
43 // Revision 1.3 2011/08/26 22:32:00 acg
44 // Torsten Maehne: added parentheses to make opearator ordering more obvious.
45 //
46 // Revision 1.2 2011/08/15 16:43:24 acg
47 // Torsten Maehne: changes to remove unused argument warnings.
48 //
49 // Revision 1.1.1.1 2006/12/15 20:20:04 acg
50 // SystemC 2.3
51 //
52 // Revision 1.3 2006/01/13 18:53:53 acg
53 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
54 // the source.
55 //
56 
57 #ifndef SC_BV_BASE_H
58 #define SC_BV_BASE_H
59 
60 
65 
66 
67 namespace sc_dt
68 {
69 
70 // classes defined in this module
71 class sc_bv_base;
72 
73 
81  : public sc_proxy<sc_bv_base>
82 {
83  friend class sc_lv_base;
84 
85 
86  void init( int length_, bool init_value = false );
87 
88  void assign_from_string( const std::string& );
89 
90 public:
91 
92  // typedefs
93 
95  typedef base_type::value_type value_type;
96 
97 
98  // constructors
99 
100  explicit sc_bv_base( int length_ = sc_length_param().len() )
101  : m_len( 0 ), m_size( 0 ), m_data( 0 )
102  { init( length_ ); }
103 
104  explicit sc_bv_base( bool a,
105  int length_ = sc_length_param().len() )
106  : m_len( 0 ), m_size( 0 ), m_data( 0 )
107  { init( length_, a ); }
108 
109  sc_bv_base( const char* a );
110 
111  sc_bv_base( const char* a, int length_ );
112 
113  template <class X>
115  : m_len( 0 ), m_size( 0 ), m_data( 0 )
116  { init( a.back_cast().length() ); base_type::assign_( a ); }
117 
118  sc_bv_base( const sc_bv_base& a );
119 
120 #ifdef SC_DT_DEPRECATED
121 
122  explicit sc_bv_base( const sc_unsigned& a )
123  : m_len( 0 ), m_size( 0 ), m_data( 0 )
124  { init( a.length() ); base_type::assign_( a ); }
125 
126  explicit sc_bv_base( const sc_signed& a )
127  : m_len( 0 ), m_size( 0 ), m_data( 0 )
128  { init( a.length() ); base_type::assign_( a ); }
129 
130  explicit sc_bv_base( const sc_uint_base& a)
131  : m_len( 0 ), m_size( 0 ), m_data( 0 )
132  { init( a.length() ); base_type::assign_( a ); }
133 
134  explicit sc_bv_base( const sc_int_base& a)
135  : m_len( 0 ), m_size( 0 ), m_data( 0 )
136  { init( a.length() ); base_type::assign_( a ); }
137 
138 #endif
139 
140 
141  // destructor
142 
143  virtual ~sc_bv_base()
144  { delete [] m_data; }
145 
146 
147  // assignment operators
148 
149  template <class X>
150  sc_bv_base& operator = ( const sc_proxy<X>& a )
151  { assign_p_( *this, a ); return *this; }
152 
153  sc_bv_base& operator = ( const sc_bv_base& a )
154  { assign_p_( *this, a ); return *this; }
155 
156  sc_bv_base& operator = ( const char* a );
157 
158  sc_bv_base& operator = ( const bool* a )
159  { base_type::assign_( a ); return *this; }
160 
161  sc_bv_base& operator = ( const sc_logic* a )
162  { base_type::assign_( a ); return *this; }
163 
164  sc_bv_base& operator = ( const sc_unsigned& a )
165  { base_type::assign_( a ); return *this; }
166 
167  sc_bv_base& operator = ( const sc_signed& a )
168  { base_type::assign_( a ); return *this; }
169 
170  sc_bv_base& operator = ( const sc_uint_base& a )
171  { base_type::assign_( a ); return *this; }
172 
173  sc_bv_base& operator = ( const sc_int_base& a )
174  { base_type::assign_( a ); return *this; }
175 
176  sc_bv_base& operator = ( unsigned long a )
177  { base_type::assign_( a ); return *this; }
178 
179  sc_bv_base& operator = ( long a )
180  { base_type::assign_( a ); return *this; }
181 
182  sc_bv_base& operator = ( unsigned int a )
183  { base_type::assign_( a ); return *this; }
184 
185  sc_bv_base& operator = ( int a )
186  { base_type::assign_( a ); return *this; }
187 
188  sc_bv_base& operator = ( uint64 a )
189  { base_type::assign_( a ); return *this; }
190 
191  sc_bv_base& operator = ( int64 a )
192  { base_type::assign_( a ); return *this; }
193 
194 
195  // common methods
196 
197  int length() const
198  { return m_len; }
199 
200  int size() const
201  { return m_size; }
202 
203  value_type get_bit( int i ) const;
204  void set_bit( int i, value_type value );
205 
206  sc_digit get_word( int i ) const
207  { return m_data[i]; }
208 
209  void set_word( int i, sc_digit w )
210  { m_data[i] = w; }
211 
212  sc_digit get_cword( int /*i*/ ) const
213  { return SC_DIGIT_ZERO; }
214 
215  void set_cword( int i, sc_digit w );
216 
217  void clean_tail();
218 
219 
220  // other methods
221 
222  bool is_01() const
223  { return true; }
224 
225 protected:
226 
227  int m_len; // length in bits
228  int m_size; // size of data array
229  sc_digit* m_data; // data array
230 };
231 
232 
233 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
234 
235 #if 0
236 
237 // bitwise left rotate
238 
239 inline
240 const sc_bv_base
241 lrotate( const sc_bv_base& x, int n )
242 {
243  sc_bv_base a( x );
244  return a.lrotate( n );
245 }
246 
247 
248 // bitwise right rotate
249 
250 inline
251 const sc_bv_base
252 rrotate( const sc_bv_base& x, int n )
253 {
254  sc_bv_base a( x );
255  return a.rrotate( n );
256 }
257 
258 #endif
259 
260 
261 // common methods
262 
263 inline
265 sc_bv_base::get_bit( int i ) const
266 {
267  int wi = i / SC_DIGIT_SIZE;
268  int bi = i % SC_DIGIT_SIZE;
269  return value_type( (m_data[wi] >> bi) & SC_DIGIT_ONE );
270 }
271 
272 inline
273 void
274 sc_bv_base::set_bit( int i, value_type value )
275 {
276  int wi = i / SC_DIGIT_SIZE;
277  int bi = i % SC_DIGIT_SIZE;
278  sc_digit mask = SC_DIGIT_ONE << bi;
279  m_data[wi] |= mask; // set bit to 1
280  m_data[wi] &= value << bi | ~mask;
281 }
282 
283 
284 inline
285 void
287 {
288  if( w ) {
289  SC_REPORT_WARNING( sc_core::SC_ID_SC_BV_CANNOT_CONTAIN_X_AND_Z_, 0 );
290  }
291 }
292 
293 
294 inline
295 void
297 {
298  int wi = m_size - 1;
299  int bi = m_len % SC_DIGIT_SIZE;
300  if ( bi != 0 ) m_data[wi] &= ~SC_DIGIT_ZERO >> (SC_DIGIT_SIZE - bi);
301 }
302 
303 } // namespace sc_dt
304 
305 
306 #endif
sc_bv_base(const sc_proxy< X > &a)
Definition: sc_bv_base.h:114
int length() const
Definition: sc_bv_base.h:197
X & lrotate(int n)
Definition: sc_lv_base.h:673
int length() const
Definition: sc_uint_base.h:762
sc_digit * m_data
Definition: sc_bv_base.h:229
const int SC_DIGIT_SIZE
Definition: sc_proxy.h:97
void set_bit(int i, value_type value)
Definition: sc_bv_base.h:274
void set_word(int i, sc_digit w)
Definition: sc_bv_base.h:209
int length() const
Definition: sc_unsigned.h:1244
int64_t int64
Definition: sc_nbdefs.h:188
Base class for sc_uint.
Definition: sc_uint_base.h:534
Arbitrary precision signed number.
Definition: sc_signed.h:1099
const sc_digit SC_DIGIT_ONE
Definition: sc_proxy.h:100
Base class template for bit/logic vector classes.
Definition: sc_proxy.h:84
uint64_t uint64
Definition: sc_nbdefs.h:189
Arbitrary precision unsigned number.
Definition: sc_unsigned.h:1001
Four-valued logic type.
Definition: sc_logic.h:104
value_type get_bit(int i) const
Definition: sc_bv_base.h:265
unsigned int sc_digit
Definition: sc_nbdefs.h:179
int length() const
Definition: sc_signed.h:1342
Base class for sc_int.
Definition: sc_int_base.h:548
const sc_lv_base lrotate(const sc_proxy< X > &x, int n)
Definition: sc_lv_base.h:698
Arbitrary size logic vector base class.
Definition: sc_lv_base.h:91
#define SC_REPORT_WARNING(msg_type, msg)
Definition: sc_report.h:218
virtual ~sc_bv_base()
Definition: sc_bv_base.h:143
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
base_type::value_type value_type
Definition: sc_bv_base.h:95
X & back_cast()
Definition: sc_proxy.h:213
bool is_01() const
Definition: sc_bv_base.h:222
Length parameter type.
Report ids for the datatypes/bit code.
const sc_digit SC_DIGIT_ZERO
Definition: sc_proxy.h:99
sc_bv_base(int length_=sc_length_param().len())
Definition: sc_bv_base.h:100
sc_bv_base(bool a, int length_=sc_length_param().len())
Definition: sc_bv_base.h:104
int size() const
Definition: sc_bv_base.h:200
sc_digit get_word(int i) const
Definition: sc_bv_base.h:206
void assign_p_(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_proxy.h:745
int length() const
Definition: sc_int_base.h:777
Proxy classes for vector data types.
X & rrotate(int n)
Definition: sc_lv_base.h:710
const sc_lv_base rrotate(const sc_proxy< X > &x, int n)
Definition: sc_lv_base.h:735
sc_digit get_cword(int) const
Definition: sc_bv_base.h:212
sc_proxy< sc_bv_base > base_type
Definition: sc_bv_base.h:94
Arbitrary size bit vector base class.
Definition: sc_bv_base.h:80
#define SC_API
Definition: sc_cmnhdr.h:168
void set_cword(int i, sc_digit w)
Definition: sc_bv_base.h:286
Proxy base class for vector data types.