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