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