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