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