1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 sc_uint.h -- A sc_uint is an unsigned integer whose length is less than the 23 machine's native integer length. We provide two implementations 24 (i) sc_uint with length between 1 - 64, and (ii) sc_uint with 25 length between 1 - 32. Implementation (i) is the default 26 implementation, while implementation (ii) can be used only if 27 compiled with -D_32BIT_. Unlike arbitrary precision, arithmetic 28 and bitwise operations are performed using the native types 29 (hence capped at 32/64 bits). The sc_uint integer is useful 30 when the user does not need arbitrary precision and the 31 performance is superior to sc_bigint/sc_biguint. 32 33 Original Author: Amit Rao, Synopsys, Inc. 34 35 *****************************************************************************/ 36 37/***************************************************************************** 38 39 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 40 changes you are making here. 41 42 Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc. 43 Description of Modification: - Resolved ambiguity with sc_(un)signed. 44 - Merged the code for 64- and 32-bit versions 45 via the constants in sc_nbdefs.h. 46 - Eliminated redundant file inclusions. 47 48 Name, Affiliation, Date: 49 Description of Modification: 50 51 *****************************************************************************/ 52 53// $Log: sc_uint.h,v $ 54// Revision 1.2 2011/02/18 20:19:15 acg 55// Andy Goodrich: updating Copyright notice. 56// 57// Revision 1.1.1.1 2006/12/15 20:20:05 acg 58// SystemC 2.3 59// 60// Revision 1.3 2006/01/13 18:49:32 acg 61// Added $Log command so that CVS check in comments are reproduced in the 62// source. 63// 64 65#ifndef SC_UINT_H 66#define SC_UINT_H 67 68 69#include "sysc/datatypes/int/sc_uint_base.h" 70 71 72namespace sc_dt 73{ 74 75// classes defined in this module 76template <int W> class sc_uint; 77 78 79// ---------------------------------------------------------------------------- 80// CLASS TEMPLATE : sc_uint<W> 81// 82// Template class sc_uint<W> is the interface that the user sees. It 83// is derived from sc_uint_base and most of its methods are just 84// wrappers that call the corresponding method in the parent 85// class. Note that the length of sc_uint datatype is specified as a 86// template parameter. 87// ---------------------------------------------------------------------------- 88 89template <int W> 90class sc_uint 91 : public sc_uint_base 92{ 93public: 94 95 // constructors 96 97 sc_uint() 98 : sc_uint_base( W ) 99 {} 100 101 sc_uint( uint_type v ) 102 : sc_uint_base( v, W ) 103 {} 104 105 sc_uint( const sc_uint<W>& a ) 106 : sc_uint_base( a ) 107 {} 108 109 sc_uint( const sc_uint_base& a ) 110 : sc_uint_base( W ) 111 { sc_uint_base::operator = ( a ); } 112 113 sc_uint( const sc_uint_subref_r& a ) 114 : sc_uint_base( W ) 115 { sc_uint_base::operator = ( a ); } 116 117 template< class T > 118 sc_uint( const sc_generic_base<T>& a ) 119 : sc_uint_base( W ) 120 { sc_uint_base::operator = ( a ); } 121 122 sc_uint( const sc_signed& a ) 123 : sc_uint_base( W ) 124 { sc_uint_base::operator = ( a ); } 125 126 sc_uint( const sc_unsigned& a ) 127 : sc_uint_base( W ) 128 { sc_uint_base::operator = ( a ); } 129 130#ifdef SC_INCLUDE_FX 131 132 explicit sc_uint( const sc_fxval& a ) 133 : sc_uint_base( W ) 134 { sc_uint_base::operator = ( a ); } 135 136 explicit sc_uint( const sc_fxval_fast& a ) 137 : sc_uint_base( W ) 138 { sc_uint_base::operator = ( a ); } 139 140 explicit sc_uint( const sc_fxnum& a ) 141 : sc_uint_base( W ) 142 { sc_uint_base::operator = ( a ); } 143 144 explicit sc_uint( const sc_fxnum_fast& a ) 145 : sc_uint_base( W ) 146 { sc_uint_base::operator = ( a ); } 147 148#endif 149 150 sc_uint( const sc_bv_base& a ) 151 : sc_uint_base( W ) 152 { sc_uint_base::operator = ( a ); } 153 154 sc_uint( const sc_lv_base& a ) 155 : sc_uint_base( W ) 156 { sc_uint_base::operator = ( a ); } 157 158 sc_uint( const char* a ) 159 : sc_uint_base( W ) 160 { sc_uint_base::operator = ( a ); } 161 162 sc_uint( unsigned long a ) 163 : sc_uint_base( W ) 164 { sc_uint_base::operator = ( a ); } 165 166 sc_uint( long a ) 167 : sc_uint_base( W ) 168 { sc_uint_base::operator = ( a ); } 169 170 sc_uint( unsigned int a ) 171 : sc_uint_base( W ) 172 { sc_uint_base::operator = ( a ); } 173 174 sc_uint( int a ) 175 : sc_uint_base( W ) 176 { sc_uint_base::operator = ( a ); } 177 178 sc_uint( int64 a ) 179 : sc_uint_base( W ) 180 { sc_uint_base::operator = ( a ); } 181 182 sc_uint( double a ) 183 : sc_uint_base( W ) 184 { sc_uint_base::operator = ( a ); } 185 186 187 // assignment operators 188 189 sc_uint<W>& operator = ( uint_type v ) 190 { sc_uint_base::operator = ( v ); return *this; } 191 192 sc_uint<W>& operator = ( const sc_uint_base& a ) 193 { sc_uint_base::operator = ( a ); return *this; } 194 195 sc_uint<W>& operator = ( const sc_uint_subref_r& a ) 196 { sc_uint_base::operator = ( a ); return *this; } 197 198 sc_uint<W>& operator = ( const sc_uint<W>& a ) 199 { m_val = a.m_val; return *this; } 200 201 template<class T> 202 sc_uint<W>& operator = ( const sc_generic_base<T>& a ) 203 { sc_uint_base::operator = ( a ); return *this; } 204 205 sc_uint<W>& operator = ( const sc_signed& a ) 206 { sc_uint_base::operator = ( a ); return *this; } 207 208 sc_uint<W>& operator = ( const sc_unsigned& a ) 209 { sc_uint_base::operator = ( a ); return *this; } 210 211#ifdef SC_INCLUDE_FX 212 213 sc_uint<W>& operator = ( const sc_fxval& a ) 214 { sc_uint_base::operator = ( a ); return *this; } 215 216 sc_uint<W>& operator = ( const sc_fxval_fast& a ) 217 { sc_uint_base::operator = ( a ); return *this; } 218 219 sc_uint<W>& operator = ( const sc_fxnum& a ) 220 { sc_uint_base::operator = ( a ); return *this; } 221 222 sc_uint<W>& operator = ( const sc_fxnum_fast& a ) 223 { sc_uint_base::operator = ( a ); return *this; } 224 225#endif 226 227 sc_uint<W>& operator = ( const sc_bv_base& a ) 228 { sc_uint_base::operator = ( a ); return *this; } 229 230 sc_uint<W>& operator = ( const sc_lv_base& a ) 231 { sc_uint_base::operator = ( a ); return *this; } 232 233 sc_uint<W>& operator = ( const char* a ) 234 { sc_uint_base::operator = ( a ); return *this; } 235 236 sc_uint<W>& operator = ( unsigned long a ) 237 { sc_uint_base::operator = ( a ); return *this; } 238 239 sc_uint<W>& operator = ( long a ) 240 { sc_uint_base::operator = ( a ); return *this; } 241 242 sc_uint<W>& operator = ( unsigned int a ) 243 { sc_uint_base::operator = ( a ); return *this; } 244 245 sc_uint<W>& operator = ( int a ) 246 { sc_uint_base::operator = ( a ); return *this; } 247 248 sc_uint<W>& operator = ( int64 a ) 249 { sc_uint_base::operator = ( a ); return *this; } 250 251 sc_uint<W>& operator = ( double a ) 252 { sc_uint_base::operator = ( a ); return *this; } 253 254 255 // arithmetic assignment operators 256 257 sc_uint<W>& operator += ( uint_type v ) 258 { sc_uint_base::operator += ( v ); return *this; } 259 260 sc_uint<W>& operator -= ( uint_type v ) 261 { sc_uint_base::operator -= ( v ); return *this; } 262 263 sc_uint<W>& operator *= ( uint_type v ) 264 { sc_uint_base::operator *= ( v ); return *this; } 265 266 sc_uint<W>& operator /= ( uint_type v ) 267 { sc_uint_base::operator /= ( v ); return *this; } 268 269 sc_uint<W>& operator %= ( uint_type v ) 270 { sc_uint_base::operator %= ( v ); return *this; } 271 272 273 // bitwise assignment operators 274 275 sc_uint<W>& operator &= ( uint_type v ) 276 { sc_uint_base::operator &= ( v ); return *this; } 277 278 sc_uint<W>& operator |= ( uint_type v ) 279 { sc_uint_base::operator |= ( v ); return *this; } 280 281 sc_uint<W>& operator ^= ( uint_type v ) 282 { sc_uint_base::operator ^= ( v ); return *this; } 283 284 285 sc_uint<W>& operator <<= ( uint_type v ) 286 { sc_uint_base::operator <<= ( v ); return *this; } 287 288 sc_uint<W>& operator >>= ( uint_type v ) 289 { sc_uint_base::operator >>= ( v ); return *this; } 290 291 292 // prefix and postfix increment and decrement operators 293 294 sc_uint<W>& operator ++ () // prefix 295 { sc_uint_base::operator ++ (); return *this; } 296 297 const sc_uint<W> operator ++ ( int ) // postfix 298 { return sc_uint<W>( sc_uint_base::operator ++ ( 0 ) ); } 299 300 sc_uint<W>& operator -- () // prefix 301 { sc_uint_base::operator -- (); return *this; } 302 303 const sc_uint<W> operator -- ( int ) // postfix 304 { return sc_uint<W>( sc_uint_base::operator -- ( 0 ) ); } 305}; 306 307} // namespace sc_dt 308 309 310#endif 311 312// Taf! 313