assign.cpp revision 12855:588919e0e4aa
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 assign.cpp -- 23 24 Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37 38// This may look like C code, but it is really -*- C++ -*- 39// 40// assign.cxx -- 41// Copyright Synopsys 1998 42// Author : Ric Hilderink 43// Created On : Wed Dec 30 09:58:11 1998 44// Status : none 45// 46 47#include <limits.h> 48#define SC_INCLUDE_FX 49#define SC_FXVAL_IMPLICIT_CONV 50#include "systemc.h" 51 52typedef unsigned int uint; 53typedef unsigned short ushort; 54typedef unsigned long ulong; 55 56#define SHOW_ASSIGN(a) cerr << #a << " : " << double(a) << " : " << a.to_string(SC_HEX) << "\n" 57#define IDENT_ASSIGN(a) cerr << "--assign-Inf-Inf-Inf-Inf-Inf- " << a << "\n" 58 59//---------------------------------------------------------------- 60static void test_fx_float_int() 61{ 62 IDENT_ASSIGN("test_fx_float_int"); 63 64 sc_fxval a = 0; 65 sc_fxval b; 66 sc_fxval c = b = -1; 67 68 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 69} 70 71static void test_fx_float_uint() 72{ 73 IDENT_ASSIGN("test_fx_float_uint"); 74 75 sc_fxval a = (uint)0; 76 sc_fxval b; 77 sc_fxval c = b = (uint)-1; 78 79 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 80} 81 82static void test_fx_float_short() 83{ 84 IDENT_ASSIGN("test_fx_float_short"); 85 86 sc_fxval a = (short)0; 87 sc_fxval b; 88 sc_fxval c = b = (short)-1; 89 90 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 91} 92 93static void test_fx_float_ushort() 94{ 95 IDENT_ASSIGN("test_fx_float_ushort"); 96 97 sc_fxval a = (ushort)0; 98 sc_fxval b; 99 sc_fxval c = b = (ushort)-1; 100 101 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 102} 103 104static void test_fx_float_long() 105{ 106 IDENT_ASSIGN("test_fx_float_long"); 107 108 sc_fxval a = (long)0; 109 sc_fxval b; 110 sc_fxval c = b = -1L; 111 112 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 113} 114 115static void test_fx_float_ulong() 116{ 117 IDENT_ASSIGN("test_fx_float_ulong"); 118 sc_fxval a(0); 119 sc_fxval b; 120 sc_fxval c = b = -1UL; 121 122 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 123} 124 125static void test_fx_float_float() 126{ 127 IDENT_ASSIGN("test_fx_float_float"); 128 129 sc_fxval a(0.0f); 130 sc_fxval b; 131 sc_fxval c = b = -1.0f; 132 133 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 134} 135 136static void test_fx_float_double() 137{ 138 IDENT_ASSIGN("test_fx_float_double"); 139 140 sc_fxval a(0.0); 141 sc_fxval b; 142 sc_fxval c = b = -1.0; 143 144 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 145} 146 147//---------------------------------------------------------------- 148static void test_fx_ufix_int() 149{ 150 IDENT_ASSIGN("test_fx_ufix_int"); 151 152 sc_ufix a(0); 153 sc_ufix b; 154 sc_ufix c = b = -1; 155 156 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 157} 158 159static void test_fx_ufix_uint() 160{ 161 IDENT_ASSIGN("test_fx_ufix_uint"); 162 163 sc_ufix a(0u); 164 sc_ufix b; 165 sc_ufix c = b = (uint)-1; 166 167 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 168} 169 170static void test_fx_ufix_short() 171{ 172 IDENT_ASSIGN("test_fx_ufix_short"); 173 174 sc_ufix a((short)0); 175 sc_ufix b; 176 sc_ufix c = b = (short)-1; 177 178 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 179} 180 181static void test_fx_ufix_ushort() 182{ 183 IDENT_ASSIGN("test_fx_ufix_ushort"); 184 185 sc_ufix a((ushort)0); 186 sc_ufix b; 187 sc_ufix c = b = (ushort)-1; 188 189 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 190} 191 192static void test_fx_ufix_long() 193{ 194 IDENT_ASSIGN("test_fx_ufix_long"); 195 196 sc_ufix a(0L); 197 sc_ufix b; 198 sc_ufix c = b = -1L; 199 200 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 201} 202 203static void test_fx_ufix_ulong() 204{ 205 IDENT_ASSIGN("test_fx_ufix_ulong"); 206 sc_ufix a = (ulong)0; 207 sc_ufix b; 208 sc_ufix c = b = (ulong)-1; 209 210 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 211} 212 213static void test_fx_ufix_float() 214{ 215 IDENT_ASSIGN("test_fx_ufix_float"); 216 217 sc_ufix a = 0.0; 218 sc_ufix b; 219 sc_ufix c = b = -1.0; 220 221 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 222} 223 224static void test_fx_ufix_double() 225{ 226 IDENT_ASSIGN("test_fx_ufix_double"); 227 228 sc_ufix a = (double)0.0; 229 sc_ufix b; 230 sc_ufix c = b = (double)-1.0; 231 232 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 233} 234 235//---------------------------------------------------------------- 236static void test_fx_fix_int() 237{ 238 IDENT_ASSIGN("test_fx_fix_int"); 239 240 sc_fix a = 0; 241 sc_fix b; 242 sc_fix c = b = -1; 243 244 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 245} 246 247static void test_fx_fix_uint() 248{ 249 IDENT_ASSIGN("test_fx_fix_uint"); 250 251 sc_fix a = (uint)0; 252 sc_fix b; 253 sc_fix c = b = (uint)-1; 254 255 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 256} 257 258static void test_fx_fix_short() 259{ 260 IDENT_ASSIGN("test_fx_fix_short"); 261 262 sc_fix a = (short)0; 263 sc_fix b; 264 sc_fix c = b = (short)-1; 265 266 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 267} 268 269static void test_fx_fix_ushort() 270{ 271 IDENT_ASSIGN("test_fx_fix_ushort"); 272 273 sc_fix a = (ushort)0; 274 sc_fix b; 275 sc_fix c = b = (ushort)-1; 276 277 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 278} 279 280static void test_fx_fix_long() 281{ 282 IDENT_ASSIGN("test_fx_fix_long"); 283 284 sc_fix a = (long)0; 285 sc_fix b; 286 sc_fix c = b = (long)-1; 287 288 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 289} 290 291static void test_fx_fix_ulong() 292{ 293 IDENT_ASSIGN("test_fx_fix_ulong"); 294 sc_fix a = (ulong)0; 295 sc_fix b; 296 sc_fix c = b = (ulong)-1; 297 298 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 299} 300 301static void test_fx_fix_float() 302{ 303 IDENT_ASSIGN("test_fx_fix_float"); 304 305 sc_fix a = 0.0; 306 sc_fix b; 307 sc_fix c = b = -1.0; 308 309 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 310} 311 312static void test_fx_fix_double() 313{ 314 IDENT_ASSIGN("test_fx_fix_double"); 315 316 sc_fix a = (double)0.0; 317 sc_fix b; 318 sc_fix c = b = (double)-1.0; 319 320 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 321} 322 323//---------------------------------------------------------------- 324static void test_fx_fixed_int() 325{ 326 IDENT_ASSIGN("test_fx_fixed_int"); 327 328 sc_fixed<8, 5> a = 0; 329 sc_fixed<8, 5> b; 330 sc_fixed<8, 5> c = b = -1; 331 332 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 333} 334 335static void test_fx_fixed_uint() 336{ 337 IDENT_ASSIGN("test_fx_fixed_uint"); 338 339 sc_fixed<8, 5> a = (uint)0; 340 sc_fixed<8, 5> b; 341 sc_fixed<8, 5> c = b = (uint)abs(-1); 342 343 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 344} 345 346static void test_fx_fixed_short() 347{ 348 IDENT_ASSIGN("test_fx_fixed_short"); 349 350 sc_fixed<8, 5> a = (short)0; 351 sc_fixed<8, 5> b; 352 sc_fixed<8, 5> c = b = (short)-1; 353 354 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 355} 356 357static void test_fx_fixed_ushort() 358{ 359 IDENT_ASSIGN("test_fx_fixed_ushort"); 360 361 sc_fixed<8, 5> a = (ushort)0; 362 sc_fixed<8, 5> b; 363 sc_fixed<8, 5> c = b = (ushort)abs(-1); 364 365 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 366} 367 368static void test_fx_fixed_long() 369{ 370 IDENT_ASSIGN("test_fx_fixed_long"); 371 372 sc_fixed<8, 5> a = (long)0; 373 sc_fixed<8, 5> b; 374 sc_fixed<8, 5> c = b = (long)-1; 375 376 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 377} 378 379static void test_fx_fixed_ulong() 380{ 381 IDENT_ASSIGN("test_fx_fixed_ulong"); 382 sc_fixed<8, 5> a = (ulong)0; 383 sc_fixed<8, 5> b; 384 sc_fixed<8, 5> c = b = (ulong)abs(-1); 385 386 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 387} 388 389static void test_fx_fixed_float() 390{ 391 IDENT_ASSIGN("test_fx_fixed_float"); 392 393 sc_fixed<8, 5> a = 0.0; 394 sc_fixed<8, 5> b; 395 sc_fixed<8, 5> c = b = -1.0; 396 397 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 398} 399 400static void test_fx_fixed_double() 401{ 402 IDENT_ASSIGN("test_fx_fixed_double"); 403 404 sc_fixed<8, 5> a = (double)0.0; 405 sc_fixed<8, 5> b; 406 sc_fixed<8, 5> c = b = (double)-1.0; 407 408 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 409} 410 411//---------------------------------------------------------------- 412static void test_fx_ufixed_int() 413{ 414 IDENT_ASSIGN("test_fx_ufixed_int"); 415 416 sc_ufixed<8, 5> a = 0; 417 sc_ufixed<8, 5> b; 418 sc_ufixed<8, 5> c = b = -1; 419 420 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 421} 422 423static void test_fx_ufixed_uint() 424{ 425 IDENT_ASSIGN("test_fx_ufixed_uint"); 426 427 sc_ufixed<8, 5> a = (uint)0; 428 sc_ufixed<8, 5> b; 429 sc_ufixed<8, 5> c = b = (uint)abs(-1); 430 431 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 432} 433 434static void test_fx_ufixed_short() 435{ 436 IDENT_ASSIGN("test_fx_ufixed_short"); 437 438 sc_ufixed<8, 5> a = (short)0; 439 sc_ufixed<8, 5> b; 440 sc_ufixed<8, 5> c = b = (short)-1; 441 442 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 443} 444 445static void test_fx_ufixed_ushort() 446{ 447 IDENT_ASSIGN("test_fx_ufixed_ushort"); 448 449 sc_ufixed<8, 5> a = (ushort)0; 450 sc_ufixed<8, 5> b; 451 sc_ufixed<8, 5> c = b = (ushort)abs(-1); 452 453 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 454} 455 456static void test_fx_ufixed_long() 457{ 458 IDENT_ASSIGN("test_fx_ufixed_long"); 459 460 sc_ufixed<8, 5> a = (long)0; 461 sc_ufixed<8, 5> b; 462 sc_ufixed<8, 5> c = b = (long)-1; 463 464 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 465} 466 467static void test_fx_ufixed_ulong() 468{ 469 IDENT_ASSIGN("test_fx_ufixed_ulong"); 470 sc_ufixed<8, 5> a = (ulong)0; 471 sc_ufixed<8, 5> b; 472 sc_ufixed<8, 5> c = b = (ulong)abs(-1); 473 474 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 475} 476 477static void test_fx_ufixed_float() 478{ 479 IDENT_ASSIGN("test_fx_ufixed_float"); 480 481 sc_ufixed<8, 5> a = 0.0; 482 sc_ufixed<8, 5> b; 483 sc_ufixed<8, 5> c = b = -1.0; 484 485 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 486} 487 488static void test_fx_ufixed_double() 489{ 490 IDENT_ASSIGN("test_fx_ufixed_double"); 491 492 sc_ufixed<8, 5> a = (double)0.0; 493 sc_ufixed<8, 5> b; 494 sc_ufixed<8, 5> c = b = (double)-1.0; 495 496 SHOW_ASSIGN(a); SHOW_ASSIGN(b); SHOW_ASSIGN(c); 497} 498 499void assign() 500{ 501 cerr << "************** assign test_fx_float_\n"; 502 test_fx_float_int(); 503 test_fx_float_uint(); 504 test_fx_float_short(); 505 test_fx_float_ushort(); 506 test_fx_float_long(); 507 test_fx_float_ulong(); 508 test_fx_float_float(); 509 test_fx_float_double(); 510 cerr << "************** assign test_fx_ufix_\n"; 511 test_fx_ufix_int(); 512 test_fx_ufix_uint(); 513 test_fx_ufix_short(); 514 test_fx_ufix_ushort(); 515 test_fx_ufix_long(); 516 test_fx_ufix_ulong(); 517 test_fx_ufix_float(); 518 test_fx_ufix_double(); 519 cerr << "************** assign test_fx_fix_\n"; 520 test_fx_fix_int(); 521 test_fx_fix_uint(); 522 test_fx_fix_short(); 523 test_fx_fix_ushort(); 524 test_fx_fix_long(); 525 test_fx_fix_ulong(); 526 test_fx_fix_float(); 527 test_fx_fix_double(); 528 cerr << "************** assign test_fx_fixed_\n"; 529 test_fx_fixed_int(); 530 test_fx_fixed_uint(); 531 test_fx_fixed_short(); 532 test_fx_fixed_ushort(); 533 test_fx_fixed_long(); 534 test_fx_fixed_ulong(); 535 test_fx_fixed_float(); 536 test_fx_fixed_double(); 537 cerr << "************** assign test_fx_ufixed_\n"; 538 test_fx_ufixed_int(); 539 test_fx_ufixed_uint(); 540 test_fx_ufixed_short(); 541 test_fx_ufixed_ushort(); 542 test_fx_ufixed_long(); 543 test_fx_ufixed_ulong(); 544 test_fx_ufixed_float(); 545 test_fx_ufixed_double(); 546} 547