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