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