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