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_int.h -- A signed 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_int 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_int.h,v $ 51// Revision 1.2 2011/02/18 20:19:14 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:31 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_INT_HH__ 63#define __SYSTEMC_EXT_DT_INT_SC_INT_HH__ 64 65#include "sc_int_base.hh" 66 67namespace sc_dt 68{ 69 70// classes defined in this module 71template <int W> 72class sc_int; 73 74 75// ---------------------------------------------------------------------------- 76// CLASS TEMPLATE : sc_int<W> 77// 78// Template class sc_int<W> is the interface that the user sees. It is 79// derived from sc_int_base and most of its methods are just wrappers 80// that call the corresponding method in the parent class. Note that 81// the length of sc_int datatype is specified as a template parameter. 82// ---------------------------------------------------------------------------- 83 84template <int W> 85class sc_int : public sc_int_base 86{ 87 public: 88 // constructors 89 sc_int() : sc_int_base(W) {} 90 sc_int(int_type v) : sc_int_base(v, W) {} 91 sc_int(const sc_int<W> &a) : sc_int_base(a) {} 92 93 sc_int(const sc_int_base &a) : sc_int_base(W) 94 { 95 sc_int_base::operator = (a); 96 } 97 sc_int(const sc_int_subref_r &a) : sc_int_base(W) 98 { 99 sc_int_base::operator = (a); 100 } 101 template< class T > 102 sc_int(const sc_generic_base<T> &a) : sc_int_base(W) 103 { 104 sc_int_base::operator = (a->to_int64()); 105 } 106 sc_int(const sc_signed &a) : sc_int_base(W) 107 { 108 sc_int_base::operator = (a); 109 } 110 sc_int(const sc_unsigned &a) : sc_int_base(W) 111 { 112 sc_int_base::operator = (a); 113 } 114 explicit sc_int(const sc_fxval &a) : sc_int_base(W) 115 { 116 sc_int_base::operator = (a); 117 } 118 explicit sc_int(const sc_fxval_fast &a) : sc_int_base(W) 119 { 120 sc_int_base::operator = (a); 121 } 122 explicit sc_int(const sc_fxnum &a) : sc_int_base(W) 123 { 124 sc_int_base::operator = (a); 125 } 126 explicit sc_int(const sc_fxnum_fast &a) : sc_int_base(W) 127 { 128 sc_int_base::operator = (a); 129 } 130 sc_int(const sc_bv_base &a) : sc_int_base(W) 131 { 132 sc_int_base::operator = (a); 133 } 134 sc_int(const sc_lv_base &a) : sc_int_base(W) 135 { 136 sc_int_base::operator = (a); 137 } 138 sc_int(const char *a) : sc_int_base(W) 139 { 140 sc_int_base::operator = (a); 141 } 142 sc_int(unsigned long a) : sc_int_base(W) 143 { 144 sc_int_base::operator = (a); 145 } 146 sc_int(long a) : sc_int_base(W) 147 { 148 sc_int_base::operator = (a); 149 } 150 sc_int(unsigned int a) : sc_int_base(W) 151 { 152 sc_int_base::operator = (a); 153 } 154 sc_int(int a) : sc_int_base(W) 155 { 156 sc_int_base::operator = (a); 157 } 158 sc_int(uint64 a) : sc_int_base(W) 159 { 160 sc_int_base::operator = (a); 161 } 162 sc_int(double a) : sc_int_base(W) 163 { 164 sc_int_base::operator = (a); 165 } 166 167 // assignment operators 168 sc_int<W> & 169 operator = (int_type v) 170 { 171 sc_int_base::operator = (v); 172 return *this; 173 } 174 sc_int<W> & 175 operator = (const sc_int_base &a) 176 { 177 sc_int_base::operator = (a); 178 return *this; 179 } 180 sc_int<W> & 181 operator = (const sc_int_subref_r &a) 182 { 183 sc_int_base::operator = (a); 184 return *this; 185 } 186 sc_int<W> & 187 operator = (const sc_int<W> &a) 188 { 189 m_val = a.m_val; 190 return *this; 191 } 192 template< class T > 193 sc_int<W> & 194 operator = (const sc_generic_base<T> &a) 195 { 196 sc_int_base::operator = (a->to_int64()); 197 return *this; 198 } 199 sc_int<W> & 200 operator = (const sc_signed &a) 201 { 202 sc_int_base::operator = (a); 203 return *this; 204 } 205 sc_int<W> & 206 operator = (const sc_unsigned &a) 207 { 208 sc_int_base::operator = (a); 209 return *this; 210 } 211 sc_int<W> & 212 operator = (const sc_fxval &a) 213 { 214 sc_int_base::operator = (a); 215 return *this; 216 } 217 sc_int<W> & 218 operator = (const sc_fxval_fast &a) 219 { 220 sc_int_base::operator = (a); 221 return *this; 222 } 223 sc_int<W> & 224 operator = (const sc_fxnum &a) 225 { 226 sc_int_base::operator = (a); 227 return *this; 228 } 229 sc_int<W> &operator = (const sc_fxnum_fast &a) 230 { 231 sc_int_base::operator = (a); 232 return *this; 233 } 234 sc_int<W> & 235 operator = (const sc_bv_base &a) 236 { 237 sc_int_base::operator = (a); 238 return *this; 239 } 240 sc_int<W> & 241 operator = (const sc_lv_base &a) 242 { 243 sc_int_base::operator = (a); 244 return *this; 245 } 246 sc_int<W> & 247 operator = (const char *a) 248 { 249 sc_int_base::operator = (a); 250 return *this; 251 } 252 sc_int<W> & 253 operator = (unsigned long a) 254 { 255 sc_int_base::operator = (a); 256 return *this; 257 } 258 sc_int<W> & 259 operator = (long a) 260 { 261 sc_int_base::operator = (a); 262 return *this; 263 } 264 sc_int<W> & 265 operator = (unsigned int a) 266 { 267 sc_int_base::operator = (a); 268 return *this; 269 } 270 sc_int<W> & 271 operator = (int a) 272 { 273 sc_int_base::operator = (a); 274 return *this; 275 } 276 sc_int<W> & 277 operator = (uint64 a) 278 { 279 sc_int_base::operator = (a); 280 return *this; 281 } 282 sc_int<W> & 283 operator = (double a) 284 { 285 sc_int_base::operator = (a); 286 return *this; 287 } 288 289 // arithmetic assignment operators 290 sc_int<W> & 291 operator += (int_type v) 292 { 293 sc_int_base::operator += (v); 294 return *this; 295 } 296 sc_int<W> & 297 operator -= (int_type v) 298 { 299 sc_int_base::operator -= (v); 300 return *this; 301 } 302 sc_int<W> & 303 operator *= (int_type v) 304 { 305 sc_int_base::operator *= (v); 306 return *this; 307 } 308 sc_int<W> & 309 operator /= (int_type v) 310 { 311 sc_int_base::operator /= (v); 312 return *this; 313 } 314 sc_int<W> & 315 operator %= (int_type v) 316 { 317 sc_int_base::operator %= (v); 318 return *this; 319 } 320 321 // bitwise assignment operators 322 sc_int<W> & 323 operator &= (int_type v) 324 { 325 sc_int_base::operator &= (v); 326 return *this; 327 } 328 sc_int<W> & 329 operator |= (int_type v) 330 { 331 sc_int_base::operator |= (v); 332 return *this; 333 } 334 sc_int<W> & 335 operator ^= (int_type v) 336 { 337 sc_int_base::operator ^= (v); 338 return *this; 339 } 340 sc_int<W> & 341 operator <<= (int_type v) 342 { 343 sc_int_base::operator <<= (v); 344 return *this; 345 } 346 sc_int<W> & 347 operator >>= (int_type v) 348 { 349 sc_int_base::operator >>= (v); 350 return *this; 351 } 352 353 // prefix and postfix increment and decrement operators 354 sc_int<W> & 355 operator ++ () // prefix 356 { 357 sc_int_base::operator ++ (); 358 return *this; 359 } 360 const sc_int<W> 361 operator ++ (int) // postfix 362 { 363 return sc_int<W>(sc_int_base::operator ++ (0)); 364 } 365 sc_int<W> & 366 operator -- () // prefix 367 { 368 sc_int_base::operator -- (); 369 return *this; 370 } 371 const sc_int<W> 372 operator -- (int) // postfix 373 { 374 return sc_int<W>(sc_int_base::operator -- (0)); 375 } 376}; 377 378} // namespace sc_dt 379 380 381#endif // __SYSTEMC_EXT_DT_INT_SC_INT_HH__ 382