00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2004 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 Version 2.3 (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.systemc.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 #ifndef SC_INT_H 00053 #define SC_INT_H 00054 00055 00056 #include "systemc/datatypes/int/sc_int_base.h" 00057 00058 00059 namespace sc_dt 00060 { 00061 00062 // classes defined in this module 00063 template <int W> class sc_int; 00064 00065 00066 // ---------------------------------------------------------------------------- 00067 // CLASS TEMPLATE : sc_int<W> 00068 // 00069 // Template class sc_int<W> is the interface that the user sees. It is 00070 // derived from sc_int_base and most of its methods are just wrappers 00071 // that call the corresponding method in the parent class. Note that 00072 // the length of sc_int datatype is specified as a template parameter. 00073 // ---------------------------------------------------------------------------- 00074 00075 template <int W> 00076 class sc_int 00077 : public sc_int_base 00078 { 00079 public: 00080 00081 // constructors 00082 00083 sc_int() 00084 : sc_int_base( W ) 00085 {} 00086 00087 sc_int( int_type v ) 00088 : sc_int_base( v, W ) 00089 {} 00090 00091 sc_int( const sc_int<W>& a ) 00092 : sc_int_base( a ) 00093 {} 00094 00095 sc_int( const sc_int_base& a ) 00096 : sc_int_base( W ) 00097 { sc_int_base::operator = ( a ); } 00098 00099 sc_int( const sc_int_subref_r& a ) 00100 : sc_int_base( W ) 00101 { sc_int_base::operator = ( a ); } 00102 00103 sc_int( const sc_concatref& a ) 00104 : sc_int_base( W ) 00105 { sc_int_base::operator = ( a ); } 00106 00107 sc_int( const sc_signed& a ) 00108 : sc_int_base( W ) 00109 { sc_int_base::operator = ( a ); } 00110 00111 sc_int( const sc_unsigned& a ) 00112 : sc_int_base( W ) 00113 { sc_int_base::operator = ( a ); } 00114 00115 #ifdef SC_INCLUDE_FX 00116 00117 explicit sc_int( const sc_fxval& a ) 00118 : sc_int_base( W ) 00119 { sc_int_base::operator = ( a ); } 00120 00121 explicit sc_int( const sc_fxval_fast& a ) 00122 : sc_int_base( W ) 00123 { sc_int_base::operator = ( a ); } 00124 00125 explicit sc_int( const sc_fxnum& a ) 00126 : sc_int_base( W ) 00127 { sc_int_base::operator = ( a ); } 00128 00129 explicit sc_int( const sc_fxnum_fast& a ) 00130 : sc_int_base( W ) 00131 { sc_int_base::operator = ( a ); } 00132 00133 #endif 00134 00135 sc_int( const sc_bv_base& a ) 00136 : sc_int_base( W ) 00137 { sc_int_base::operator = ( a ); } 00138 00139 sc_int( const sc_lv_base& a ) 00140 : sc_int_base( W ) 00141 { sc_int_base::operator = ( a ); } 00142 00143 sc_int( const char* a ) 00144 : sc_int_base( W ) 00145 { sc_int_base::operator = ( a ); } 00146 00147 sc_int( unsigned long a ) 00148 : sc_int_base( W ) 00149 { sc_int_base::operator = ( a ); } 00150 00151 sc_int( long a ) 00152 : sc_int_base( W ) 00153 { sc_int_base::operator = ( a ); } 00154 00155 sc_int( unsigned int a ) 00156 : sc_int_base( W ) 00157 { sc_int_base::operator = ( a ); } 00158 00159 sc_int( int a ) 00160 : sc_int_base( W ) 00161 { sc_int_base::operator = ( a ); } 00162 00163 sc_int( uint64 a ) 00164 : sc_int_base( W ) 00165 { sc_int_base::operator = ( a ); } 00166 00167 sc_int( double a ) 00168 : sc_int_base( W ) 00169 { sc_int_base::operator = ( a ); } 00170 00171 00172 // assignment operators 00173 00174 sc_int<W>& operator = ( int_type v ) 00175 { sc_int_base::operator = ( v ); return *this; } 00176 00177 sc_int<W>& operator = ( const sc_int_base& a ) 00178 { sc_int_base::operator = ( a ); return *this; } 00179 00180 sc_int<W>& operator = ( const sc_int_subref_r& a ) 00181 { sc_int_base::operator = ( a ); return *this; } 00182 00183 sc_int<W>& operator = ( const sc_int<W>& a ) 00184 { m_val = a.m_val; return *this; } 00185 00186 sc_int<W>& operator = ( const sc_concatref& a ) 00187 { sc_int_base::operator = ( a ); return *this; } 00188 00189 sc_int<W>& operator = ( const sc_signed& a ) 00190 { sc_int_base::operator = ( a ); return *this; } 00191 00192 sc_int<W>& operator = ( const sc_unsigned& a ) 00193 { sc_int_base::operator = ( a ); return *this; } 00194 00195 #ifdef SC_INCLUDE_FX 00196 00197 sc_int<W>& operator = ( const sc_fxval& a ) 00198 { sc_int_base::operator = ( a ); return *this; } 00199 00200 sc_int<W>& operator = ( const sc_fxval_fast& a ) 00201 { sc_int_base::operator = ( a ); return *this; } 00202 00203 sc_int<W>& operator = ( const sc_fxnum& a ) 00204 { sc_int_base::operator = ( a ); return *this; } 00205 00206 sc_int<W>& operator = ( const sc_fxnum_fast& a ) 00207 { sc_int_base::operator = ( a ); return *this; } 00208 00209 #endif 00210 00211 sc_int<W>& operator = ( const sc_bv_base& a ) 00212 { sc_int_base::operator = ( a ); return *this; } 00213 00214 sc_int<W>& operator = ( const sc_lv_base& a ) 00215 { sc_int_base::operator = ( a ); return *this; } 00216 00217 sc_int<W>& operator = ( const char* a ) 00218 { sc_int_base::operator = ( a ); return *this; } 00219 00220 sc_int<W>& operator = ( unsigned long a ) 00221 { sc_int_base::operator = ( a ); return *this; } 00222 00223 sc_int<W>& operator = ( long a ) 00224 { sc_int_base::operator = ( a ); return *this; } 00225 00226 sc_int<W>& operator = ( unsigned int a ) 00227 { sc_int_base::operator = ( a ); return *this; } 00228 00229 sc_int<W>& operator = ( int a ) 00230 { sc_int_base::operator = ( a ); return *this; } 00231 00232 sc_int<W>& operator = ( uint64 a ) 00233 { sc_int_base::operator = ( a ); return *this; } 00234 00235 sc_int<W>& operator = ( double a ) 00236 { sc_int_base::operator = ( a ); return *this; } 00237 00238 00239 // arithmetic assignment operators 00240 00241 sc_int<W>& operator += ( int_type v ) 00242 { sc_int_base::operator += ( v ); return *this; } 00243 00244 sc_int<W>& operator -= ( int_type v ) 00245 { sc_int_base::operator -= ( v ); return *this; } 00246 00247 sc_int<W>& operator *= ( int_type v ) 00248 { sc_int_base::operator *= ( v ); return *this; } 00249 00250 sc_int<W>& operator /= ( int_type v ) 00251 { sc_int_base::operator /= ( v ); return *this; } 00252 00253 sc_int<W>& operator %= ( int_type v ) 00254 { sc_int_base::operator %= ( v ); return *this; } 00255 00256 00257 // bitwise assignment operators 00258 00259 sc_int<W>& operator &= ( int_type v ) 00260 { sc_int_base::operator &= ( v ); return *this; } 00261 00262 sc_int<W>& operator |= ( int_type v ) 00263 { sc_int_base::operator |= ( v ); return *this; } 00264 00265 sc_int<W>& operator ^= ( int_type v ) 00266 { sc_int_base::operator ^= ( v ); return *this; } 00267 00268 00269 sc_int<W>& operator <<= ( int_type v ) 00270 { sc_int_base::operator <<= ( v ); return *this; } 00271 00272 sc_int<W>& operator >>= ( int_type v ) 00273 { sc_int_base::operator >>= ( v ); return *this; } 00274 00275 00276 // prefix and postfix increment and decrement operators 00277 00278 sc_int<W>& operator ++ () // prefix 00279 { sc_int_base::operator ++ (); return *this; } 00280 00281 const sc_int<W> operator ++ ( int ) // postfix 00282 { return sc_int<W>( sc_int_base::operator ++ ( 0 ) ); } 00283 00284 sc_int<W>& operator -- () // prefix 00285 { sc_int_base::operator -- (); return *this; } 00286 00287 const sc_int<W> operator -- ( int ) // postfix 00288 { return sc_int<W>( sc_int_base::operator -- ( 0 ) ); } 00289 }; 00290 00291 } // namespace sc_dt 00292 00293 00294 #endif 00295 00296 // Taf!
1.2.18