00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2014 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.accellera.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_int.h -- A sc_int is a signed integer whose length is less than the 00021 machine's native integer length. We provide two implementations 00022 (i) sc_int with length between 1 - 64, and (ii) sc_int with 00023 length between 1 - 32. Implementation (i) is the default 00024 implementation, while implementation (ii) can be used only if 00025 the class library is compiled with -D_32BIT_. Unlike arbitrary 00026 precision, arithmetic and bitwise operations are performed 00027 using the native types (hence capped at 32/64 bits). The sc_int 00028 integer is useful when the user does not need arbitrary 00029 precision and the performance is superior to 00030 sc_bigint/sc_biguint. 00031 00032 Original Author: Amit Rao, Synopsys, Inc. 00033 00034 *****************************************************************************/ 00035 00036 /***************************************************************************** 00037 00038 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 00039 changes you are making here. 00040 00041 Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc. 00042 Description of Modification: - Resolved ambiguity with sc_(un)signed. 00043 - Merged the code for 64- and 32-bit versions 00044 via the constants in sc_nbdefs.h. 00045 - Eliminated redundant file inclusions. 00046 00047 Name, Affiliation, Date: 00048 Description of Modification: 00049 00050 *****************************************************************************/ 00051 00052 // $Log: sc_int.h,v $ 00053 // Revision 1.2 2011/02/18 20:19:14 acg 00054 // Andy Goodrich: updating Copyright notice. 00055 // 00056 // Revision 1.1.1.1 2006/12/15 20:20:05 acg 00057 // SystemC 2.3 00058 // 00059 // Revision 1.3 2006/01/13 18:49:31 acg 00060 // Added $Log command so that CVS check in comments are reproduced in the 00061 // source. 00062 // 00063 00064 #ifndef SC_INT_H 00065 #define SC_INT_H 00066 00067 00068 #include "sysc/datatypes/int/sc_int_base.h" 00069 00070 00071 namespace sc_dt 00072 { 00073 00074 // classes defined in this module 00075 template <int W> class sc_int; 00076 00077 00078 // ---------------------------------------------------------------------------- 00079 // CLASS TEMPLATE : sc_int<W> 00080 // 00081 // Template class sc_int<W> is the interface that the user sees. It is 00082 // derived from sc_int_base and most of its methods are just wrappers 00083 // that call the corresponding method in the parent class. Note that 00084 // the length of sc_int datatype is specified as a template parameter. 00085 // ---------------------------------------------------------------------------- 00086 00087 template <int W> 00088 class sc_int 00089 : public sc_int_base 00090 { 00091 public: 00092 00093 // constructors 00094 00095 sc_int() 00096 : sc_int_base( W ) 00097 {} 00098 00099 sc_int( int_type v ) 00100 : sc_int_base( v, W ) 00101 {} 00102 00103 sc_int( const sc_int<W>& a ) 00104 : sc_int_base( a ) 00105 {} 00106 00107 sc_int( const sc_int_base& a ) 00108 : sc_int_base( W ) 00109 { sc_int_base::operator = ( a ); } 00110 00111 sc_int( const sc_int_subref_r& a ) 00112 : sc_int_base( W ) 00113 { sc_int_base::operator = ( a ); } 00114 00115 template< class T > 00116 sc_int( const sc_generic_base<T>& a ) 00117 : sc_int_base( W ) 00118 { sc_int_base::operator = ( a->to_int64() ); } 00119 00120 sc_int( const sc_signed& a ) 00121 : sc_int_base( W ) 00122 { sc_int_base::operator = ( a ); } 00123 00124 sc_int( const sc_unsigned& a ) 00125 : sc_int_base( W ) 00126 { sc_int_base::operator = ( a ); } 00127 00128 #ifdef SC_INCLUDE_FX 00129 00130 explicit sc_int( const sc_fxval& a ) 00131 : sc_int_base( W ) 00132 { sc_int_base::operator = ( a ); } 00133 00134 explicit sc_int( const sc_fxval_fast& a ) 00135 : sc_int_base( W ) 00136 { sc_int_base::operator = ( a ); } 00137 00138 explicit sc_int( const sc_fxnum& a ) 00139 : sc_int_base( W ) 00140 { sc_int_base::operator = ( a ); } 00141 00142 explicit sc_int( const sc_fxnum_fast& a ) 00143 : sc_int_base( W ) 00144 { sc_int_base::operator = ( a ); } 00145 00146 #endif 00147 00148 sc_int( const sc_bv_base& a ) 00149 : sc_int_base( W ) 00150 { sc_int_base::operator = ( a ); } 00151 00152 sc_int( const sc_lv_base& a ) 00153 : sc_int_base( W ) 00154 { sc_int_base::operator = ( a ); } 00155 00156 sc_int( const char* a ) 00157 : sc_int_base( W ) 00158 { sc_int_base::operator = ( a ); } 00159 00160 sc_int( unsigned long a ) 00161 : sc_int_base( W ) 00162 { sc_int_base::operator = ( a ); } 00163 00164 sc_int( long a ) 00165 : sc_int_base( W ) 00166 { sc_int_base::operator = ( a ); } 00167 00168 sc_int( unsigned int a ) 00169 : sc_int_base( W ) 00170 { sc_int_base::operator = ( a ); } 00171 00172 sc_int( int a ) 00173 : sc_int_base( W ) 00174 { sc_int_base::operator = ( a ); } 00175 00176 sc_int( uint64 a ) 00177 : sc_int_base( W ) 00178 { sc_int_base::operator = ( a ); } 00179 00180 sc_int( double a ) 00181 : sc_int_base( W ) 00182 { sc_int_base::operator = ( a ); } 00183 00184 00185 // assignment operators 00186 00187 sc_int<W>& operator = ( int_type v ) 00188 { sc_int_base::operator = ( v ); return *this; } 00189 00190 sc_int<W>& operator = ( const sc_int_base& a ) 00191 { sc_int_base::operator = ( a ); return *this; } 00192 00193 sc_int<W>& operator = ( const sc_int_subref_r& a ) 00194 { sc_int_base::operator = ( a ); return *this; } 00195 00196 sc_int<W>& operator = ( const sc_int<W>& a ) 00197 { m_val = a.m_val; return *this; } 00198 00199 template< class T > 00200 sc_int<W>& operator = ( const sc_generic_base<T>& a ) 00201 { sc_int_base::operator = ( a->to_int64() ); return *this; } 00202 00203 sc_int<W>& operator = ( const sc_signed& a ) 00204 { sc_int_base::operator = ( a ); return *this; } 00205 00206 sc_int<W>& operator = ( const sc_unsigned& a ) 00207 { sc_int_base::operator = ( a ); return *this; } 00208 00209 #ifdef SC_INCLUDE_FX 00210 00211 sc_int<W>& operator = ( const sc_fxval& a ) 00212 { sc_int_base::operator = ( a ); return *this; } 00213 00214 sc_int<W>& operator = ( const sc_fxval_fast& a ) 00215 { sc_int_base::operator = ( a ); return *this; } 00216 00217 sc_int<W>& operator = ( const sc_fxnum& a ) 00218 { sc_int_base::operator = ( a ); return *this; } 00219 00220 sc_int<W>& operator = ( const sc_fxnum_fast& a ) 00221 { sc_int_base::operator = ( a ); return *this; } 00222 00223 #endif 00224 00225 sc_int<W>& operator = ( const sc_bv_base& a ) 00226 { sc_int_base::operator = ( a ); return *this; } 00227 00228 sc_int<W>& operator = ( const sc_lv_base& a ) 00229 { sc_int_base::operator = ( a ); return *this; } 00230 00231 sc_int<W>& operator = ( const char* a ) 00232 { sc_int_base::operator = ( a ); return *this; } 00233 00234 sc_int<W>& operator = ( unsigned long a ) 00235 { sc_int_base::operator = ( a ); return *this; } 00236 00237 sc_int<W>& operator = ( long a ) 00238 { sc_int_base::operator = ( a ); return *this; } 00239 00240 sc_int<W>& operator = ( unsigned int a ) 00241 { sc_int_base::operator = ( a ); return *this; } 00242 00243 sc_int<W>& operator = ( int a ) 00244 { sc_int_base::operator = ( a ); return *this; } 00245 00246 sc_int<W>& operator = ( uint64 a ) 00247 { sc_int_base::operator = ( a ); return *this; } 00248 00249 sc_int<W>& operator = ( double a ) 00250 { sc_int_base::operator = ( a ); return *this; } 00251 00252 00253 // arithmetic assignment operators 00254 00255 sc_int<W>& operator += ( int_type v ) 00256 { sc_int_base::operator += ( v ); return *this; } 00257 00258 sc_int<W>& operator -= ( int_type v ) 00259 { sc_int_base::operator -= ( v ); return *this; } 00260 00261 sc_int<W>& operator *= ( int_type v ) 00262 { sc_int_base::operator *= ( v ); return *this; } 00263 00264 sc_int<W>& operator /= ( int_type v ) 00265 { sc_int_base::operator /= ( v ); return *this; } 00266 00267 sc_int<W>& operator %= ( int_type v ) 00268 { sc_int_base::operator %= ( v ); return *this; } 00269 00270 00271 // bitwise assignment operators 00272 00273 sc_int<W>& operator &= ( int_type v ) 00274 { sc_int_base::operator &= ( v ); return *this; } 00275 00276 sc_int<W>& operator |= ( int_type v ) 00277 { sc_int_base::operator |= ( v ); return *this; } 00278 00279 sc_int<W>& operator ^= ( int_type v ) 00280 { sc_int_base::operator ^= ( v ); return *this; } 00281 00282 00283 sc_int<W>& operator <<= ( int_type v ) 00284 { sc_int_base::operator <<= ( v ); return *this; } 00285 00286 sc_int<W>& operator >>= ( int_type v ) 00287 { sc_int_base::operator >>= ( v ); return *this; } 00288 00289 00290 // prefix and postfix increment and decrement operators 00291 00292 sc_int<W>& operator ++ () // prefix 00293 { sc_int_base::operator ++ (); return *this; } 00294 00295 const sc_int<W> operator ++ ( int ) // postfix 00296 { return sc_int<W>( sc_int_base::operator ++ ( 0 ) ); } 00297 00298 sc_int<W>& operator -- () // prefix 00299 { sc_int_base::operator -- (); return *this; } 00300 00301 const sc_int<W> operator -- ( int ) // postfix 00302 { return sc_int<W>( sc_int_base::operator -- ( 0 ) ); } 00303 }; 00304 00305 } // namespace sc_dt 00306 00307 00308 #endif 00309 00310 // Taf!