SystemC 3.0.0
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
24 Original Author: Gene Bushuyev, Synopsys, Inc.
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31 changes you are making here.
32
33 Name, Affiliation, Date:
34 Description of Modification:
35
36 *****************************************************************************/
37
38// $Log: sc_bv_base.h,v $
39// Revision 1.3 2011/08/26 22:32:00 acg
40// Torsten Maehne: added parentheses to make opearator ordering more obvious.
41//
42// Revision 1.2 2011/08/15 16:43:24 acg
43// Torsten Maehne: changes to remove unused argument warnings.
44//
45// Revision 1.1.1.1 2006/12/15 20:20:04 acg
46// SystemC 2.3
47//
48// Revision 1.3 2006/01/13 18:53:53 acg
49// Andy Goodrich: added $Log command so that CVS comments are reproduced in
50// the source.
51//
52
53#ifndef SC_BV_BASE_H
54#define SC_BV_BASE_H
55
56
62
63
64namespace sc_dt
65{
66
67// classes defined in this module
68class sc_bv_base;
69
70
71// ----------------------------------------------------------------------------
72// CLASS : sc_bv_base
73//
74// Arbitrary size bit vector base class.
75// ----------------------------------------------------------------------------
76
78 : public sc_proxy<sc_bv_base>
79{
80 friend class sc_lv_base;
81
82
83 void init( int length_, bool init_value = false );
84
85 void assign_from_string( const std::string& );
86
87public:
88
89 // typedefs
90
92 typedef base_type::value_type value_type;
93
94
95 // constructors
96
97 explicit sc_bv_base( int length_ = sc_length_param().len() )
98 : m_len( 0 ), m_size( 0 ), m_data( 0 )
99 { init( length_ ); }
100
101 explicit sc_bv_base( bool a,
102 int length_ = sc_length_param().len() )
103 : m_len( 0 ), m_size( 0 ), m_data( 0 )
104 { init( length_, a ); }
105
106 sc_bv_base( const char* a );
107
108 sc_bv_base( const char* a, int length_ );
109
110 template <class X>
112 : m_len( 0 ), m_size( 0 ), m_data( 0 )
113 { init( a.back_cast().length() ); base_type::assign_( a ); }
114
116
117#ifdef SC_DT_DEPRECATED
118
119 explicit sc_bv_base( const sc_unsigned& 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_signed& 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_uint_base& a)
128 : m_len( 0 ), m_size( 0 ), m_data( 0 )
129 { init( a.length() ); base_type::assign_( a ); }
130
131 explicit sc_bv_base( const sc_int_base& a)
132 : m_len( 0 ), m_size( 0 ), m_data( 0 )
133 { init( a.length() ); base_type::assign_( a ); }
134
135#endif
136
137
138 // destructor
139
140 virtual ~sc_bv_base()
141 { if ( m_data != m_base_vec ) delete [] m_data; }
142
143
144 // assignment operators
145
146 template <class X>
147 sc_bv_base& operator = ( const sc_proxy<X>& a )
148 { assign_p_( *this, a ); return *this; }
149
150 sc_bv_base& operator = ( const sc_bv_base& a )
151 { assign_p_( *this, a ); return *this; }
152
153 sc_bv_base& operator = ( const char* a );
154
155 sc_bv_base& operator = ( const bool* a )
156 { base_type::assign_( a ); return *this; }
157
158 sc_bv_base& operator = ( const sc_logic* a )
159 { base_type::assign_( a ); return *this; }
160
161 sc_bv_base& operator = ( const sc_unsigned& a )
162 { base_type::assign_( a ); return *this; }
163
164 sc_bv_base& operator = ( const sc_signed& a )
165 { base_type::assign_( a ); return *this; }
166
167 sc_bv_base& operator = ( const sc_uint_base& a )
168 { base_type::assign_( a ); return *this; }
169
170 sc_bv_base& operator = ( const sc_int_base& a )
171 { base_type::assign_( a ); return *this; }
172
173 sc_bv_base& operator = ( unsigned long a )
174 { base_type::assign_( a ); return *this; }
175
176 sc_bv_base& operator = ( long a )
177 { base_type::assign_( a ); return *this; }
178
179 sc_bv_base& operator = ( unsigned int a )
180 { base_type::assign_( a ); return *this; }
181
182 sc_bv_base& operator = ( int a )
183 { base_type::assign_( a ); return *this; }
184
185 sc_bv_base& operator = ( uint64 a )
186 { base_type::assign_( a ); return *this; }
187
188 sc_bv_base& operator = ( int64 a )
189 { base_type::assign_( a ); return *this; }
190
191
192 // common methods
193
194 int length() const
195 { return m_len; }
196
197 int size() const
198 { return m_size; }
199
200 value_type get_bit( int i ) const;
201 void set_bit( int i, value_type value );
202
203 sc_digit get_word( int i ) const
204 { return m_data[i]; }
205
206 void set_word( int i, sc_digit w )
207 { m_data[i] = w; }
208
209 sc_digit get_cword( int /*i*/ ) const
210 { return SC_DIGIT_ZERO; }
211
212 void set_cword( int i, sc_digit w );
213
214 void clean_tail();
215
216
217 // other methods
218
219 bool is_01() const
220 { return true; }
221
222protected:
223
224 int m_len; // length in bits
225 int m_size; // size of data array
226 sc_digit* m_data; // data array
228};
229
230
231// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
232
233// common methods
234
235inline
238{
239 int wi = i / SC_DIGIT_SIZE;
240 int bi = i % SC_DIGIT_SIZE;
241 return value_type( (m_data[wi] >> bi) & SC_DIGIT_ONE );
242}
243
244inline
245void
247{
248 int wi = i / SC_DIGIT_SIZE;
249 int bi = i % SC_DIGIT_SIZE;
250 sc_digit mask = SC_DIGIT_ONE << bi;
251 m_data[wi] |= mask; // set bit to 1
252 m_data[wi] &= value << bi | ~mask;
253}
254
255
256inline
257void
259{
260 if( w ) {
262 }
263}
264
265
266inline
267void
269{
270 int wi = m_size - 1;
271 int bi = m_len % SC_DIGIT_SIZE;
272 if ( bi != 0 ) m_data[wi] &= ~SC_DIGIT_ZERO >> (SC_DIGIT_SIZE - bi);
273}
274
275} // namespace sc_dt
276
277
278#endif
#define SC_BASE_VEC_DIGITS
Definition: sc_nbdefs.h:127
#define SC_API
Definition: sc_cmnhdr.h:148
#define SC_REPORT_WARNING(msg_type, msg)
Definition: sc_report.h:213
const char SC_ID_SC_BV_CANNOT_CONTAIN_X_AND_Z_[]
const sc_digit SC_DIGIT_ONE
Definition: sc_proxy.h:98
const int SC_DIGIT_SIZE
Definition: sc_proxy.h:95
const sc_digit SC_DIGIT_ZERO
Definition: sc_proxy.h:97
unsigned long long uint64
Definition: sc_nbdefs.h:216
void assign_p_(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_proxy.h:746
unsigned int sc_digit
Definition: sc_nbdefs.h:161
long long int64
Definition: sc_nbdefs.h:215
sc_core::sc_signal_in_if< T > & value(const T &val)
Definition: sc_stub.h:217
sc_proxy< sc_bv_base > base_type
Definition: sc_bv_base.h:91
sc_digit * m_data
Definition: sc_bv_base.h:226
sc_bv_base(const char *a)
sc_bv_base(const sc_bv_base &a)
void set_word(int i, sc_digit w)
Definition: sc_bv_base.h:206
void set_cword(int i, sc_digit w)
Definition: sc_bv_base.h:258
sc_bv_base(const char *a, int length_)
sc_bv_base(bool a, int length_=sc_length_param().len())
Definition: sc_bv_base.h:101
sc_bv_base(const sc_proxy< X > &a)
Definition: sc_bv_base.h:111
sc_digit get_cword(int) const
Definition: sc_bv_base.h:209
int size() const
Definition: sc_bv_base.h:197
value_type get_bit(int i) const
Definition: sc_bv_base.h:237
sc_digit get_word(int i) const
Definition: sc_bv_base.h:203
void set_bit(int i, value_type value)
Definition: sc_bv_base.h:246
int length() const
Definition: sc_bv_base.h:194
virtual ~sc_bv_base()
Definition: sc_bv_base.h:140
bool is_01() const
Definition: sc_bv_base.h:219
sc_bv_base(int length_=sc_length_param().len())
Definition: sc_bv_base.h:97
base_type::value_type value_type
Definition: sc_bv_base.h:92
X & back_cast()
Definition: sc_proxy.h:211
int length() const
Definition: sc_signed.h:807
int length() const
Definition: sc_unsigned.h:808