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_signed.h -- Arbitrary precision signed arithmetic. 23 24 This file includes the definitions of sc_signed_bitref, 25 sc_signed_subref, and sc_signed classes. The first two classes are 26 proxy classes to reference one bit and a range of bits of a 27 sc_signed number, respectively. 28 29 An sc_signed number has the sign-magnitude representation 30 internally. However, its interface guarantees a 2's-complement 31 representation. The sign-magnitude representation is chosen 32 because of its efficiency: The sc_signed and sc_unsigned types are 33 optimized for arithmetic rather than bitwise operations. For 34 arithmetic operations, the sign-magnitude representation performs 35 better. 36 37 The implementations of sc_signed and sc_unsigned classes are 38 almost identical: Most of the member and friend functions are 39 defined in sc_nbcommon.cpp and sc_nbfriends.cpp so that they can 40 be shared by both of these classes. These functions are chosed by 41 defining a few macros before including them such as IF_SC_SIGNED 42 and CLASS_TYPE. Our implementation choices are mostly dictated by 43 performance considerations in that we tried to provide the most 44 efficient sc_signed and sc_unsigned types without compromising 45 their interface. 46 47 For the behavior of operators, we have two semantics: the old and 48 new. The most important difference between these two semantics is 49 that the old semantics is closer to C/C++ semantics in that the 50 result type of a binary operator on unsigned and signed arguments 51 is unsigned; the new semantics, on the other hand, requires the 52 result type be signed. The new semantics is required by the VSIA 53 C/C++ data types standard. We have implemented the new semantics. 54 55 Original Author: Ali Dasdan, Synopsys, Inc. 56 57 *****************************************************************************/ 58 59/***************************************************************************** 60 61 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 62 changes you are making here. 63 64 Name, Affiliation, Date: 65 Description of Modification: 66 67 *****************************************************************************/ 68 69// $Log: sc_signed.h,v $ 70// Revision 1.3 2011/08/24 22:05:46 acg 71// Torsten Maehne: initialization changes to remove warnings. 72// 73// Revision 1.2 2011/02/18 20:19:15 acg 74// Andy Goodrich: updating Copyright notice. 75// 76// Revision 1.1.1.1 2006/12/15 20:20:05 acg 77// SystemC 2.3 78// 79// Revision 1.5 2006/05/08 17:50:01 acg 80// Andy Goodrich: Added David Long's declarations for friend operators, 81// functions, and methods, to keep the Microsoft compiler happy. 82// 83// Revision 1.4 2006/03/13 20:25:27 acg 84// Andy Goodrich: Addition of function declarations, e.g., xor_signed_friend() 85// to keep gcc 4.x happy. 86// 87// Revision 1.3 2006/01/13 18:49:32 acg 88// Added $Log command so that CVS check in comments are reproduced in the 89// source. 90// 91 92#ifndef SC_SIGNED_H 93#define SC_SIGNED_H 94 95 96#include "sysc/kernel/sc_object.h" 97#include "sysc/datatypes/misc/sc_value_base.h" 98#include "sysc/utils/sc_iostream.h" 99#include "sysc/utils/sc_temporary.h" 100#include "sysc/datatypes/int/sc_length_param.h" 101#include "sysc/datatypes/int/sc_nbdefs.h" 102#include "sysc/datatypes/int/sc_nbutils.h" 103#include "sysc/datatypes/int/sc_nbexterns.h" 104#include "sysc/datatypes/int/sc_unsigned.h" 105 106 107namespace sc_dt 108{ 109 110// classes defined in this module 111class sc_signed_bitref_r; 112class sc_signed_bitref; 113class sc_signed_subref_r; 114class sc_signed_subref; 115class sc_concatref; 116class sc_signed; 117 118// forward class declarations 119class sc_bv_base; 120class sc_lv_base; 121class sc_int_base; 122class sc_uint_base; 123class sc_int_subref_r; 124class sc_uint_subref_r; 125class sc_signed; 126class sc_unsigned; 127class sc_unsigned_subref_r; 128class sc_fxval; 129class sc_fxval_fast; 130class sc_fxnum; 131class sc_fxnum_fast; 132 133 134// Helper function declarations 135sc_signed add_signed_friend(small_type us, 136 int unb, 137 int und, 138 const sc_digit *ud, 139 small_type vs, 140 int vnb, 141 int vnd, 142 const sc_digit *vd); 143 144sc_signed sub_signed_friend(small_type us, 145 int unb, 146 int und, 147 const sc_digit *ud, 148 small_type vs, 149 int vnb, 150 int vnd, 151 const sc_digit *vd); 152 153sc_signed mul_signed_friend(small_type s, 154 int unb, 155 int und, 156 const sc_digit *ud, 157 int vnb, 158 int vnd, 159 const sc_digit *vd); 160 161sc_signed div_signed_friend(small_type s, 162 int unb, 163 int und, 164 const sc_digit *ud, 165 int vnb, 166 int vnd, 167 const sc_digit *vd); 168 169sc_signed mod_signed_friend(small_type us, 170 int unb, 171 int und, 172 const sc_digit *ud, 173 int vnb, 174 int vnd, 175 const sc_digit *vd); 176 177sc_signed and_signed_friend(small_type us, 178 int unb, 179 int und, 180 const sc_digit *ud, 181 small_type vs, 182 int vnb, 183 int vnd, 184 const sc_digit *vd); 185 186sc_signed or_signed_friend(small_type us, 187 int unb, 188 int und, 189 const sc_digit *ud, 190 small_type vs, 191 int vnb, 192 int vnd, 193 const sc_digit *vd); 194 195sc_signed xor_signed_friend(small_type us, 196 int unb, 197 int und, 198 const sc_digit *ud, 199 small_type vs, 200 int vnb, 201 int vnd, 202 const sc_digit *vd); 203 204 205// friend operator declarations 206 // ARITHMETIC OPERATORS: 207 208 // ADDition operators: 209 210 sc_signed operator + (const sc_unsigned& u, const sc_signed& v); 211 sc_signed operator + (const sc_signed& u, const sc_unsigned& v); 212 213 sc_signed operator + (const sc_unsigned& u, int64 v); 214 sc_signed operator + (const sc_unsigned& u, long v); 215 inline sc_signed operator + (const sc_unsigned& u, int v); 216 217 sc_signed operator + (int64 u, const sc_unsigned& v); 218 sc_signed operator + (long u, const sc_unsigned& v); 219 inline sc_signed operator + (int u, const sc_unsigned& v); 220 221 sc_signed operator + (const sc_signed& u, const sc_signed& v); 222 sc_signed operator + (const sc_signed& u, int64 v); 223 sc_signed operator + (const sc_signed& u, uint64 v); 224 sc_signed operator + (const sc_signed& u, long v); 225 sc_signed operator + (const sc_signed& u, unsigned long v); 226 inline sc_signed operator + (const sc_signed& u, int v); 227 inline sc_signed operator + (const sc_signed& u, unsigned int v); 228 229 sc_signed operator + (int64 u, const sc_signed& v); 230 sc_signed operator + (uint64 u, const sc_signed& v); 231 sc_signed operator + (long u, const sc_signed& v); 232 sc_signed operator + (unsigned long u, const sc_signed& v); 233 inline sc_signed operator + (int u, const sc_signed& v); 234 inline sc_signed operator + (unsigned int u, const sc_signed& v); 235 236 sc_signed operator + (const sc_unsigned& u, const sc_int_base& v); 237 sc_signed operator + (const sc_int_base& u, const sc_unsigned& v); 238 sc_signed operator + (const sc_signed& u, const sc_int_base& v); 239 sc_signed operator + (const sc_signed& u, const sc_uint_base& v); 240 sc_signed operator + (const sc_int_base& u, const sc_signed& v); 241 sc_signed operator + (const sc_uint_base& u, const sc_signed& v); 242 243 244 245 // SUBtraction operators: 246 247 sc_signed operator - (const sc_unsigned& u, const sc_signed& v); 248 sc_signed operator - (const sc_signed& u, const sc_unsigned& v); 249 250 sc_signed operator - (const sc_unsigned& u, const sc_unsigned& v); 251 sc_signed operator - (const sc_unsigned& u, int64 v); 252 sc_signed operator - (const sc_unsigned& u, uint64 v); 253 sc_signed operator - (const sc_unsigned& u, long v); 254 sc_signed operator - (const sc_unsigned& u, unsigned long v); 255 inline sc_signed operator - (const sc_unsigned& u, int v); 256 inline sc_signed operator - (const sc_unsigned& u, unsigned int v); 257 258 sc_signed operator - (int64 u, const sc_unsigned& v); 259 sc_signed operator - (uint64 u, const sc_unsigned& v); 260 sc_signed operator - (long u, const sc_unsigned& v); 261 sc_signed operator - (unsigned long u, const sc_unsigned& v); 262 inline sc_signed operator - (int u, const sc_unsigned& v); 263 inline sc_signed operator - (unsigned int u, const sc_unsigned& v); 264 265 sc_signed operator - (const sc_signed& u, const sc_signed& v); 266 sc_signed operator - (const sc_signed& u, int64 v); 267 sc_signed operator - (const sc_signed& u, uint64 v); 268 sc_signed operator - (const sc_signed& u, long v); 269 sc_signed operator - (const sc_signed& u, unsigned long v); 270 inline sc_signed operator - (const sc_signed& u, int v); 271 inline sc_signed operator - (const sc_signed& u, unsigned int v); 272 273 sc_signed operator - (int64 u, const sc_signed& v); 274 sc_signed operator - (uint64 u, const sc_signed& v); 275 sc_signed operator - (long u, const sc_signed& v); 276 sc_signed operator - (unsigned long u, const sc_signed& v); 277 inline sc_signed operator - (int u, const sc_signed& v); 278 inline sc_signed operator - (unsigned int u, const sc_signed& v); 279 280 281 sc_signed operator - (const sc_unsigned& u, const sc_int_base& v); 282 sc_signed operator - (const sc_unsigned& u, const sc_uint_base& v); 283 sc_signed operator - (const sc_int_base& u, const sc_unsigned& v); 284 sc_signed operator - (const sc_uint_base& u, const sc_unsigned& v); 285 sc_signed operator - (const sc_signed& u, const sc_int_base& v); 286 sc_signed operator - (const sc_signed& u, const sc_uint_base& v); 287 sc_signed operator - (const sc_int_base& u, const sc_signed& v); 288 sc_signed operator - (const sc_uint_base& u, const sc_signed& v); 289 290 291 292 // MULtiplication operators: 293 294 sc_signed operator * (const sc_unsigned& u, const sc_signed& v); 295 sc_signed operator * (const sc_signed& u, const sc_unsigned& v); 296 297 sc_signed operator * (const sc_unsigned& u, int64 v); 298 sc_signed operator * (const sc_unsigned& u, long v); 299 inline sc_signed operator * (const sc_unsigned& u, int v); 300 301 sc_signed operator * (int64 u, const sc_unsigned& v); 302 sc_signed operator * (long u, const sc_unsigned& v); 303 inline sc_signed operator * (int u, const sc_unsigned& v); 304 305 sc_signed operator * (const sc_signed& u, const sc_signed& v); 306 sc_signed operator * (const sc_signed& u, int64 v); 307 sc_signed operator * (const sc_signed& u, uint64 v); 308 sc_signed operator * (const sc_signed& u, long v); 309 sc_signed operator * (const sc_signed& u, unsigned long v); 310 inline sc_signed operator * (const sc_signed& u, int v); 311 inline sc_signed operator * (const sc_signed& u, unsigned int v); 312 313 sc_signed operator * (int64 u, const sc_signed& v); 314 sc_signed operator * (uint64 u, const sc_signed& v); 315 sc_signed operator * (long u, const sc_signed& v); 316 sc_signed operator * (unsigned long u, const sc_signed& v); 317 inline sc_signed operator * (int u, const sc_signed& v); 318 inline sc_signed operator * (unsigned int u, const sc_signed& v); 319 320 sc_signed operator * (const sc_unsigned& u, const sc_int_base& v); 321 sc_signed operator * (const sc_int_base& u, const sc_unsigned& v); 322 sc_signed operator * (const sc_signed& u, const sc_int_base& v); 323 sc_signed operator * (const sc_signed& u, const sc_uint_base& v); 324 sc_signed operator * (const sc_int_base& u, const sc_signed& v); 325 sc_signed operator * (const sc_uint_base& u, const sc_signed& v); 326 327 328 329 // DIVision operators: 330 331 sc_signed operator / (const sc_unsigned& u, const sc_signed& v); 332 sc_signed operator / (const sc_signed& u, const sc_unsigned& v); 333 334 sc_signed operator / (const sc_unsigned& u, int64 v); 335 sc_signed operator / (const sc_unsigned& u, long v); 336 inline sc_signed operator / (const sc_unsigned& u, int v); 337 338 sc_signed operator / (int64 u, const sc_unsigned& v); 339 sc_signed operator / (long u, const sc_unsigned& v); 340 inline sc_signed operator / (int u, const sc_unsigned& v); 341 342 sc_signed operator / (const sc_signed& u, const sc_signed& v); 343 sc_signed operator / (const sc_signed& u, int64 v); 344 sc_signed operator / (const sc_signed& u, uint64 v); 345 sc_signed operator / (const sc_signed& u, long v); 346 sc_signed operator / (const sc_signed& u, unsigned long v); 347 inline sc_signed operator / (const sc_signed& u, int v); 348 inline sc_signed operator / (const sc_signed& u, unsigned int v); 349 350 sc_signed operator / (int64 u, const sc_signed& v); 351 sc_signed operator / (uint64 u, const sc_signed& v); 352 sc_signed operator / (long u, const sc_signed& v); 353 sc_signed operator / (unsigned long u, const sc_signed& v); 354 inline sc_signed operator / (int u, const sc_signed& v); 355 inline sc_signed operator / (unsigned int u, const sc_signed& v); 356 357 sc_signed operator / (const sc_unsigned& u, const sc_int_base& v); 358 sc_signed operator / (const sc_int_base& u, const sc_unsigned& v); 359 sc_signed operator / (const sc_signed& u, const sc_int_base& v); 360 sc_signed operator / (const sc_signed& u, const sc_uint_base& v); 361 sc_signed operator / (const sc_int_base& u, const sc_signed& v); 362 sc_signed operator / (const sc_uint_base& u, const sc_signed& v); 363 364 365 366 // MODulo operators: 367 368 sc_signed operator % (const sc_unsigned& u, const sc_signed& v); 369 sc_signed operator % (const sc_signed& u, const sc_unsigned& v); 370 371 sc_signed operator % (const sc_unsigned& u, int64 v); 372 sc_signed operator % (const sc_unsigned& u, long v); 373 inline sc_signed operator % (const sc_unsigned& u, int v); 374 375 sc_signed operator % (int64 u, const sc_unsigned& v); 376 sc_signed operator % (long u, const sc_unsigned& v); 377 inline sc_signed operator % (int u, const sc_unsigned& v); 378 379 sc_signed operator % (const sc_signed& u, const sc_signed& v); 380 sc_signed operator % (const sc_signed& u, int64 v); 381 sc_signed operator % (const sc_signed& u, uint64 v); 382 sc_signed operator % (const sc_signed& u, long v); 383 sc_signed operator % (const sc_signed& u, unsigned long v); 384 inline sc_signed operator % (const sc_signed& u, int v); 385 inline sc_signed operator % (const sc_signed& u, unsigned int v); 386 387 sc_signed operator % (int64 u, const sc_signed& v); 388 sc_signed operator % (uint64 u, const sc_signed& v); 389 sc_signed operator % (long u, const sc_signed& v); 390 sc_signed operator % (unsigned long u, const sc_signed& v); 391 inline sc_signed operator % (int u, const sc_signed& v); 392 inline sc_signed operator % (unsigned int u, const sc_signed& v); 393 394 sc_signed operator % (const sc_unsigned& u, const sc_int_base& v); 395 sc_signed operator % (const sc_int_base& u, const sc_unsigned& v); 396 sc_signed operator % (const sc_signed& u, const sc_int_base& v); 397 sc_signed operator % (const sc_signed& u, const sc_uint_base& v); 398 sc_signed operator % (const sc_int_base& u, const sc_signed& v); 399 sc_signed operator % (const sc_uint_base& u, const sc_signed& v); 400 401 402 403 // BITWISE OPERATORS: 404 405 // Bitwise AND operators: 406 407 sc_signed operator & (const sc_unsigned& u, const sc_signed& v); 408 sc_signed operator & (const sc_signed& u, const sc_unsigned& v); 409 410 sc_signed operator & (const sc_unsigned& u, int64 v); 411 sc_signed operator & (const sc_unsigned& u, long v); 412 inline sc_signed operator & (const sc_unsigned& u, int v); 413 414 sc_signed operator & (int64 u, const sc_unsigned& v); 415 sc_signed operator & (long u, const sc_unsigned& v); 416 inline sc_signed operator & (int u, const sc_unsigned& v); 417 418 sc_signed operator & (const sc_signed& u, const sc_signed& v); 419 sc_signed operator & (const sc_signed& u, int64 v); 420 sc_signed operator & (const sc_signed& u, uint64 v); 421 sc_signed operator & (const sc_signed& u, long v); 422 sc_signed operator & (const sc_signed& u, unsigned long v); 423 inline sc_signed operator & (const sc_signed& u, int v); 424 inline sc_signed operator & (const sc_signed& u, unsigned int v); 425 426 sc_signed operator & (int64 u, const sc_signed& v); 427 sc_signed operator & (uint64 u, const sc_signed& v); 428 sc_signed operator & (long u, const sc_signed& v); 429 sc_signed operator & (unsigned long u, const sc_signed& v); 430 inline sc_signed operator & (int u, const sc_signed& v); 431 inline sc_signed operator & (unsigned int u, const sc_signed& v); 432 433 sc_signed operator & (const sc_unsigned& u, const sc_int_base& v); 434 sc_signed operator & (const sc_int_base& u, const sc_unsigned& v); 435 sc_signed operator & (const sc_signed& u, const sc_int_base& v); 436 sc_signed operator & (const sc_signed& u, const sc_uint_base& v); 437 sc_signed operator & (const sc_int_base& u, const sc_signed& v); 438 sc_signed operator & (const sc_uint_base& u, const sc_signed& v); 439 440 441 442 // Bitwise OR operators: 443 444 sc_signed operator | (const sc_unsigned& u, const sc_signed& v); 445 sc_signed operator | (const sc_signed& u, const sc_unsigned& v); 446 447 sc_signed operator | (const sc_unsigned& u, int64 v); 448 sc_signed operator | (const sc_unsigned& u, long v); 449 inline sc_signed operator | (const sc_unsigned& u, int v); 450 451 sc_signed operator | (int64 u, const sc_unsigned& v); 452 sc_signed operator | (long u, const sc_unsigned& v); 453 inline sc_signed operator | (int u, const sc_unsigned& v); 454 455 sc_signed operator | (const sc_signed& u, const sc_signed& v); 456 sc_signed operator | (const sc_signed& u, int64 v); 457 sc_signed operator | (const sc_signed& u, uint64 v); 458 sc_signed operator | (const sc_signed& u, long v); 459 sc_signed operator | (const sc_signed& u, unsigned long v); 460 inline sc_signed operator | (const sc_signed& u, int v); 461 inline sc_signed operator | (const sc_signed& u, unsigned int v); 462 463 sc_signed operator | (int64 u, const sc_signed& v); 464 sc_signed operator | (uint64 u, const sc_signed& v); 465 sc_signed operator | (long u, const sc_signed& v); 466 sc_signed operator | (unsigned long u, const sc_signed& v); 467 inline sc_signed operator | (int u, const sc_signed& v); 468 inline sc_signed operator | (unsigned int u, const sc_signed& v); 469 470 sc_signed operator | (const sc_unsigned& u, const sc_int_base& v); 471 sc_signed operator | (const sc_int_base& u, const sc_unsigned& v); 472 sc_signed operator | (const sc_signed& u, const sc_int_base& v); 473 sc_signed operator | (const sc_signed& u, const sc_uint_base& v); 474 sc_signed operator | (const sc_int_base& u, const sc_signed& v); 475 sc_signed operator | (const sc_uint_base& u, const sc_signed& v); 476 477 478 479 // Bitwise XOR operators: 480 481 sc_signed operator ^ (const sc_unsigned& u, const sc_signed& v); 482 sc_signed operator ^ (const sc_signed& u, const sc_unsigned& v); 483 484 sc_signed operator ^ (const sc_unsigned& u, int64 v); 485 sc_signed operator ^ (const sc_unsigned& u, long v); 486 inline sc_signed operator ^ (const sc_unsigned& u, int v); 487 488 sc_signed operator ^ (int64 u, const sc_unsigned& v); 489 sc_signed operator ^ (long u, const sc_unsigned& v); 490 inline sc_signed operator ^ (int u, const sc_unsigned& v); 491 492 sc_signed operator ^ (const sc_signed& u, const sc_signed& v); 493 sc_signed operator ^ (const sc_signed& u, int64 v); 494 sc_signed operator ^ (const sc_signed& u, uint64 v); 495 sc_signed operator ^ (const sc_signed& u, long v); 496 sc_signed operator ^ (const sc_signed& u, unsigned long v); 497 inline sc_signed operator ^ (const sc_signed& u, int v); 498 inline sc_signed operator ^ (const sc_signed& u, unsigned int v); 499 500 sc_signed operator ^ (int64 u, const sc_signed& v); 501 sc_signed operator ^ (uint64 u, const sc_signed& v); 502 sc_signed operator ^ (long u, const sc_signed& v); 503 sc_signed operator ^ (unsigned long u, const sc_signed& v); 504 inline sc_signed operator ^ (int u, const sc_signed& v); 505 inline sc_signed operator ^ (unsigned int u, const sc_signed& v); 506 507 sc_signed operator ^ (const sc_unsigned& u, const sc_int_base& v); 508 sc_signed operator ^ (const sc_int_base& u, const sc_unsigned& v); 509 sc_signed operator ^ (const sc_signed& u, const sc_int_base& v); 510 sc_signed operator ^ (const sc_signed& u, const sc_uint_base& v); 511 sc_signed operator ^ (const sc_int_base& u, const sc_signed& v); 512 sc_signed operator ^ (const sc_uint_base& u, const sc_signed& v); 513 514 515 516 // SHIFT OPERATORS: 517 518 // LEFT SHIFT operators: 519 520 sc_unsigned operator << (const sc_unsigned& u, const sc_signed& v); 521 sc_signed operator << (const sc_signed& u, const sc_unsigned& v); 522 523 sc_signed operator << (const sc_signed& u, const sc_signed& v); 524 sc_signed operator << (const sc_signed& u, int64 v); 525 sc_signed operator << (const sc_signed& u, uint64 v); 526 sc_signed operator << (const sc_signed& u, long v); 527 sc_signed operator << (const sc_signed& u, unsigned long v); 528 inline sc_signed operator << (const sc_signed& u, int v); 529 inline sc_signed operator << (const sc_signed& u, unsigned int v); 530 531 sc_signed operator << (const sc_signed& u, const sc_int_base& v); 532 sc_signed operator << (const sc_signed& u, const sc_uint_base& v); 533 534 535 536 // RIGHT SHIFT operators: 537 538 sc_unsigned operator >> (const sc_unsigned& u, const sc_signed& v); 539 sc_signed operator >> (const sc_signed& u, const sc_unsigned& v); 540 541 sc_signed operator >> (const sc_signed& u, const sc_signed& v); 542 sc_signed operator >> (const sc_signed& u, int64 v); 543 sc_signed operator >> (const sc_signed& u, uint64 v); 544 sc_signed operator >> (const sc_signed& u, long v); 545 sc_signed operator >> (const sc_signed& u, unsigned long v); 546 inline sc_signed operator >> (const sc_signed& u, int v); 547 inline sc_signed operator >> (const sc_signed& u, unsigned int v); 548 549 sc_signed operator >> (const sc_signed& u, const sc_int_base& v); 550 sc_signed operator >> (const sc_signed& u, const sc_uint_base& v); 551 552 553 554 // Unary arithmetic operators 555 sc_signed operator + (const sc_signed& u); 556 sc_signed operator - (const sc_signed& u); 557 sc_signed operator - (const sc_unsigned& u); 558 559 // LOGICAL OPERATORS: 560 561 // Logical EQUAL operators: 562 563 bool operator == (const sc_unsigned& u, const sc_signed& v); 564 bool operator == (const sc_signed& u, const sc_unsigned& v); 565 566 bool operator == (const sc_signed& u, const sc_signed& v); 567 bool operator == (const sc_signed& u, int64 v); 568 bool operator == (const sc_signed& u, uint64 v); 569 bool operator == (const sc_signed& u, long v); 570 bool operator == (const sc_signed& u, unsigned long v); 571 inline bool operator == (const sc_signed& u, int v); 572 inline bool operator == (const sc_signed& u, unsigned int v); 573 574 bool operator == (int64 u, const sc_signed& v); 575 bool operator == (uint64 u, const sc_signed& v); 576 bool operator == (long u, const sc_signed& v); 577 bool operator == (unsigned long u, const sc_signed& v); 578 inline bool operator == (int u, const sc_signed& v); 579 inline bool operator == (unsigned int u, const sc_signed& v); 580 581 bool operator == (const sc_signed& u, const sc_int_base& v); 582 bool operator == (const sc_signed& u, const sc_uint_base& v); 583 bool operator == (const sc_int_base& u, const sc_signed& v); 584 bool operator == (const sc_uint_base& u, const sc_signed& v); 585 586 // Logical NOT_EQUAL operators: 587 588 bool operator != (const sc_unsigned& u, const sc_signed& v); 589 bool operator != (const sc_signed& u, const sc_unsigned& v); 590 591 bool operator != (const sc_signed& u, const sc_signed& v); 592 bool operator != (const sc_signed& u, int64 v); 593 bool operator != (const sc_signed& u, uint64 v); 594 bool operator != (const sc_signed& u, long v); 595 bool operator != (const sc_signed& u, unsigned long v); 596 inline bool operator != (const sc_signed& u, int v); 597 inline bool operator != (const sc_signed& u, unsigned int v); 598 599 bool operator != (int64 u, const sc_signed& v); 600 bool operator != (uint64 u, const sc_signed& v); 601 bool operator != (long u, const sc_signed& v); 602 bool operator != (unsigned long u, const sc_signed& v); 603 inline bool operator != (int u, const sc_signed& v); 604 inline bool operator != (unsigned int u, const sc_signed& v); 605 606 bool operator != (const sc_signed& u, const sc_int_base& v); 607 bool operator != (const sc_signed& u, const sc_uint_base& v); 608 bool operator != (const sc_int_base& u, const sc_signed& v); 609 bool operator != (const sc_uint_base& u, const sc_signed& v); 610 611 // Logical LESS_THAN operators: 612 613 bool operator < (const sc_unsigned& u, const sc_signed& v); 614 bool operator < (const sc_signed& u, const sc_unsigned& v); 615 616 bool operator < (const sc_signed& u, const sc_signed& v); 617 bool operator < (const sc_signed& u, int64 v); 618 bool operator < (const sc_signed& u, uint64 v); 619 bool operator < (const sc_signed& u, long v); 620 bool operator < (const sc_signed& u, unsigned long v); 621 inline bool operator < (const sc_signed& u, int v); 622 inline bool operator < (const sc_signed& u, unsigned int v); 623 624 bool operator < (int64 u, const sc_signed& v); 625 bool operator < (uint64 u, const sc_signed& v); 626 bool operator < (long u, const sc_signed& v); 627 bool operator < (unsigned long u, const sc_signed& v); 628 inline bool operator < (int u, const sc_signed& v); 629 inline bool operator < (unsigned int u, const sc_signed& v); 630 631 bool operator < (const sc_signed& u, const sc_int_base& v); 632 bool operator < (const sc_signed& u, const sc_uint_base& v); 633 bool operator < (const sc_int_base& u, const sc_signed& v); 634 bool operator < (const sc_uint_base& u, const sc_signed& v); 635 636 // Logical LESS_THAN_AND_EQUAL operators: 637 638 bool operator <= (const sc_unsigned& u, const sc_signed& v); 639 bool operator <= (const sc_signed& u, const sc_unsigned& v); 640 641 bool operator <= (const sc_signed& u, const sc_signed& v); 642 bool operator <= (const sc_signed& u, int64 v); 643 bool operator <= (const sc_signed& u, uint64 v); 644 bool operator <= (const sc_signed& u, long v); 645 bool operator <= (const sc_signed& u, unsigned long v); 646 inline bool operator <= (const sc_signed& u, int v); 647 inline bool operator <= (const sc_signed& u, unsigned int v); 648 649 bool operator <= (int64 u, const sc_signed& v); 650 bool operator <= (uint64 u, const sc_signed& v); 651 bool operator <= (long u, const sc_signed& v); 652 bool operator <= (unsigned long u, const sc_signed& v); 653 inline bool operator <= (int u, const sc_signed& v); 654 inline bool operator <= (unsigned int u, const sc_signed& v); 655 656 bool operator <= (const sc_signed& u, const sc_int_base& v); 657 bool operator <= (const sc_signed& u, const sc_uint_base& v); 658 bool operator <= (const sc_int_base& u, const sc_signed& v); 659 bool operator <= (const sc_uint_base& u, const sc_signed& v); 660 661 // Logical GREATER_THAN operators: 662 663 bool operator > (const sc_unsigned& u, const sc_signed& v); 664 bool operator > (const sc_signed& u, const sc_unsigned& v); 665 666 bool operator > (const sc_signed& u, const sc_signed& v); 667 bool operator > (const sc_signed& u, int64 v); 668 bool operator > (const sc_signed& u, uint64 v); 669 bool operator > (const sc_signed& u, long v); 670 bool operator > (const sc_signed& u, unsigned long v); 671 inline bool operator > (const sc_signed& u, int v); 672 inline bool operator > (const sc_signed& u, unsigned int v); 673 674 bool operator > (int64 u, const sc_signed& v); 675 bool operator > (uint64 u, const sc_signed& v); 676 bool operator > (long u, const sc_signed& v); 677 bool operator > (unsigned long u, const sc_signed& v); 678 inline bool operator > (int u, const sc_signed& v); 679 inline bool operator > (unsigned int u, const sc_signed& v); 680 681 bool operator > (const sc_signed& u, const sc_int_base& v); 682 bool operator > (const sc_signed& u, const sc_uint_base& v); 683 bool operator > (const sc_int_base& u, const sc_signed& v); 684 bool operator > (const sc_uint_base& u, const sc_signed& v); 685 686 // Logical GREATER_THAN_AND_EQUAL operators: 687 688 bool operator >= (const sc_unsigned& u, const sc_signed& v); 689 bool operator >= (const sc_signed& u, const sc_unsigned& v); 690 691 bool operator >= (const sc_signed& u, const sc_signed& v); 692 bool operator >= (const sc_signed& u, int64 v); 693 bool operator >= (const sc_signed& u, uint64 v); 694 bool operator >= (const sc_signed& u, long v); 695 bool operator >= (const sc_signed& u, unsigned long v); 696 inline bool operator >= (const sc_signed& u, int v); 697 inline bool operator >= (const sc_signed& u, unsigned int v); 698 699 bool operator >= (int64 u, const sc_signed& v); 700 bool operator >= (uint64 u, const sc_signed& v); 701 bool operator >= (long u, const sc_signed& v); 702 bool operator >= (unsigned long u, const sc_signed& v); 703 inline bool operator >= (int u, const sc_signed& v); 704 inline bool operator >= (unsigned int u, const sc_signed& v); 705 706 bool operator >= (const sc_signed& u, const sc_int_base& v); 707 bool operator >= (const sc_signed& u, const sc_uint_base& v); 708 bool operator >= (const sc_int_base& u, const sc_signed& v); 709 bool operator >= (const sc_uint_base& u, const sc_signed& v); 710 711 // Bitwise NOT operator (unary). 712 sc_signed operator ~ (const sc_signed& u); 713 714// ---------------------------------------------------------------------------- 715// CLASS : sc_signed_bitref_r 716// 717// Proxy class for sc_signed bit selection (r-value only). 718// ---------------------------------------------------------------------------- 719 720class sc_signed_bitref_r : public sc_value_base 721{ 722 friend class sc_signed; 723 724protected: 725 726 // constructor 727 728 sc_signed_bitref_r() : sc_value_base(), m_index(0), m_obj_p(0) 729 {} 730 731 void initialize( const sc_signed* obj_p, int index_ ) 732 { 733 m_index = index_; 734 m_obj_p = ( CCAST<sc_signed*>( obj_p ) ); 735 } 736 737public: 738 739 // destructor 740 741 virtual ~sc_signed_bitref_r() 742 {} 743 744 // copy constructor 745 746 sc_signed_bitref_r( const sc_signed_bitref_r& a ) 747 : sc_value_base(a), m_index( a.m_index ), m_obj_p( a.m_obj_p ) 748 {} 749 750 // capacity 751 752 int length() const 753 { return 1; } 754 755 756 // implicit conversion to bool 757 758 operator uint64 () const; 759 bool operator ! () const; 760 bool operator ~ () const; 761 762 763 // explicit conversions 764 765 bool value() const 766 { return operator uint64(); } 767 768 bool to_bool() const 769 { return operator uint64(); } 770 771 // concatenation support 772 773 virtual int concat_length(bool* xz_present_p) const 774 { if ( xz_present_p ) *xz_present_p = false; return 1; } 775 virtual uint64 concat_get_uint64() const 776 { return (uint64)operator uint64(); } 777 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const 778 { 779 int bit_mask = 1 << (low_i % BITS_PER_DIGIT); 780 int word_i = low_i / BITS_PER_DIGIT; 781 dst_p[word_i] &= ~bit_mask; 782 return false; 783 } 784 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const 785 { 786 int bit_mask = 1 << (low_i % BITS_PER_DIGIT); 787 bool result; // True if non-zero. 788 int word_i = low_i / BITS_PER_DIGIT; 789 if ( operator uint64() ) 790 { 791 dst_p[word_i] |= bit_mask; 792 result = true; 793 } 794 else 795 { 796 dst_p[word_i] &= ~bit_mask; 797 result = false; 798 } 799 return result; 800 } 801 802 803 // other methods 804 805 void print( ::std::ostream& os = ::std::cout ) const 806 { os << to_bool(); } 807 808protected: 809 810 int m_index; // Bit to be selected. 811 sc_signed* m_obj_p; // Target of this bit selection. 812 813private: 814 815 // disabled 816 const sc_signed_bitref_r& operator = ( const sc_signed_bitref_r& ); 817}; 818 819 820 821inline 822::std::ostream& 823operator << ( ::std::ostream&, const sc_signed_bitref_r& ); 824 825 826// ---------------------------------------------------------------------------- 827// CLASS : sc_signed_bitref 828// 829// Proxy class for sc_signed bit selection (r-value and l-value). 830// ---------------------------------------------------------------------------- 831 832class sc_signed_bitref 833 : public sc_signed_bitref_r 834{ 835 friend class sc_signed; 836 friend class sc_core::sc_vpool<sc_signed_bitref>; 837 838 839 // constructor 840 841protected: 842 843 sc_signed_bitref() : sc_signed_bitref_r() 844 {} 845 846public: 847 848 // copy constructor 849 850 sc_signed_bitref( const sc_signed_bitref& a ) 851 : sc_signed_bitref_r( a ) 852 {} 853 854 // assignment operators 855 856 const sc_signed_bitref& operator = ( const sc_signed_bitref_r& ); 857 const sc_signed_bitref& operator = ( const sc_signed_bitref& ); 858 const sc_signed_bitref& operator = ( bool ); 859 860 const sc_signed_bitref& operator &= ( bool ); 861 const sc_signed_bitref& operator |= ( bool ); 862 const sc_signed_bitref& operator ^= ( bool ); 863 864 // concatenation methods 865 866 virtual void concat_set(int64 src, int low_i); 867 virtual void concat_set(const sc_signed& src, int low_i); 868 virtual void concat_set(const sc_unsigned& src, int low_i); 869 virtual void concat_set(uint64 src, int low_i); 870 871 872 // other methods 873 874 void scan( ::std::istream& is = ::std::cin ); 875 876protected: 877 static sc_core::sc_vpool<sc_signed_bitref> m_pool; 878}; 879 880 881 882inline 883::std::istream& 884operator >> ( ::std::istream&, sc_signed_bitref& ); 885 886 887// ---------------------------------------------------------------------------- 888// CLASS : sc_signed_subref_r 889// 890// Proxy class for sc_signed part selection (r-value only). 891// ---------------------------------------------------------------------------- 892 893class sc_signed_subref_r : public sc_value_base 894{ 895 friend class sc_signed; 896 friend class sc_signed_signal; 897 friend class sc_unsigned; 898 899protected: 900 901 // constructor 902 903 sc_signed_subref_r() : sc_value_base(), m_left(0), m_obj_p(0), m_right(0) 904 {} 905 906 void initialize( const sc_signed* obj_p, int left_, int right_ ) 907 { 908 m_obj_p = ( CCAST<sc_signed*>( obj_p )); 909 m_left = left_; 910 m_right = right_; 911 } 912 913 914public: 915 916 // destructor 917 918 virtual ~sc_signed_subref_r() 919 {} 920 921 // copy constructor 922 923 sc_signed_subref_r( const sc_signed_subref_r& a ) 924 : sc_value_base(a), m_left( a.m_left ), m_obj_p( a.m_obj_p ), 925 m_right( a.m_right ) 926 {} 927 928 929 // capacity 930 931 int length() const 932 { return m_left >= m_right ? (m_left-m_right+1) : (m_right-m_left+1 ); } 933 934 935 // implicit conversion to sc_unsigned 936 937 operator sc_unsigned () const; 938 939 940 // explicit conversions 941 942 int to_int() const; 943 unsigned int to_uint() const; 944 long to_long() const; 945 unsigned long to_ulong() const; 946 int64 to_int64() const; 947 uint64 to_uint64() const; 948 double to_double() const; 949 950 951 // explicit conversion to character string 952 953 const std::string to_string( sc_numrep numrep = SC_DEC ) const; 954 const std::string to_string( sc_numrep numrep, bool w_prefix ) const; 955 956 // concatenation support 957 958 virtual int concat_length(bool* xz_present_p) const 959 { 960 if ( xz_present_p ) *xz_present_p = false; 961 return m_left - m_right + 1; 962 } 963 virtual uint64 concat_get_uint64() const; 964 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const; 965 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const; 966 967 // reduce methods 968 969 bool and_reduce() const; 970 bool nand_reduce() const; 971 bool or_reduce() const; 972 bool nor_reduce() const; 973 bool xor_reduce() const ; 974 bool xnor_reduce() const; 975 976 977 // other methods 978 979 void print( ::std::ostream& os = ::std::cout ) const 980 { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); } 981 982protected: 983 984 int m_left; // Left-most bit in this part selection. 985 sc_signed* m_obj_p; // Target of this part selection. 986 int m_right; // Right-most bit in this part selection. 987 988private: 989 const sc_signed_subref_r& operator = ( const sc_signed_subref_r& ); 990 991}; 992 993 994 995inline 996::std::ostream& 997operator << ( ::std::ostream&, const sc_signed_subref_r& ); 998 999 1000// ---------------------------------------------------------------------------- 1001// CLASS : sc_signed_subref 1002// 1003// Proxy class for sc_signed part selection (r-value and l-value). 1004// ---------------------------------------------------------------------------- 1005 1006class sc_signed_subref 1007 : public sc_signed_subref_r 1008{ 1009 friend class sc_signed; 1010 friend class sc_core::sc_vpool<sc_signed_subref>; 1011 1012 1013 // constructor 1014 1015 sc_signed_subref() : sc_signed_subref_r() 1016 {} 1017 1018public: 1019 1020 // copy constructor 1021 1022 sc_signed_subref( const sc_signed_subref& a ) 1023 : sc_signed_subref_r( a ) 1024 {} 1025 1026 1027 // assignment operators 1028 1029 const sc_signed_subref& operator = ( const sc_signed_subref_r& a ); 1030 const sc_signed_subref& operator = ( const sc_signed_subref& a ); 1031 const sc_signed_subref& operator = ( const sc_signed& a ); 1032 1033 const sc_signed_subref& operator = ( const sc_unsigned_subref_r& a ); 1034 const sc_signed_subref& operator = ( const sc_unsigned& a ); 1035 1036 template< class T > 1037 const sc_signed_subref& operator = ( const sc_generic_base<T>& a ) 1038 { 1039 sc_unsigned temp( length() ); 1040 a->to_sc_unsigned(temp); 1041 return operator = (temp); 1042 } 1043 1044 const sc_signed_subref& operator = ( const char* a ); 1045 const sc_signed_subref& operator = ( unsigned long a ); 1046 const sc_signed_subref& operator = ( long a ); 1047 const sc_signed_subref& operator = ( unsigned int a ) 1048 { return operator = ( (unsigned long) a ); } 1049 1050 const sc_signed_subref& operator = ( int a ) 1051 { return operator = ( (long) a ); } 1052 1053 const sc_signed_subref& operator = ( uint64 a ); 1054 const sc_signed_subref& operator = ( int64 a ); 1055 const sc_signed_subref& operator = ( double a ); 1056 const sc_signed_subref& operator = ( const sc_int_base& a ); 1057 const sc_signed_subref& operator = ( const sc_uint_base& a ); 1058 1059 // concatenation methods 1060 1061 virtual void concat_set(int64 src, int low_i); 1062 virtual void concat_set(const sc_signed& src, int low_i); 1063 virtual void concat_set(const sc_unsigned& src, int low_i); 1064 virtual void concat_set(uint64 src, int low_i); 1065 1066 // other methods 1067 1068 void scan( ::std::istream& is = ::std::cin ); 1069 1070protected: 1071 static sc_core::sc_vpool<sc_signed_subref> m_pool; 1072}; 1073 1074 1075 1076inline 1077::std::istream& 1078operator >> ( ::std::istream&, sc_signed_subref& ); 1079 1080 1081// ---------------------------------------------------------------------------- 1082// CLASS : sc_signed 1083// 1084// Arbitrary precision signed number. 1085// ---------------------------------------------------------------------------- 1086 1087class sc_signed : public sc_value_base 1088{ 1089 friend class sc_concatref; 1090 friend class sc_signed_bitref_r; 1091 friend class sc_signed_bitref; 1092 friend class sc_signed_subref_r; 1093 friend class sc_signed_subref; 1094 friend class sc_unsigned; 1095 friend class sc_unsigned_subref; 1096 1097 // Needed for types using sc_signed. 1098 typedef bool elemtype; 1099 1100public: 1101 1102 // constructors 1103 1104 explicit sc_signed( int nb = sc_length_param().len() ); 1105 sc_signed( const sc_signed& v ); 1106 sc_signed( const sc_unsigned& v ); 1107 template<class T> 1108 explicit sc_signed( const sc_generic_base<T>& v ); 1109 explicit sc_signed( const sc_bv_base& v ); 1110 explicit sc_signed( const sc_lv_base& v ); 1111 explicit sc_signed( const sc_int_subref_r& v ); 1112 explicit sc_signed( const sc_uint_subref_r& v ); 1113 explicit sc_signed( const sc_signed_subref_r& v ); 1114 explicit sc_signed( const sc_unsigned_subref_r& v ); 1115 1116 // assignment operators 1117 1118 const sc_signed& operator = (const sc_signed& v); 1119 const sc_signed& operator = (const sc_signed_subref_r& a ); 1120 1121 template< class T > 1122 const sc_signed& operator = ( const sc_generic_base<T>& a ) 1123 { a->to_sc_signed(*this); return *this; } 1124 1125 const sc_signed& operator = (const sc_unsigned& v); 1126 const sc_signed& operator = (const sc_unsigned_subref_r& a ); 1127 1128 const sc_signed& operator = (const char* v); 1129 const sc_signed& operator = (int64 v); 1130 const sc_signed& operator = (uint64 v); 1131 const sc_signed& operator = (long v); 1132 const sc_signed& operator = (unsigned long v); 1133 1134 const sc_signed& operator = (int v) 1135 { return operator=((long) v); } 1136 1137 const sc_signed& operator = (unsigned int v) 1138 { return operator=((unsigned long) v); } 1139 1140 const sc_signed& operator = (double v); 1141 const sc_signed& operator = (const sc_int_base& v); 1142 const sc_signed& operator = (const sc_uint_base& v); 1143 1144 const sc_signed& operator = ( const sc_bv_base& ); 1145 const sc_signed& operator = ( const sc_lv_base& ); 1146 1147#ifdef SC_INCLUDE_FX 1148 const sc_signed& operator = ( const sc_fxval& ); 1149 const sc_signed& operator = ( const sc_fxval_fast& ); 1150 const sc_signed& operator = ( const sc_fxnum& ); 1151 const sc_signed& operator = ( const sc_fxnum_fast& ); 1152#endif 1153 1154 1155 // destructor 1156 1157 virtual ~sc_signed() 1158 { 1159#ifndef SC_MAX_NBITS 1160 delete [] digit; 1161#endif 1162 } 1163 1164 // Concatenation support: 1165 1166 sc_digit* get_raw() const 1167 { return digit; } 1168 virtual int concat_length(bool* xz_present_p) const 1169 { if ( xz_present_p ) *xz_present_p = false; return nbits; } 1170 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const; 1171 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const; 1172 virtual uint64 concat_get_uint64() const; 1173 virtual void concat_set(int64 src, int low_i); 1174 virtual void concat_set(const sc_signed& src, int low_i); 1175 virtual void concat_set(const sc_unsigned& src, int low_i); 1176 virtual void concat_set(uint64 src, int low_i); 1177 1178 1179 1180 // Increment operators. 1181 sc_signed& operator ++ (); 1182 const sc_signed operator ++ (int); 1183 1184 // Decrement operators. 1185 sc_signed& operator -- (); 1186 const sc_signed operator -- (int); 1187 1188 1189 // bit selection 1190 1191 inline void check_index( int i ) const 1192 { if ( i < 0 || i >= nbits ) invalid_index(i); } 1193 1194 void invalid_index( int i ) const; 1195 1196 sc_signed_bitref& operator [] ( int i ) 1197 { 1198 check_index(i); 1199 sc_signed_bitref* result_p = 1200 sc_signed_bitref::m_pool.allocate(); 1201 result_p->initialize( this, i ); 1202 return *result_p; 1203 } 1204 1205 const sc_signed_bitref_r& operator [] ( int i ) const 1206 { 1207 check_index(i); 1208 sc_signed_bitref* result_p = 1209 sc_signed_bitref::m_pool.allocate(); 1210 result_p->initialize( this, i ); 1211 return *result_p; 1212 } 1213 1214 sc_signed_bitref& bit( int i ) 1215 { 1216 check_index(i); 1217 sc_signed_bitref* result_p = 1218 sc_signed_bitref::m_pool.allocate(); 1219 result_p->initialize( this, i ); 1220 return *result_p; 1221 } 1222 1223 const sc_signed_bitref_r& bit( int i ) const 1224 { 1225 check_index(i); 1226 sc_signed_bitref* result_p = 1227 sc_signed_bitref::m_pool.allocate(); 1228 result_p->initialize( this, i ); 1229 return *result_p; 1230 } 1231 1232 1233 // part selection 1234 1235 // Subref operators. Help access the range of bits from the ith to 1236 // jth. These indices have arbitrary precedence with respect to each 1237 // other, i.e., we can have i <= j or i > j. Note the equivalence 1238 // between range(i, j) and operator(i, j). Also note that 1239 // operator(i, i) returns a signed number that corresponds to the 1240 // bit operator[i], so these two forms are not the same. 1241 1242 inline void check_range( int l, int r ) const 1243 { 1244 if ( l < r ) 1245 { 1246 if ( l < 0 || r >= nbits ) invalid_range(l,r); 1247 } 1248 else 1249 { 1250 if ( r < 0 || l >= nbits ) invalid_range(l,r); 1251 } 1252 } 1253 1254 void invalid_range( int l, int r ) const; 1255 1256 sc_signed_subref& range( int i, int j ) 1257 { 1258 check_range( i, j ); 1259 sc_signed_subref* result_p = 1260 sc_signed_subref::m_pool.allocate(); 1261 result_p->initialize( this, i, j ); 1262 return *result_p; 1263 } 1264 1265 const sc_signed_subref_r& range( int i, int j ) const 1266 { 1267 check_range( i, j ); 1268 sc_signed_subref* result_p = 1269 sc_signed_subref::m_pool.allocate(); 1270 result_p->initialize( this, i, j ); 1271 return *result_p; 1272 } 1273 1274 sc_signed_subref& operator () ( int i, int j ) 1275 { 1276 check_range( i, j ); 1277 sc_signed_subref* result_p = 1278 sc_signed_subref::m_pool.allocate(); 1279 result_p->initialize( this, i, j ); 1280 return *result_p; 1281 } 1282 1283 const sc_signed_subref_r& operator () ( int i, int j ) const 1284 { 1285 check_range( i, j ); 1286 sc_signed_subref* result_p = 1287 sc_signed_subref::m_pool.allocate(); 1288 result_p->initialize( this, i, j ); 1289 return *result_p; 1290 } 1291 1292 1293 // explicit conversions 1294 1295 int to_int() const; 1296 unsigned int to_uint() const; 1297 long to_long() const; 1298 unsigned long to_ulong() const; 1299 int64 to_int64() const; 1300 uint64 to_uint64() const; 1301 double to_double() const; 1302 1303#ifdef SC_DT_DEPRECATED 1304 int to_signed() const 1305 { return to_int(); } 1306 1307 unsigned int to_unsigned() const 1308 { return to_uint(); } 1309#endif 1310 1311 // explicit conversion to character string 1312 1313 const std::string to_string( sc_numrep numrep = SC_DEC ) const; 1314 const std::string to_string( sc_numrep numrep, bool w_prefix ) const; 1315 1316 1317 // Print functions. dump prints the internals of the class. 1318 1319 void print( ::std::ostream& os = ::std::cout ) const 1320 { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); } 1321 1322 void scan( ::std::istream& is = ::std::cin ); 1323 1324 void dump( ::std::ostream& os = ::std::cout ) const; 1325 1326 1327 // Functions to find various properties. 1328 int length() const { return nbits; } // Bit width. 1329 bool iszero() const; // Is the number zero? 1330 bool sign() const; // Sign. 1331 1332 // reduce methods 1333 1334 bool and_reduce() const; 1335 1336 bool nand_reduce() const 1337 { return ( ! and_reduce() ); } 1338 1339 bool or_reduce() const; 1340 1341 bool nor_reduce() const 1342 { return ( ! or_reduce() ); } 1343 1344 bool xor_reduce() const; 1345 1346 bool xnor_reduce() const 1347 { return ( ! xor_reduce() ); } 1348 1349 // Functions to access individual bits. 1350 bool test(int i) const; // Is the ith bit 0 or 1? 1351 void set(int i); // Set the ith bit to 1. 1352 void clear(int i); // Set the ith bit to 0. 1353 void set(int i, bool v) // Set the ith bit to v. 1354 { if (v) set(i); else clear(i); } 1355 void invert(int i) // Negate the ith bit. 1356 { if (test(i)) clear(i); else set(i); } 1357 1358 // Make the number equal to its mirror image. 1359 void reverse(); 1360 1361 // Get/set a packed bit representation of the number. 1362 void get_packed_rep(sc_digit *buf) const; 1363 void set_packed_rep(sc_digit *buf); 1364 1365 /* 1366 The comparison of the old and new semantics are as follows: 1367 1368 Let s = sc_signed, 1369 u = sc_unsigned, 1370 un = { uint64, unsigned long, unsigned int }, 1371 sn = { int64, long, int, char* }, and 1372 OP = { +, -, *, /, % }. 1373 1374 Old semantics: New semantics: 1375 u OP u -> u u OP u -> u 1376 s OP u -> u s OP u -> s 1377 u OP s -> u u OP s -> s 1378 s OP s -> s s OP s -> s 1379 1380 u OP un = un OP u -> u u OP un = un OP u -> u 1381 u OP sn = sn OP u -> u u OP sn = sn OP u -> s 1382 1383 s OP un = un OP s -> s s OP un = un OP s -> s 1384 s OP sn = sn OP s -> s s OP sn = sn OP s -> s 1385 1386 In the new semantics, the result is u if both operands are u; the 1387 result is s otherwise. The only exception is subtraction. The result 1388 of a subtraction is always s. 1389 1390 The old semantics is like C/C++ semantics on integer types; the 1391 new semantics is due to the VSIA C/C++ data types standard. 1392 */ 1393 1394 // ARITHMETIC OPERATORS: 1395 1396 // ADDition operators: 1397 1398 friend sc_signed operator + (const sc_unsigned& u, const sc_signed& v); 1399 friend sc_signed operator + (const sc_signed& u, const sc_unsigned& v); 1400 1401 friend sc_signed operator + (const sc_unsigned& u, int64 v); 1402 friend sc_signed operator + (const sc_unsigned& u, long v); 1403 friend sc_signed operator + (const sc_unsigned& u, int v) 1404 { return operator+(u, (long) v); } 1405 1406 friend sc_signed operator + (int64 u, const sc_unsigned& v); 1407 friend sc_signed operator + (long u, const sc_unsigned& v); 1408 friend sc_signed operator + (int u, const sc_unsigned& v) 1409 { return operator+((long) u, v); } 1410 1411 friend sc_signed operator + (const sc_signed& u, const sc_signed& v); 1412 friend sc_signed operator + (const sc_signed& u, int64 v); 1413 friend sc_signed operator + (const sc_signed& u, uint64 v); 1414 friend sc_signed operator + (const sc_signed& u, long v); 1415 friend sc_signed operator + (const sc_signed& u, unsigned long v); 1416 friend sc_signed operator + (const sc_signed& u, int v) 1417 { return operator+(u, (long) v); } 1418 friend sc_signed operator + (const sc_signed& u, unsigned int v) 1419 { return operator+(u, (unsigned long) v); } 1420 1421 friend sc_signed operator + (int64 u, const sc_signed& v); 1422 friend sc_signed operator + (uint64 u, const sc_signed& v); 1423 friend sc_signed operator + (long u, const sc_signed& v); 1424 friend sc_signed operator + (unsigned long u, const sc_signed& v); 1425 friend sc_signed operator + (int u, const sc_signed& v) 1426 { return operator+((long) u, v); } 1427 friend sc_signed operator + (unsigned int u, const sc_signed& v) 1428 { return operator+((unsigned long) u, v); } 1429 1430 const sc_signed& operator += (const sc_signed& v); 1431 const sc_signed& operator += (const sc_unsigned& v); 1432 const sc_signed& operator += (int64 v); 1433 const sc_signed& operator += (uint64 v); 1434 const sc_signed& operator += (long v); 1435 const sc_signed& operator += (unsigned long v); 1436 const sc_signed& operator += (int v) 1437 { return operator+=((long) v); } 1438 const sc_signed& operator += (unsigned int v) 1439 { return operator+=((unsigned long) v); } 1440 1441 friend sc_signed operator + (const sc_unsigned& u, const sc_int_base& v); 1442 friend sc_signed operator + (const sc_int_base& u, const sc_unsigned& v); 1443 friend sc_signed operator + (const sc_signed& u, const sc_int_base& v); 1444 friend sc_signed operator + (const sc_signed& u, const sc_uint_base& v); 1445 friend sc_signed operator + (const sc_int_base& u, const sc_signed& v); 1446 friend sc_signed operator + (const sc_uint_base& u, const sc_signed& v); 1447 const sc_signed& operator += (const sc_int_base& v); 1448 const sc_signed& operator += (const sc_uint_base& v); 1449 1450 // SUBtraction operators: 1451 1452 friend sc_signed operator - (const sc_unsigned& u, const sc_signed& v); 1453 friend sc_signed operator - (const sc_signed& u, const sc_unsigned& v); 1454 1455 friend sc_signed operator - (const sc_unsigned& u, const sc_unsigned& v); 1456 friend sc_signed operator - (const sc_unsigned& u, int64 v); 1457 friend sc_signed operator - (const sc_unsigned& u, uint64 v); 1458 friend sc_signed operator - (const sc_unsigned& u, long v); 1459 friend sc_signed operator - (const sc_unsigned& u, unsigned long v); 1460 friend sc_signed operator - (const sc_unsigned& u, int v) 1461 { return operator-(u, (long) v); } 1462 friend sc_signed operator - (const sc_unsigned& u, unsigned int v) 1463 { return operator-(u, (unsigned long) v); } 1464 1465 friend sc_signed operator - (int64 u, const sc_unsigned& v); 1466 friend sc_signed operator - (uint64 u, const sc_unsigned& v); 1467 friend sc_signed operator - (long u, const sc_unsigned& v); 1468 friend sc_signed operator - (unsigned long u, const sc_unsigned& v); 1469 friend sc_signed operator - (int u, const sc_unsigned& v) 1470 { return operator-((long) u, v); } 1471 friend sc_signed operator - (unsigned int u, const sc_unsigned& v) 1472 { return operator-((unsigned long) u, v); } 1473 1474 friend sc_signed operator - (const sc_signed& u, const sc_signed& v); 1475 friend sc_signed operator - (const sc_signed& u, int64 v); 1476 friend sc_signed operator - (const sc_signed& u, uint64 v); 1477 friend sc_signed operator - (const sc_signed& u, long v); 1478 friend sc_signed operator - (const sc_signed& u, unsigned long v); 1479 friend sc_signed operator - (const sc_signed& u, int v) 1480 { return operator-(u, (long) v); } 1481 friend sc_signed operator - (const sc_signed& u, unsigned int v) 1482 { return operator-(u, (unsigned long) v); } 1483 1484 friend sc_signed operator - (int64 u, const sc_signed& v); 1485 friend sc_signed operator - (uint64 u, const sc_signed& v); 1486 friend sc_signed operator - (long u, const sc_signed& v); 1487 friend sc_signed operator - (unsigned long u, const sc_signed& v); 1488 friend sc_signed operator - (int u, const sc_signed& v) 1489 { return operator-((long) u, v); } 1490 friend sc_signed operator - (unsigned int u, const sc_signed& v) 1491 { return operator-((unsigned long) u, v); } 1492 1493 const sc_signed& operator -= (const sc_signed& v); 1494 const sc_signed& operator -= (const sc_unsigned& v); 1495 const sc_signed& operator -= (int64 v); 1496 const sc_signed& operator -= (uint64 v); 1497 const sc_signed& operator -= (long v); 1498 const sc_signed& operator -= (unsigned long v); 1499 const sc_signed& operator -= (int v) 1500 { return operator -= ((long) v); } 1501 const sc_signed& operator -= (unsigned int v) 1502 { return operator -= ((unsigned long) v); } 1503 1504 friend sc_signed operator - (const sc_unsigned& u, const sc_int_base& v); 1505 friend sc_signed operator - (const sc_unsigned& u, const sc_uint_base& v); 1506 friend sc_signed operator - (const sc_int_base& u, const sc_unsigned& v); 1507 friend sc_signed operator - (const sc_uint_base& u, const sc_unsigned& v); 1508 friend sc_signed operator - (const sc_signed& u, const sc_int_base& v); 1509 friend sc_signed operator - (const sc_signed& u, const sc_uint_base& v); 1510 friend sc_signed operator - (const sc_int_base& u, const sc_signed& v); 1511 friend sc_signed operator - (const sc_uint_base& u, const sc_signed& v); 1512 const sc_signed& operator -= (const sc_int_base& v); 1513 const sc_signed& operator -= (const sc_uint_base& v); 1514 1515 // MULtiplication operators: 1516 1517 friend sc_signed operator * (const sc_unsigned& u, const sc_signed& v); 1518 friend sc_signed operator * (const sc_signed& u, const sc_unsigned& v); 1519 1520 friend sc_signed operator * (const sc_unsigned& u, int64 v); 1521 friend sc_signed operator * (const sc_unsigned& u, long v); 1522 friend sc_signed operator * (const sc_unsigned& u, int v) 1523 { return operator*(u, (long) v); } 1524 1525 friend sc_signed operator * (int64 u, const sc_unsigned& v); 1526 friend sc_signed operator * (long u, const sc_unsigned& v); 1527 friend sc_signed operator * (int u, const sc_unsigned& v) 1528 { return operator*((long) u, v); } 1529 1530 friend sc_signed operator * (const sc_signed& u, const sc_signed& v); 1531 friend sc_signed operator * (const sc_signed& u, int64 v); 1532 friend sc_signed operator * (const sc_signed& u, uint64 v); 1533 friend sc_signed operator * (const sc_signed& u, long v); 1534 friend sc_signed operator * (const sc_signed& u, unsigned long v); 1535 friend sc_signed operator * (const sc_signed& u, int v) 1536 { return operator*(u, (long) v); } 1537 friend sc_signed operator * (const sc_signed& u, unsigned int v) 1538 { return operator*(u, (unsigned long) v); } 1539 1540 friend sc_signed operator * (int64 u, const sc_signed& v); 1541 friend sc_signed operator * (uint64 u, const sc_signed& v); 1542 friend sc_signed operator * (long u, const sc_signed& v); 1543 friend sc_signed operator * (unsigned long u, const sc_signed& v); 1544 friend sc_signed operator * (int u, const sc_signed& v) 1545 { return operator*((long) u, v); } 1546 friend sc_signed operator * (unsigned int u, const sc_signed& v) 1547 { return operator*((unsigned long) u, v); } 1548 1549 const sc_signed& operator *= (const sc_signed& v); 1550 const sc_signed& operator *= (const sc_unsigned& v); 1551 const sc_signed& operator *= (int64 v); 1552 const sc_signed& operator *= (uint64 v); 1553 const sc_signed& operator *= (long v); 1554 const sc_signed& operator *= (unsigned long v); 1555 const sc_signed& operator *= (int v) 1556 { return operator*=((long) v); } 1557 const sc_signed& operator *= (unsigned int v) 1558 { return operator*=((unsigned long) v); } 1559 1560 friend sc_signed operator * (const sc_unsigned& u, const sc_int_base& v); 1561 friend sc_signed operator * (const sc_int_base& u, const sc_unsigned& v); 1562 friend sc_signed operator * (const sc_signed& u, const sc_int_base& v); 1563 friend sc_signed operator * (const sc_signed& u, const sc_uint_base& v); 1564 friend sc_signed operator * (const sc_int_base& u, const sc_signed& v); 1565 friend sc_signed operator * (const sc_uint_base& u, const sc_signed& v); 1566 const sc_signed& operator *= (const sc_int_base& v); 1567 const sc_signed& operator *= (const sc_uint_base& v); 1568 1569 // DIVision operators: 1570 1571 friend sc_signed operator / (const sc_unsigned& u, const sc_signed& v); 1572 friend sc_signed operator / (const sc_signed& u, const sc_unsigned& v); 1573 1574 friend sc_signed operator / (const sc_unsigned& u, int64 v); 1575 friend sc_signed operator / (const sc_unsigned& u, long v); 1576 friend sc_signed operator / (const sc_unsigned& u, int v) 1577 { return operator/(u, (long) v); } 1578 1579 friend sc_signed operator / (int64 u, const sc_unsigned& v); 1580 friend sc_signed operator / (long u, const sc_unsigned& v); 1581 friend sc_signed operator / (int u, const sc_unsigned& v) 1582 { return operator/((long) u, v); } 1583 1584 friend sc_signed operator / (const sc_signed& u, const sc_signed& v); 1585 friend sc_signed operator / (const sc_signed& u, int64 v); 1586 friend sc_signed operator / (const sc_signed& u, uint64 v); 1587 friend sc_signed operator / (const sc_signed& u, long v); 1588 friend sc_signed operator / (const sc_signed& u, unsigned long v); 1589 friend sc_signed operator / (const sc_signed& u, int v) 1590 { return operator/(u, (long) v); } 1591 friend sc_signed operator / (const sc_signed& u, unsigned int v) 1592 { return operator/(u, (unsigned long) v); } 1593 1594 friend sc_signed operator / (int64 u, const sc_signed& v); 1595 friend sc_signed operator / (uint64 u, const sc_signed& v); 1596 friend sc_signed operator / (long u, const sc_signed& v); 1597 friend sc_signed operator / (unsigned long u, const sc_signed& v); 1598 friend sc_signed operator / (int u, const sc_signed& v) 1599 { return operator/((long) u, v); } 1600 friend sc_signed operator / (unsigned int u, const sc_signed& v) 1601 { return operator/((unsigned long) u, v); } 1602 1603 const sc_signed& operator /= (const sc_signed& v); 1604 const sc_signed& operator /= (const sc_unsigned& v); 1605 const sc_signed& operator /= (int64 v); 1606 const sc_signed& operator /= (uint64 v); 1607 const sc_signed& operator /= (long v); 1608 const sc_signed& operator /= (unsigned long v); 1609 const sc_signed& operator /= (int v) 1610 { return operator/=((long) v); } 1611 const sc_signed& operator /= (unsigned int v) 1612 { return operator/=((unsigned long) v); } 1613 1614 friend sc_signed operator / (const sc_unsigned& u, const sc_int_base& v); 1615 friend sc_signed operator / (const sc_int_base& u, const sc_unsigned& v); 1616 friend sc_signed operator / (const sc_signed& u, const sc_int_base& v); 1617 friend sc_signed operator / (const sc_signed& u, const sc_uint_base& v); 1618 friend sc_signed operator / (const sc_int_base& u, const sc_signed& v); 1619 friend sc_signed operator / (const sc_uint_base& u, const sc_signed& v); 1620 const sc_signed& operator /= (const sc_int_base& v); 1621 const sc_signed& operator /= (const sc_uint_base& v); 1622 1623 // MODulo operators: 1624 1625 friend sc_signed operator % (const sc_unsigned& u, const sc_signed& v); 1626 friend sc_signed operator % (const sc_signed& u, const sc_unsigned& v); 1627 1628 friend sc_signed operator % (const sc_unsigned& u, int64 v); 1629 friend sc_signed operator % (const sc_unsigned& u, long v); 1630 friend sc_signed operator % (const sc_unsigned& u, int v) 1631 { return operator%(u, (long) v); } 1632 1633 friend sc_signed operator % (int64 u, const sc_unsigned& v); 1634 friend sc_signed operator % (long u, const sc_unsigned& v); 1635 friend sc_signed operator % (int u, const sc_unsigned& v) 1636 { return operator%((long) u, v); } 1637 1638 friend sc_signed operator % (const sc_signed& u, const sc_signed& v); 1639 friend sc_signed operator % (const sc_signed& u, int64 v); 1640 friend sc_signed operator % (const sc_signed& u, uint64 v); 1641 friend sc_signed operator % (const sc_signed& u, long v); 1642 friend sc_signed operator % (const sc_signed& u, unsigned long v); 1643 friend sc_signed operator % (const sc_signed& u, int v) 1644 { return operator%(u, (long) v); } 1645 friend sc_signed operator % (const sc_signed& u, unsigned int v) 1646 { return operator%(u, (unsigned long) v); } 1647 1648 friend sc_signed operator % (int64 u, const sc_signed& v); 1649 friend sc_signed operator % (uint64 u, const sc_signed& v); 1650 friend sc_signed operator % (long u, const sc_signed& v); 1651 friend sc_signed operator % (unsigned long u, const sc_signed& v); 1652 friend sc_signed operator % (int u, const sc_signed& v) 1653 { return operator%((long) u, v); } 1654 friend sc_signed operator % (unsigned int u, const sc_signed& v) 1655 { return operator%((unsigned long) u, v); } 1656 1657 const sc_signed& operator %= (const sc_signed& v); 1658 const sc_signed& operator %= (const sc_unsigned& v); 1659 const sc_signed& operator %= (int64 v); 1660 const sc_signed& operator %= (uint64 v); 1661 const sc_signed& operator %= (long v); 1662 const sc_signed& operator %= (unsigned long v); 1663 const sc_signed& operator %= (int v) 1664 { return operator%=((long) v); } 1665 const sc_signed& operator %= (unsigned int v) 1666 { return operator%=((unsigned long) v); } 1667 1668 friend sc_signed operator % (const sc_unsigned& u, const sc_int_base& v); 1669 friend sc_signed operator % (const sc_int_base& u, const sc_unsigned& v); 1670 friend sc_signed operator % (const sc_signed& u, const sc_int_base& v); 1671 friend sc_signed operator % (const sc_signed& u, const sc_uint_base& v); 1672 friend sc_signed operator % (const sc_int_base& u, const sc_signed& v); 1673 friend sc_signed operator % (const sc_uint_base& u, const sc_signed& v); 1674 const sc_signed& operator %= (const sc_int_base& v); 1675 const sc_signed& operator %= (const sc_uint_base& v); 1676 1677 // BITWISE OPERATORS: 1678 1679 // Bitwise AND operators: 1680 1681 friend sc_signed operator & (const sc_unsigned& u, const sc_signed& v); 1682 friend sc_signed operator & (const sc_signed& u, const sc_unsigned& v); 1683 1684 friend sc_signed operator & (const sc_unsigned& u, int64 v); 1685 friend sc_signed operator & (const sc_unsigned& u, long v); 1686 friend sc_signed operator & (const sc_unsigned& u, int v) 1687 { return operator&(u, (long) v); } 1688 1689 friend sc_signed operator & (int64 u, const sc_unsigned& v); 1690 friend sc_signed operator & (long u, const sc_unsigned& v); 1691 friend sc_signed operator & (int u, const sc_unsigned& v) 1692 { return operator&((long) u, v); } 1693 1694 friend sc_signed operator & (const sc_signed& u, const sc_signed& v); 1695 friend sc_signed operator & (const sc_signed& u, int64 v); 1696 friend sc_signed operator & (const sc_signed& u, uint64 v); 1697 friend sc_signed operator & (const sc_signed& u, long v); 1698 friend sc_signed operator & (const sc_signed& u, unsigned long v); 1699 friend sc_signed operator & (const sc_signed& u, int v) 1700 { return operator&(u, (long) v); } 1701 friend sc_signed operator & (const sc_signed& u, unsigned int v) 1702 { return operator&(u, (unsigned long) v); } 1703 1704 friend sc_signed operator & (int64 u, const sc_signed& v); 1705 friend sc_signed operator & (uint64 u, const sc_signed& v); 1706 friend sc_signed operator & (long u, const sc_signed& v); 1707 friend sc_signed operator & (unsigned long u, const sc_signed& v); 1708 friend sc_signed operator & (int u, const sc_signed& v) 1709 { return operator&((long) u, v); } 1710 friend sc_signed operator & (unsigned int u, const sc_signed& v) 1711 { return operator&((unsigned long) u, v); } 1712 1713 const sc_signed& operator &= (const sc_signed& v); 1714 const sc_signed& operator &= (const sc_unsigned& v); 1715 const sc_signed& operator &= (int64 v); 1716 const sc_signed& operator &= (uint64 v); 1717 const sc_signed& operator &= (long v); 1718 const sc_signed& operator &= (unsigned long v); 1719 const sc_signed& operator &= (int v) 1720 { return operator&=((long) v); } 1721 const sc_signed& operator &= (unsigned int v) 1722 { return operator&=((unsigned long) v); } 1723 1724 friend sc_signed operator & (const sc_unsigned& u, const sc_int_base& v); 1725 friend sc_signed operator & (const sc_int_base& u, const sc_unsigned& v); 1726 friend sc_signed operator & (const sc_signed& u, const sc_int_base& v); 1727 friend sc_signed operator & (const sc_signed& u, const sc_uint_base& v); 1728 friend sc_signed operator & (const sc_int_base& u, const sc_signed& v); 1729 friend sc_signed operator & (const sc_uint_base& u, const sc_signed& v); 1730 const sc_signed& operator &= (const sc_int_base& v); 1731 const sc_signed& operator &= (const sc_uint_base& v); 1732 1733 // Bitwise OR operators: 1734 1735 friend sc_signed operator | (const sc_unsigned& u, const sc_signed& v); 1736 friend sc_signed operator | (const sc_signed& u, const sc_unsigned& v); 1737 1738 friend sc_signed operator | (const sc_unsigned& u, int64 v); 1739 friend sc_signed operator | (const sc_unsigned& u, long v); 1740 friend sc_signed operator | (const sc_unsigned& u, int v) 1741 { return operator|(u, (long) v); } 1742 1743 friend sc_signed operator | (int64 u, const sc_unsigned& v); 1744 friend sc_signed operator | (long u, const sc_unsigned& v); 1745 friend sc_signed operator | (int u, const sc_unsigned& v) 1746 { return operator|((long) u, v); } 1747 1748 friend sc_signed operator | (const sc_signed& u, const sc_signed& v); 1749 friend sc_signed operator | (const sc_signed& u, int64 v); 1750 friend sc_signed operator | (const sc_signed& u, uint64 v); 1751 friend sc_signed operator | (const sc_signed& u, long v); 1752 friend sc_signed operator | (const sc_signed& u, unsigned long v); 1753 friend sc_signed operator | (const sc_signed& u, int v) 1754 { return operator|(u, (long) v); } 1755 friend sc_signed operator | (const sc_signed& u, unsigned int v) 1756 { return operator|(u, (unsigned long) v); } 1757 1758 friend sc_signed operator | (int64 u, const sc_signed& v); 1759 friend sc_signed operator | (uint64 u, const sc_signed& v); 1760 friend sc_signed operator | (long u, const sc_signed& v); 1761 friend sc_signed operator | (unsigned long u, const sc_signed& v); 1762 friend sc_signed operator | (int u, const sc_signed& v) 1763 { return operator|((long) u, v); } 1764 friend sc_signed operator | (unsigned int u, const sc_signed& v) 1765 { return operator|((unsigned long) u, v); } 1766 1767 const sc_signed& operator |= (const sc_signed& v); 1768 const sc_signed& operator |= (const sc_unsigned& v); 1769 const sc_signed& operator |= (int64 v); 1770 const sc_signed& operator |= (uint64 v); 1771 const sc_signed& operator |= (long v); 1772 const sc_signed& operator |= (unsigned long v); 1773 const sc_signed& operator |= (int v) 1774 { return operator|=((long) v); } 1775 const sc_signed& operator |= (unsigned int v) 1776 { return operator|=((unsigned long) v); } 1777 1778 friend sc_signed operator | (const sc_unsigned& u, const sc_int_base& v); 1779 friend sc_signed operator | (const sc_int_base& u, const sc_unsigned& v); 1780 friend sc_signed operator | (const sc_signed& u, const sc_int_base& v); 1781 friend sc_signed operator | (const sc_signed& u, const sc_uint_base& v); 1782 friend sc_signed operator | (const sc_int_base& u, const sc_signed& v); 1783 friend sc_signed operator | (const sc_uint_base& u, const sc_signed& v); 1784 const sc_signed& operator |= (const sc_int_base& v); 1785 const sc_signed& operator |= (const sc_uint_base& v); 1786 1787 // Bitwise XOR operators: 1788 1789 friend sc_signed operator ^ (const sc_unsigned& u, const sc_signed& v); 1790 friend sc_signed operator ^ (const sc_signed& u, const sc_unsigned& v); 1791 1792 friend sc_signed operator ^ (const sc_unsigned& u, int64 v); 1793 friend sc_signed operator ^ (const sc_unsigned& u, long v); 1794 friend sc_signed operator ^ (const sc_unsigned& u, int v) 1795 { return operator^(u, (long) v); } 1796 1797 friend sc_signed operator ^ (int64 u, const sc_unsigned& v); 1798 friend sc_signed operator ^ (long u, const sc_unsigned& v); 1799 friend sc_signed operator ^ (int u, const sc_unsigned& v) 1800 { return operator^((long) u, v); } 1801 1802 friend sc_signed operator ^ (const sc_signed& u, const sc_signed& v); 1803 friend sc_signed operator ^ (const sc_signed& u, int64 v); 1804 friend sc_signed operator ^ (const sc_signed& u, uint64 v); 1805 friend sc_signed operator ^ (const sc_signed& u, long v); 1806 friend sc_signed operator ^ (const sc_signed& u, unsigned long v); 1807 friend sc_signed operator ^ (const sc_signed& u, int v) 1808 { return operator^(u, (long) v); } 1809 friend sc_signed operator ^ (const sc_signed& u, unsigned int v) 1810 { return operator^(u, (unsigned long) v); } 1811 1812 friend sc_signed operator ^ (int64 u, const sc_signed& v); 1813 friend sc_signed operator ^ (uint64 u, const sc_signed& v); 1814 friend sc_signed operator ^ (long u, const sc_signed& v); 1815 friend sc_signed operator ^ (unsigned long u, const sc_signed& v); 1816 friend sc_signed operator ^ (int u, const sc_signed& v) 1817 { return operator^((long) u, v); } 1818 friend sc_signed operator ^ (unsigned int u, const sc_signed& v) 1819 { return operator^((unsigned long) u, v); } 1820 1821 const sc_signed& operator ^= (const sc_signed& v); 1822 const sc_signed& operator ^= (const sc_unsigned& v); 1823 const sc_signed& operator ^= (int64 v); 1824 const sc_signed& operator ^= (uint64 v); 1825 const sc_signed& operator ^= (long v); 1826 const sc_signed& operator ^= (unsigned long v); 1827 const sc_signed& operator ^= (int v) 1828 { return operator^=((long) v); } 1829 const sc_signed& operator ^= (unsigned int v) 1830 { return operator^=((unsigned long) v); } 1831 1832 friend sc_signed operator ^ (const sc_unsigned& u, const sc_int_base& v); 1833 friend sc_signed operator ^ (const sc_int_base& u, const sc_unsigned& v); 1834 friend sc_signed operator ^ (const sc_signed& u, const sc_int_base& v); 1835 friend sc_signed operator ^ (const sc_signed& u, const sc_uint_base& v); 1836 friend sc_signed operator ^ (const sc_int_base& u, const sc_signed& v); 1837 friend sc_signed operator ^ (const sc_uint_base& u, const sc_signed& v); 1838 const sc_signed& operator ^= (const sc_int_base& v); 1839 const sc_signed& operator ^= (const sc_uint_base& v); 1840 1841 // SHIFT OPERATORS: 1842 1843 // LEFT SHIFT operators: 1844 1845 friend sc_unsigned operator << (const sc_unsigned& u, const sc_signed& v); 1846 friend sc_signed operator << (const sc_signed& u, const sc_unsigned& v); 1847 1848 friend sc_signed operator << (const sc_signed& u, const sc_signed& v); 1849 friend sc_signed operator << (const sc_signed& u, int64 v); 1850 friend sc_signed operator << (const sc_signed& u, uint64 v); 1851 friend sc_signed operator << (const sc_signed& u, long v); 1852 friend sc_signed operator << (const sc_signed& u, unsigned long v); 1853 friend sc_signed operator << (const sc_signed& u, int v) 1854 { return operator<<(u, (long) v); } 1855 friend sc_signed operator << (const sc_signed& u, unsigned int v) 1856 { return operator<<(u, (unsigned long) v); } 1857 1858 const sc_signed& operator <<= (const sc_signed& v); 1859 const sc_signed& operator <<= (const sc_unsigned& v); 1860 const sc_signed& operator <<= (int64 v); 1861 const sc_signed& operator <<= (uint64 v); 1862 const sc_signed& operator <<= (long v); 1863 const sc_signed& operator <<= (unsigned long v); 1864 const sc_signed& operator <<= (int v) 1865 { return operator<<=((long) v); } 1866 const sc_signed& operator <<= (unsigned int v) 1867 { return operator<<=((unsigned long) v); } 1868 1869 friend sc_signed operator << (const sc_signed& u, const sc_int_base& v); 1870 friend sc_signed operator << (const sc_signed& u, const sc_uint_base& v); 1871 const sc_signed& operator <<= (const sc_int_base& v); 1872 const sc_signed& operator <<= (const sc_uint_base& v); 1873 1874 // RIGHT SHIFT operators: 1875 1876 friend sc_unsigned operator >> (const sc_unsigned& u, const sc_signed& v); 1877 friend sc_signed operator >> (const sc_signed& u, const sc_unsigned& v); 1878 1879 friend sc_signed operator >> (const sc_signed& u, const sc_signed& v); 1880 friend sc_signed operator >> (const sc_signed& u, int64 v); 1881 friend sc_signed operator >> (const sc_signed& u, uint64 v); 1882 friend sc_signed operator >> (const sc_signed& u, long v); 1883 friend sc_signed operator >> (const sc_signed& u, unsigned long v); 1884 friend sc_signed operator >> (const sc_signed& u, int v) 1885 { return operator>>(u, (long) v); } 1886 friend sc_signed operator >> (const sc_signed& u, unsigned int v) 1887 { return operator>>(u, (unsigned long) v); } 1888 1889 const sc_signed& operator >>= (const sc_signed& v); 1890 const sc_signed& operator >>= (const sc_unsigned& v); 1891 const sc_signed& operator >>= (int64 v); 1892 const sc_signed& operator >>= (uint64 v); 1893 const sc_signed& operator >>= (long v); 1894 const sc_signed& operator >>= (unsigned long v); 1895 const sc_signed& operator >>= (int v) 1896 { return operator>>=((long) v); } 1897 const sc_signed& operator >>= (unsigned int v) 1898 { return operator>>=((unsigned long) v); } 1899 1900 friend sc_signed operator >> (const sc_signed& u, const sc_int_base& v); 1901 friend sc_signed operator >> (const sc_signed& u, const sc_uint_base& v); 1902 const sc_signed& operator >>= (const sc_int_base& v); 1903 const sc_signed& operator >>= (const sc_uint_base& v); 1904 1905 // Unary arithmetic operators 1906 friend sc_signed operator + (const sc_signed& u); 1907 friend sc_signed operator - (const sc_signed& u); 1908 friend sc_signed operator - (const sc_unsigned& u); 1909 1910 // LOGICAL OPERATORS: 1911 1912 // Logical EQUAL operators: 1913 1914 friend bool operator == (const sc_unsigned& u, const sc_signed& v); 1915 friend bool operator == (const sc_signed& u, const sc_unsigned& v); 1916 1917 friend bool operator == (const sc_signed& u, const sc_signed& v); 1918 friend bool operator == (const sc_signed& u, int64 v); 1919 friend bool operator == (const sc_signed& u, uint64 v); 1920 friend bool operator == (const sc_signed& u, long v); 1921 friend bool operator == (const sc_signed& u, unsigned long v); 1922 friend bool operator == (const sc_signed& u, int v) 1923 { return operator==(u, (long) v); } 1924 friend bool operator == (const sc_signed& u, unsigned int v) 1925 { return operator==(u, (unsigned long) v); } 1926 1927 friend bool operator == (int64 u, const sc_signed& v); 1928 friend bool operator == (uint64 u, const sc_signed& v); 1929 friend bool operator == (long u, const sc_signed& v); 1930 friend bool operator == (unsigned long u, const sc_signed& v); 1931 friend bool operator == (int u, const sc_signed& v) 1932 { return operator==((long) u, v); } 1933 friend bool operator == (unsigned int u, const sc_signed& v) 1934 { return operator==((unsigned long) u, v); } 1935 1936 friend bool operator == (const sc_signed& u, const sc_int_base& v); 1937 friend bool operator == (const sc_signed& u, const sc_uint_base& v); 1938 friend bool operator == (const sc_int_base& u, const sc_signed& v); 1939 friend bool operator == (const sc_uint_base& u, const sc_signed& v); 1940 1941 // Logical NOT_EQUAL operators: 1942 1943 friend bool operator != (const sc_unsigned& u, const sc_signed& v); 1944 friend bool operator != (const sc_signed& u, const sc_unsigned& v); 1945 1946 friend bool operator != (const sc_signed& u, const sc_signed& v); 1947 friend bool operator != (const sc_signed& u, int64 v); 1948 friend bool operator != (const sc_signed& u, uint64 v); 1949 friend bool operator != (const sc_signed& u, long v); 1950 friend bool operator != (const sc_signed& u, unsigned long v); 1951 friend bool operator != (const sc_signed& u, int v) 1952 { return operator!=(u, (long) v); } 1953 friend bool operator != (const sc_signed& u, unsigned int v) 1954 { return operator!=(u, (unsigned long) v); } 1955 1956 friend bool operator != (int64 u, const sc_signed& v); 1957 friend bool operator != (uint64 u, const sc_signed& v); 1958 friend bool operator != (long u, const sc_signed& v); 1959 friend bool operator != (unsigned long u, const sc_signed& v); 1960 friend bool operator != (int u, const sc_signed& v) 1961 { return operator!=((long) u, v); } 1962 friend bool operator != (unsigned int u, const sc_signed& v) 1963 { return operator!=((unsigned long) u, v); } 1964 1965 friend bool operator != (const sc_signed& u, const sc_int_base& v); 1966 friend bool operator != (const sc_signed& u, const sc_uint_base& v); 1967 friend bool operator != (const sc_int_base& u, const sc_signed& v); 1968 friend bool operator != (const sc_uint_base& u, const sc_signed& v); 1969 1970 // Logical LESS_THAN operators: 1971 1972 friend bool operator < (const sc_unsigned& u, const sc_signed& v); 1973 friend bool operator < (const sc_signed& u, const sc_unsigned& v); 1974 1975 friend bool operator < (const sc_signed& u, const sc_signed& v); 1976 friend bool operator < (const sc_signed& u, int64 v); 1977 friend bool operator < (const sc_signed& u, uint64 v); 1978 friend bool operator < (const sc_signed& u, long v); 1979 friend bool operator < (const sc_signed& u, unsigned long v); 1980 friend bool operator < (const sc_signed& u, int v) 1981 { return operator<(u, (long) v); } 1982 friend bool operator < (const sc_signed& u, unsigned int v) 1983 { return operator<(u, (unsigned long) v); } 1984 1985 friend bool operator < (int64 u, const sc_signed& v); 1986 friend bool operator < (uint64 u, const sc_signed& v); 1987 friend bool operator < (long u, const sc_signed& v); 1988 friend bool operator < (unsigned long u, const sc_signed& v); 1989 friend bool operator < (int u, const sc_signed& v) 1990 { return operator<((long) u, v); } 1991 friend bool operator < (unsigned int u, const sc_signed& v) 1992 { return operator<((unsigned long) u, v); } 1993 1994 friend bool operator < (const sc_signed& u, const sc_int_base& v); 1995 friend bool operator < (const sc_signed& u, const sc_uint_base& v); 1996 friend bool operator < (const sc_int_base& u, const sc_signed& v); 1997 friend bool operator < (const sc_uint_base& u, const sc_signed& v); 1998 1999 // Logical LESS_THAN_AND_EQUAL operators: 2000 2001 friend bool operator <= (const sc_unsigned& u, const sc_signed& v); 2002 friend bool operator <= (const sc_signed& u, const sc_unsigned& v); 2003 2004 friend bool operator <= (const sc_signed& u, const sc_signed& v); 2005 friend bool operator <= (const sc_signed& u, int64 v); 2006 friend bool operator <= (const sc_signed& u, uint64 v); 2007 friend bool operator <= (const sc_signed& u, long v); 2008 friend bool operator <= (const sc_signed& u, unsigned long v); 2009 friend bool operator <= (const sc_signed& u, int v) 2010 { return operator<=(u, (long) v); } 2011 friend bool operator <= (const sc_signed& u, unsigned int v) 2012 { return operator<=(u, (unsigned long) v); } 2013 2014 friend bool operator <= (int64 u, const sc_signed& v); 2015 friend bool operator <= (uint64 u, const sc_signed& v); 2016 friend bool operator <= (long u, const sc_signed& v); 2017 friend bool operator <= (unsigned long u, const sc_signed& v); 2018 friend bool operator <= (int u, const sc_signed& v) 2019 { return operator<=((long) u, v); } 2020 friend bool operator <= (unsigned int u, const sc_signed& v) 2021 { return operator<=((unsigned long) u, v); } 2022 2023 friend bool operator <= (const sc_signed& u, const sc_int_base& v); 2024 friend bool operator <= (const sc_signed& u, const sc_uint_base& v); 2025 friend bool operator <= (const sc_int_base& u, const sc_signed& v); 2026 friend bool operator <= (const sc_uint_base& u, const sc_signed& v); 2027 2028 // Logical GREATER_THAN operators: 2029 2030 friend bool operator > (const sc_unsigned& u, const sc_signed& v); 2031 friend bool operator > (const sc_signed& u, const sc_unsigned& v); 2032 2033 friend bool operator > (const sc_signed& u, const sc_signed& v); 2034 friend bool operator > (const sc_signed& u, int64 v); 2035 friend bool operator > (const sc_signed& u, uint64 v); 2036 friend bool operator > (const sc_signed& u, long v); 2037 friend bool operator > (const sc_signed& u, unsigned long v); 2038 friend bool operator > (const sc_signed& u, int v) 2039 { return operator>(u, (long) v); } 2040 friend bool operator > (const sc_signed& u, unsigned int v) 2041 { return operator>(u, (unsigned long) v); } 2042 2043 friend bool operator > (int64 u, const sc_signed& v); 2044 friend bool operator > (uint64 u, const sc_signed& v); 2045 friend bool operator > (long u, const sc_signed& v); 2046 friend bool operator > (unsigned long u, const sc_signed& v); 2047 friend bool operator > (int u, const sc_signed& v) 2048 { return operator>((long) u, v); } 2049 friend bool operator > (unsigned int u, const sc_signed& v) 2050 { return operator>((unsigned long) u, v); } 2051 2052 friend bool operator > (const sc_signed& u, const sc_int_base& v); 2053 friend bool operator > (const sc_signed& u, const sc_uint_base& v); 2054 friend bool operator > (const sc_int_base& u, const sc_signed& v); 2055 friend bool operator > (const sc_uint_base& u, const sc_signed& v); 2056 2057 // Logical GREATER_THAN_AND_EQUAL operators: 2058 2059 friend bool operator >= (const sc_unsigned& u, const sc_signed& v); 2060 friend bool operator >= (const sc_signed& u, const sc_unsigned& v); 2061 2062 friend bool operator >= (const sc_signed& u, const sc_signed& v); 2063 friend bool operator >= (const sc_signed& u, int64 v); 2064 friend bool operator >= (const sc_signed& u, uint64 v); 2065 friend bool operator >= (const sc_signed& u, long v); 2066 friend bool operator >= (const sc_signed& u, unsigned long v); 2067 friend bool operator >= (const sc_signed& u, int v) 2068 { return operator>=(u, (long) v); } 2069 friend bool operator >= (const sc_signed& u, unsigned int v) 2070 { return operator>=(u, (unsigned long) v); } 2071 2072 friend bool operator >= (int64 u, const sc_signed& v); 2073 friend bool operator >= (uint64 u, const sc_signed& v); 2074 friend bool operator >= (long u, const sc_signed& v); 2075 friend bool operator >= (unsigned long u, const sc_signed& v); 2076 friend bool operator >= (int u, const sc_signed& v) 2077 { return operator>=((long) u, v); } 2078 friend bool operator >= (unsigned int u, const sc_signed& v) 2079 { return operator>=((unsigned long) u, v); } 2080 2081 friend bool operator >= (const sc_signed& u, const sc_int_base& v); 2082 friend bool operator >= (const sc_signed& u, const sc_uint_base& v); 2083 friend bool operator >= (const sc_int_base& u, const sc_signed& v); 2084 friend bool operator >= (const sc_uint_base& u, const sc_signed& v); 2085 2086 // Bitwise NOT operator (unary). 2087 friend sc_signed operator ~ (const sc_signed& u); 2088 2089 // Helper functions. 2090 friend sc_signed add_signed_friend(small_type us, 2091 int unb, 2092 int und, 2093 const sc_digit *ud, 2094 small_type vs, 2095 int vnb, 2096 int vnd, 2097 const sc_digit *vd); 2098 2099 friend sc_signed sub_signed_friend(small_type us, 2100 int unb, 2101 int und, 2102 const sc_digit *ud, 2103 small_type vs, 2104 int vnb, 2105 int vnd, 2106 const sc_digit *vd); 2107 2108 friend sc_signed mul_signed_friend(small_type s, 2109 int unb, 2110 int und, 2111 const sc_digit *ud, 2112 int vnb, 2113 int vnd, 2114 const sc_digit *vd); 2115 2116 friend sc_signed div_signed_friend(small_type s, 2117 int unb, 2118 int und, 2119 const sc_digit *ud, 2120 int vnb, 2121 int vnd, 2122 const sc_digit *vd); 2123 2124 friend sc_signed mod_signed_friend(small_type us, 2125 int unb, 2126 int und, 2127 const sc_digit *ud, 2128 int vnb, 2129 int vnd, 2130 const sc_digit *vd); 2131 2132 friend sc_signed and_signed_friend(small_type us, 2133 int unb, 2134 int und, 2135 const sc_digit *ud, 2136 small_type vs, 2137 int vnb, 2138 int vnd, 2139 const sc_digit *vd); 2140 2141 friend sc_signed or_signed_friend(small_type us, 2142 int unb, 2143 int und, 2144 const sc_digit *ud, 2145 small_type vs, 2146 int vnb, 2147 int vnd, 2148 const sc_digit *vd); 2149 2150 friend sc_signed xor_signed_friend(small_type us, 2151 int unb, 2152 int und, 2153 const sc_digit *ud, 2154 small_type vs, 2155 int vnb, 2156 int vnd, 2157 const sc_digit *vd); 2158 2159private: 2160 2161 small_type sgn; // Shortened as s. 2162 int nbits; // Shortened as nb. 2163 int ndigits; // Shortened as nd. 2164 2165#ifdef SC_MAX_NBITS 2166 sc_digit digit[DIV_CEIL(SC_MAX_NBITS)]; // Shortened as d. 2167#else 2168 sc_digit *digit; // Shortened as d. 2169#endif 2170 2171 // Private constructors: 2172 2173 // Create a copy of v with sign s. 2174 sc_signed(const sc_signed& v, small_type s); 2175 sc_signed(const sc_unsigned& v, small_type s); 2176 2177 // Create a signed number with the given attributes. 2178 sc_signed(small_type s, int nb, int nd, 2179 sc_digit *d, bool alloc = true); 2180 2181 // Create an unsigned number using the bits u[l..r]. 2182 sc_signed(const sc_signed* u, int l, int r); 2183 sc_signed(const sc_unsigned* u, int l, int r); 2184 2185 // Private member functions. The called functions are inline functions. 2186 2187 small_type default_sign() const 2188 { return SC_NOSIGN; } 2189 2190 int num_bits(int nb) const { return nb; } 2191 2192 bool check_if_outside(int bit_num) const; 2193 2194 void copy_digits(int nb, int nd, const sc_digit *d) 2195 { copy_digits_signed(sgn, nbits, ndigits, digit, nb, nd, d); } 2196 2197 void makezero() 2198 { sgn = make_zero(ndigits, digit); } 2199 2200 // Conversion functions between 2's complement (2C) and 2201 // sign-magnitude (SM): 2202 void convert_2C_to_SM() 2203 { sgn = convert_signed_2C_to_SM(nbits, ndigits, digit); } 2204 2205 void convert_SM_to_2C_to_SM() 2206 { sgn = convert_signed_SM_to_2C_to_SM(sgn, nbits, ndigits, digit); } 2207 2208 void convert_SM_to_2C() 2209 { convert_signed_SM_to_2C(sgn, ndigits, digit); } 2210 2211}; 2212 2213 2214 2215inline 2216::std::ostream& 2217operator << ( ::std::ostream&, const sc_signed& ); 2218 2219inline 2220::std::istream& 2221operator >> ( ::std::istream&, sc_signed& ); 2222 2223 2224 2225inline 2226::std::ostream& 2227operator << ( ::std::ostream& os, const sc_signed_bitref_r& a ) 2228{ 2229 a.print( os ); 2230 return os; 2231} 2232 2233 2234inline 2235::std::istream& 2236operator >> ( ::std::istream& is, sc_signed_bitref& a ) 2237{ 2238 a.scan( is ); 2239 return is; 2240} 2241 2242 2243// ---------------------------------------------------------------------------- 2244// CLASS : sc_signed_subref_r 2245// 2246// Proxy class for sc_signed part selection (r-value only). 2247// ---------------------------------------------------------------------------- 2248 2249 2250// reduce methods 2251 2252inline bool sc_signed_subref_r::and_reduce() const 2253{ 2254 const sc_signed* target_p = m_obj_p; 2255 for ( int i = m_right; i <= m_left; i++ ) 2256 if ( !target_p->test(i) ) return false; 2257 return true; 2258} 2259 2260inline bool sc_signed_subref_r::nand_reduce() const 2261{ 2262 return !and_reduce(); 2263} 2264 2265inline bool sc_signed_subref_r::or_reduce() const 2266{ 2267 const sc_signed* target_p = m_obj_p; 2268 for ( int i = m_right; i <= m_left; i++ ) 2269 if ( target_p->test(i) ) return true; 2270 return false; 2271} 2272 2273inline bool sc_signed_subref_r::nor_reduce() const 2274{ 2275 return !or_reduce(); 2276} 2277 2278inline bool sc_signed_subref_r::xor_reduce() const 2279{ 2280 int odd; 2281 const sc_signed* target_p = m_obj_p; 2282 odd = 0; 2283 for ( int i = m_right; i <= m_left; i++ ) 2284 if ( target_p->test(i) ) odd = ~odd; 2285 return odd ? true : false; 2286} 2287 2288inline bool sc_signed_subref_r::xnor_reduce() const 2289{ 2290 return !xor_reduce(); 2291} 2292 2293inline 2294::std::ostream& 2295operator << ( ::std::ostream& os, const sc_signed_subref_r& a ) 2296{ 2297 a.print( os ); 2298 return os; 2299} 2300 2301 2302// ---------------------------------------------------------------------------- 2303// CLASS : sc_signed_subref 2304// 2305// Proxy class for sc_signed part selection (r-value and l-value). 2306// ---------------------------------------------------------------------------- 2307 2308// assignment operators 2309 2310inline 2311const sc_signed_subref& 2312sc_signed_subref::operator = ( const char* a ) 2313{ 2314 sc_signed aa( length() ); 2315 return ( *this = aa = a ); 2316} 2317 2318 2319 2320 2321inline 2322::std::istream& 2323operator >> ( ::std::istream& is, sc_signed_subref& a ) 2324{ 2325 a.scan( is ); 2326 return is; 2327} 2328 2329 2330 2331// ---------------------------------------------------------------------------- 2332// CLASS : sc_signed 2333// 2334// Arbitrary precision signed number. 2335// ---------------------------------------------------------------------------- 2336 2337template<class T> 2338sc_signed::sc_signed( const sc_generic_base<T>& v ) 2339{ 2340 int nb = v->length(); 2341 sgn = default_sign(); 2342 if( nb > 0 ) { 2343 nbits = num_bits( nb ); 2344 } else { 2345 char msg[BUFSIZ]; 2346 std::sprintf( msg, 2347 "sc_unsigned( sc_generic_base<T> ) : nb = %d is not valid", nb); 2348 SC_REPORT_ERROR( sc_core::SC_ID_INIT_FAILED_, msg ); 2349 } 2350 ndigits = DIV_CEIL(nbits); 2351# ifdef SC_MAX_NBITS 2352 test_bound(nb); 2353# else 2354 digit = new sc_digit[ndigits]; 2355# endif 2356 makezero(); 2357 v->to_sc_signed(*this); 2358} 2359 2360 2361 2362inline 2363::std::ostream& 2364operator << ( ::std::ostream& os, const sc_signed& a ) 2365{ 2366 a.print( os ); 2367 return os; 2368} 2369 2370inline 2371::std::istream& 2372operator >> ( ::std::istream& is, sc_signed& a ) 2373{ 2374 a.scan( is ); 2375 return is; 2376} 2377 2378 2379} // namespace sc_dt 2380 2381 2382#endif 2383