SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_uint.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_uint.h -- A sc_uint is an unsigned integer whose length is less than the
23 machine's native integer length. We provide two implementations
24 (i) sc_uint with length between 1 - 64, and (ii) sc_uint with
25 length between 1 - 32. Implementation (i) is the default
26 implementation, while implementation (ii) can be used only if
27 compiled with -D_32BIT_. Unlike arbitrary precision, arithmetic
28 and bitwise operations are performed using the native types
29 (hence capped at 32/64 bits). The sc_uint integer is useful
30 when the user does not need arbitrary precision and the
31 performance is superior to sc_bigint/sc_biguint.
32
33 Original Author: Amit Rao, Synopsys, Inc.
34
35 *****************************************************************************/
36
37/*****************************************************************************
38
39 MODIFICATION LOG - modifiers, enter your name, affiliation, date and
40 changes you are making here.
41
42 Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc.
43 Description of Modification: - Resolved ambiguity with sc_(un)signed.
44 - Merged the code for 64- and 32-bit versions
45 via the constants in sc_nbdefs.h.
46 - Eliminated redundant file inclusions.
47
48 Name, Affiliation, Date:
49 Description of Modification:
50
51 *****************************************************************************/
52
53// $Log: sc_uint.h,v $
54// Revision 1.2 2011/02/18 20:19:15 acg
55// Andy Goodrich: updating Copyright notice.
56//
57// Revision 1.1.1.1 2006/12/15 20:20:05 acg
58// SystemC 2.3
59//
60// Revision 1.3 2006/01/13 18:49:32 acg
61// Added $Log command so that CVS check in comments are reproduced in the
62// source.
63//
64
65#ifndef SC_UINT_H
66#define SC_UINT_H
67
68
70
71
72namespace sc_dt
73{
74
75// classes defined in this module
76template <int W> class sc_uint;
77
78
79// ----------------------------------------------------------------------------
80// CLASS TEMPLATE : sc_uint<W>
81//
82// Template class sc_uint<W> is the interface that the user sees. It
83// is derived from sc_uint_base and most of its methods are just
84// wrappers that call the corresponding method in the parent
85// class. Note that the length of sc_uint datatype is specified as a
86// template parameter.
87// ----------------------------------------------------------------------------
88
89template <int W>
91 : public sc_uint_base
92{
93public:
94
95 // assignment with sign extensions
96
98 {
99 m_val = value & ( ~UINT_ZERO >> (SC_INTWIDTH-W) );
100 }
101
102 // constructors
103
105 : sc_uint_base( W )
106 {}
107
109 : sc_uint_base( W )
110 { assign(v); }
111
112 sc_uint( const sc_uint<W>& a )
113 : sc_uint_base( a )
114 {}
115
117 : sc_uint_base( W )
118 { assign( a ); }
119
121 : sc_uint_base( W )
122 { assign( a ); }
123
124 template< class T >
126 : sc_uint_base( W )
127 { assign( a->to_uint64() ); }
128
129 template<int WO>
131 : sc_uint_base( W )
132 { assign( a.to_uint64() ); }
133
134 template<int WO>
136 : sc_uint_base( W )
137 { assign( a.to_uint64() ); }
138
139 sc_uint( const sc_signed& a )
140 : sc_uint_base( W )
141 { assign( a.to_uint64() ); }
142
144 : sc_uint_base( W )
145 { assign( a.to_uint64() ); }
146
147#ifdef SC_INCLUDE_FX
148
149 explicit sc_uint( const sc_fxval& a )
150 : sc_uint_base( W )
152
153 explicit sc_uint( const sc_fxval_fast& a )
154 : sc_uint_base( W )
156
157 explicit sc_uint( const sc_fxnum& a )
158 : sc_uint_base( W )
160
161 explicit sc_uint( const sc_fxnum_fast& a )
162 : sc_uint_base( W )
164
165#endif
166
167 sc_uint( const sc_bv_base& a )
168 : sc_uint_base( W )
170
171 sc_uint( const sc_lv_base& a )
172 : sc_uint_base( W )
174
175 sc_uint( const char* a )
176 : sc_uint_base( W )
178
179 sc_uint( unsigned long a )
180 : sc_uint_base( W )
181 { assign( a ); }
182
183 sc_uint( long a )
184 : sc_uint_base( W )
185 { assign( a ); }
186
187 sc_uint( unsigned int a )
188 : sc_uint_base( W )
189 { assign( a ); }
190
191 sc_uint( int a )
192 : sc_uint_base( W )
193 { assign( a ); }
194
196 : sc_uint_base( W )
197 { assign( a ); }
198
199 sc_uint( double a )
200 : sc_uint_base( W )
202
203
204 // assignment operators
205
207 { sc_uint_base::operator = ( v ); return *this; }
208
210 { assign( a ); return *this; }
211
213 { assign( a ); return *this; }
214
216 { m_val = a.m_val; return *this; }
217
218 template<class T>
220 { assign( a->to_uint64() ); return *this; }
221
223 { assign( a.to_uint64() ); return *this; }
224
225 template<int W1>
226 inline
227 const sc_uint<W>& operator = ( const sc_bigint<W1>& a );
228
229 template<int W1>
230 inline
231 const sc_uint<W>& operator = ( const sc_biguint<W1>& a );
232
234 { assign( a.to_uint64() ); return *this; }
235
237 { sc_uint_base::operator = ( a ); return *this; }
238
240 { sc_uint_base::operator = ( a ); return *this; }
241
242#ifdef SC_INCLUDE_FX
243
244 sc_uint<W>& operator = ( const sc_fxval& a )
245 { sc_uint_base::operator = ( a ); return *this; }
246
247 sc_uint<W>& operator = ( const sc_fxval_fast& a )
248 { sc_uint_base::operator = ( a ); return *this; }
249
250 sc_uint<W>& operator = ( const sc_fxnum& a )
251 { sc_uint_base::operator = ( a ); return *this; }
252
253 sc_uint<W>& operator = ( const sc_fxnum_fast& a )
254 { sc_uint_base::operator = ( a ); return *this; }
255
256#endif
257
259 { sc_uint_base::operator = ( a ); return *this; }
260
262 { sc_uint_base::operator = ( a ); return *this; }
263
264 sc_uint<W>& operator = ( const char* a )
265 { sc_uint_base::operator = ( a ); return *this; }
266
267 sc_uint<W>& operator = ( unsigned long a )
268 { assign( a ); return *this; }
269
271 { assign( a ); return *this; }
272
273 sc_uint<W>& operator = ( unsigned int a )
274 { assign( a ); return *this; }
275
277 { assign( a ); return *this; }
278
280 { assign( a ); return *this; }
281
283 { sc_uint_base::operator = ( a ); return *this; }
284
285
286 // arithmetic assignment operators
287
289 { sc_uint_base::operator += ( v ); return *this; }
290
292 { sc_uint_base::operator -= ( v ); return *this; }
293
295 { sc_uint_base::operator *= ( v ); return *this; }
296
298 { sc_uint_base::operator /= ( v ); return *this; }
299
301 { sc_uint_base::operator %= ( v ); return *this; }
302
303
304 // bitwise assignment operators
305
307 { sc_uint_base::operator &= ( v ); return *this; }
308
310 { sc_uint_base::operator |= ( v ); return *this; }
311
313 { sc_uint_base::operator ^= ( v ); return *this; }
314
315
317 { sc_uint_base::operator <<= ( v ); return *this; }
318
320 { sc_uint_base::operator >>= ( v ); return *this; }
321
322
323 // prefix and postfix increment and decrement operators
324
326 { sc_uint_base::operator ++ (); return *this; }
327
328 sc_uint<W> operator ++ ( int ) // postfix
329 { return sc_uint<W>( sc_uint_base::operator ++ ( 0 ) ); }
330
332 { sc_uint_base::operator -- (); return *this; }
333
334 sc_uint<W> operator -- ( int ) // postfix
335 { return sc_uint<W>( sc_uint_base::operator -- ( 0 ) ); }
336};
337
338} // namespace sc_dt
339
340
341#endif
342
343// Taf!
#define SC_INTWIDTH
Definition: sc_nbdefs.h:260
uint64 uint_type
Definition: sc_nbdefs.h:259
long long int64
Definition: sc_nbdefs.h:215
uint64 to_uint64() const
Definition: sc_bigint.h:441
uint64 to_uint64() const
Definition: sc_biguint.h:450
uint64 to_uint64() const
Definition: sc_signed.h:1530
sc_uint< W > & operator/=(uint_type v)
Definition: sc_uint.h:297
sc_uint< W > & operator&=(uint_type v)
Definition: sc_uint.h:306
sc_uint(const sc_uint_subref_r &a)
Definition: sc_uint.h:120
sc_uint(int64 a)
Definition: sc_uint.h:195
sc_uint< W > & operator%=(uint_type v)
Definition: sc_uint.h:300
sc_uint(const sc_signed &a)
Definition: sc_uint.h:139
sc_uint(double a)
Definition: sc_uint.h:199
sc_uint< W > & operator--()
Definition: sc_uint.h:331
sc_uint< W > & operator*=(uint_type v)
Definition: sc_uint.h:294
sc_uint(unsigned long a)
Definition: sc_uint.h:179
sc_uint(const sc_generic_base< T > &a)
Definition: sc_uint.h:125
sc_uint(const sc_bv_base &a)
Definition: sc_uint.h:167
sc_uint(const sc_uint_base &a)
Definition: sc_uint.h:116
sc_uint< W > & operator|=(uint_type v)
Definition: sc_uint.h:309
sc_uint< W > & operator^=(uint_type v)
Definition: sc_uint.h:312
sc_uint< W > & operator-=(uint_type v)
Definition: sc_uint.h:291
sc_uint(const sc_uint< W > &a)
Definition: sc_uint.h:112
void assign(uint_type value)
Definition: sc_uint.h:97
sc_uint(uint_type v)
Definition: sc_uint.h:108
sc_uint(unsigned int a)
Definition: sc_uint.h:187
sc_uint< W > & operator+=(uint_type v)
Definition: sc_uint.h:288
sc_uint< W > & operator>>=(uint_type v)
Definition: sc_uint.h:319
sc_uint(const char *a)
Definition: sc_uint.h:175
sc_uint(const sc_bigint< WO > &a)
Definition: sc_uint.h:130
sc_uint(int a)
Definition: sc_uint.h:191
sc_uint(const sc_lv_base &a)
Definition: sc_uint.h:171
sc_uint< W > & operator=(uint_type v)
Definition: sc_uint.h:206
sc_uint(const sc_unsigned &a)
Definition: sc_uint.h:143
sc_uint(const sc_biguint< WO > &a)
Definition: sc_uint.h:135
sc_uint(long a)
Definition: sc_uint.h:183
sc_uint< W > & operator<<=(uint_type v)
Definition: sc_uint.h:316
sc_uint< W > & operator++()
Definition: sc_uint.h:325
sc_uint_base & operator++()
Definition: sc_uint_base.h:679
sc_uint_base & operator>>=(uint_type v)
Definition: sc_uint_base.h:673
uint_type value() const
Definition: sc_uint_base.h:805
sc_uint_base & operator/=(uint_type v)
Definition: sc_uint_base.h:651
sc_uint_base(int w=sc_length_param().len())
Definition: sc_uint_base.h:550
sc_uint_base & operator=(uint_type v)
Definition: sc_uint_base.h:590
sc_uint_base & operator%=(uint_type v)
Definition: sc_uint_base.h:654
sc_uint_base & operator<<=(uint_type v)
Definition: sc_uint_base.h:670
sc_uint_base & operator^=(uint_type v)
Definition: sc_uint_base.h:666
sc_uint_base & operator+=(uint_type v)
Definition: sc_uint_base.h:642
sc_uint_base & operator*=(uint_type v)
Definition: sc_uint_base.h:648
sc_uint_base & operator--()
Definition: sc_uint_base.h:685
sc_uint_base & operator|=(uint_type v)
Definition: sc_uint_base.h:663
sc_uint_base & operator-=(uint_type v)
Definition: sc_uint_base.h:645
sc_uint_base & operator&=(uint_type v)
Definition: sc_uint_base.h:660
uint64 to_uint64() const
Definition: sc_unsigned.h:1525