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 -- An unsigned integer whose length is less than 64 bits. 23 24 Unlike arbitrary precision, arithmetic and bitwise operations 25 are performed using the native types (hence capped at 64 bits). 26 The sc_uint integer is useful when the user does not need 27 arbitrary precision and the performance is superior to 28 sc_bigint/sc_biguint. 29 30 Original Author: Amit Rao, Synopsys, Inc. 31 32 *****************************************************************************/ 33 34/***************************************************************************** 35 36 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 37 changes you are making here. 38 39 Name, Affiliation, Date: Ali Dasdan, Synopsys, Inc. 40 Description of Modification: - Resolved ambiguity with sc_(un)signed. 41 - Merged the code for 64- and 32-bit versions 42 via the constants in sc_nbdefs.h. 43 - Eliminated redundant file inclusions. 44 45 Name, Affiliation, Date: 46 Description of Modification: 47 48 *****************************************************************************/ 49 50// $Log: sc_uint.h,v $ 51// Revision 1.2 2011/02/18 20:19:15 acg 52// Andy Goodrich: updating Copyright notice. 53// 54// Revision 1.1.1.1 2006/12/15 20:20:05 acg 55// SystemC 2.3 56// 57// Revision 1.3 2006/01/13 18:49:32 acg 58// Added $Log command so that CVS check in comments are reproduced in the 59// source. 60// 61 62#ifndef __SYSTEMC_EXT_DT_INT_SC_UINT_HH__ 63#define __SYSTEMC_EXT_DT_INT_SC_UINT_HH__ 64 65#include "sc_uint_base.hh" 66 67namespace sc_dt 68{ 69 70// classes defined in this module 71template <int W> 72class sc_uint; 73 74 75// ---------------------------------------------------------------------------- 76// CLASS TEMPLATE : sc_uint<W> 77// 78// Template class sc_uint<W> is the interface that the user sees. It 79// is derived from sc_uint_base and most of its methods are just 80// wrappers that call the corresponding method in the parent 81// class. Note that the length of sc_uint datatype is specified as a 82// template parameter. 83// ---------------------------------------------------------------------------- 84 85template <int W> 86class sc_uint : public sc_uint_base 87{ 88 public: 89 // constructors 90 sc_uint() : sc_uint_base(W) {} 91 sc_uint(uint_type v) : sc_uint_base(v, W) {} 92 sc_uint(const sc_uint<W> &a) : sc_uint_base(a) {} 93 sc_uint(const sc_uint_base &a) : sc_uint_base(W) 94 { 95 sc_uint_base::operator = (a); 96 } 97 sc_uint(const sc_uint_subref_r &a) : sc_uint_base(W) 98 { 99 sc_uint_base::operator = (a); 100 } 101 template< class T > 102 sc_uint(const sc_generic_base<T> &a) : sc_uint_base(W) 103 { 104 sc_uint_base::operator = (a); 105 } 106 sc_uint(const sc_signed &a) : sc_uint_base(W) 107 { 108 sc_uint_base::operator = (a); 109 } 110 sc_uint(const sc_unsigned &a) : sc_uint_base(W) 111 { 112 sc_uint_base::operator = (a); 113 } 114 explicit sc_uint(const sc_fxval &a) : sc_uint_base(W) 115 { 116 sc_uint_base::operator = (a); 117 } 118 explicit sc_uint(const sc_fxval_fast &a) : sc_uint_base(W) 119 { 120 sc_uint_base::operator = (a); 121 } 122 explicit sc_uint(const sc_fxnum &a) : sc_uint_base(W) 123 { 124 sc_uint_base::operator = (a); 125 } 126 explicit sc_uint(const sc_fxnum_fast &a) : sc_uint_base(W) 127 { 128 sc_uint_base::operator = (a); 129 } 130 sc_uint(const sc_bv_base &a) : sc_uint_base(W) 131 { 132 sc_uint_base::operator = (a); 133 } 134 sc_uint(const sc_lv_base &a) : sc_uint_base(W) 135 { 136 sc_uint_base::operator = (a); 137 } 138 sc_uint(const char* a) : sc_uint_base(W) 139 { 140 sc_uint_base::operator = (a); 141 } 142 sc_uint(unsigned long a) : sc_uint_base(W) 143 { 144 sc_uint_base::operator = (a); 145 } 146 sc_uint(long a) : sc_uint_base(W) 147 { 148 sc_uint_base::operator = (a); 149 } 150 sc_uint(unsigned int a) : sc_uint_base(W) 151 { 152 sc_uint_base::operator = (a); 153 } 154 sc_uint(int a) : sc_uint_base(W) 155 { 156 sc_uint_base::operator = (a); 157 } 158 sc_uint(int64 a) : sc_uint_base(W) 159 { 160 sc_uint_base::operator = (a); 161 } 162 sc_uint(double a) : sc_uint_base(W) 163 { 164 sc_uint_base::operator = (a); 165 } 166 167 // assignment operators 168 sc_uint<W> & 169 operator = (uint_type v) 170 { 171 sc_uint_base::operator = (v); 172 return *this; 173 } 174 sc_uint<W> & 175 operator = (const sc_uint_base &a) 176 { 177 sc_uint_base::operator = (a); 178 return *this; 179 } 180 sc_uint<W> & 181 operator = (const sc_uint_subref_r &a) 182 { 183 sc_uint_base::operator = (a); 184 return *this; 185 } 186 sc_uint<W> & 187 operator = (const sc_uint<W> &a) 188 { 189 m_val = a.m_val; 190 return *this; 191 } 192 template<class T> 193 sc_uint<W> & 194 operator = (const sc_generic_base<T> &a) 195 { 196 sc_uint_base::operator = (a); 197 return *this; 198 } 199 sc_uint<W> & 200 operator = (const sc_signed &a) 201 { 202 sc_uint_base::operator = (a); 203 return *this; 204 } 205 sc_uint<W> & 206 operator = (const sc_unsigned &a) 207 { 208 sc_uint_base::operator = (a); 209 return *this; 210 } 211 sc_uint<W> & 212 operator = (const sc_fxval &a) 213 { 214 sc_uint_base::operator = (a); 215 return *this; 216 } 217 sc_uint<W> & 218 operator = (const sc_fxval_fast &a) 219 { 220 sc_uint_base::operator = (a); 221 return *this; 222 } 223 sc_uint<W> & 224 operator = (const sc_fxnum &a) 225 { 226 sc_uint_base::operator = (a); 227 return *this; 228 } 229 sc_uint<W> & 230 operator = (const sc_fxnum_fast &a) 231 { 232 sc_uint_base::operator = (a); 233 return *this; 234 } 235 sc_uint<W> & 236 operator = (const sc_bv_base &a) 237 { 238 sc_uint_base::operator = (a); 239 return *this; 240 } 241 sc_uint<W> & 242 operator = (const sc_lv_base &a) 243 { 244 sc_uint_base::operator = (a); 245 return *this; 246 } 247 sc_uint<W> & 248 operator = (const char* a) 249 { 250 sc_uint_base::operator = (a); 251 return *this; 252 } 253 sc_uint<W> & 254 operator = (unsigned long a) 255 { 256 sc_uint_base::operator = (a); 257 return *this; 258 } 259 sc_uint<W> & 260 operator = (long a) 261 { 262 sc_uint_base::operator = (a); 263 return *this; 264 } 265 sc_uint<W> & 266 operator = (unsigned int a) 267 { 268 sc_uint_base::operator = (a); 269 return *this; 270 } 271 sc_uint<W> & 272 operator = (int a) 273 { 274 sc_uint_base::operator = (a); 275 return *this; 276 } 277 sc_uint<W> & 278 operator = (int64 a) 279 { 280 sc_uint_base::operator = (a); 281 return *this; 282 } 283 sc_uint<W> & 284 operator = (double a) 285 { 286 sc_uint_base::operator = (a); 287 return *this; 288 } 289 290 // arithmetic assignment operators 291 sc_uint<W> & 292 operator += (uint_type v) 293 { 294 sc_uint_base::operator += (v); 295 return *this; 296 } 297 sc_uint<W> & 298 operator -= (uint_type v) 299 { 300 sc_uint_base::operator -= (v); 301 return *this; 302 } 303 sc_uint<W> & 304 operator *= (uint_type v) 305 { 306 sc_uint_base::operator *= (v); 307 return *this; 308 } 309 sc_uint<W> & 310 operator /= (uint_type v) 311 { 312 sc_uint_base::operator /= (v); 313 return *this; 314 } 315 sc_uint<W> & 316 operator %= (uint_type v) 317 { 318 sc_uint_base::operator %= (v); 319 return *this; 320 } 321 322 // bitwise assignment operators 323 sc_uint<W> & 324 operator &= (uint_type v) 325 { 326 sc_uint_base::operator &= (v); 327 return *this; 328 } 329 sc_uint<W> & 330 operator |= (uint_type v) 331 { 332 sc_uint_base::operator |= (v); 333 return *this; 334 } 335 sc_uint<W> & 336 operator ^= (uint_type v) 337 { 338 sc_uint_base::operator ^= (v); 339 return *this; 340 } 341 342 sc_uint<W> & 343 operator <<= (uint_type v) 344 { 345 sc_uint_base::operator <<= (v); 346 return *this; 347 } 348 sc_uint<W> & 349 operator >>= (uint_type v) 350 { 351 sc_uint_base::operator >>= (v); 352 return *this; 353 } 354 355 // prefix and postfix increment and decrement operators 356 sc_uint<W> & 357 operator ++ () // prefix 358 { 359 sc_uint_base::operator ++ (); 360 return *this; 361 } 362 const sc_uint<W> 363 operator ++ ( int ) // postfix 364 { 365 return sc_uint<W>(sc_uint_base::operator ++ (0)); 366 } 367 sc_uint<W> & 368 operator -- () // prefix 369 { 370 sc_uint_base::operator -- (); 371 return *this; 372 } 373 const sc_uint<W> 374 operator -- (int) // postfix 375 { 376 return sc_uint<W>(sc_uint_base::operator -- (0)); 377 } 378}; 379 380} // namespace sc_dt 381 382#endif // __SYSTEMC_EXT_DT_INT_SC_UINT_HH__ 383