test.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 test.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/* 39Subject: range() of sc_biguint 40From: "Masahiro Taniguchi" <taniguchi.masahiro@lsi.melco.co.jp> 41Date: Mon, 12 Nov 2001 16:29:04 +0900 42To: "systemc-forum" <systemc-forum@systemc.org> 43 44Hi all, 45 46I found a strange simulation result regarding sc_biguint. 47I attached the example about it. 48The example described 3 case. 49 1. Write non-0 50 2. Write 0 without cast 51 3. Write 0 with cast (sc_biguint<8>) 52The wrong result appears in the 2nd case. 53Is this a bug of SystemC? 54 55-------Environment------- 56 SystemC V1.0.2 and V2.0 57 GCC 2.95.2 58 Sun Solaris 59------------------------- 60 61Regards, 62 63Masahiro Taniguchi 64Mitsubishi Electric Corporation 65JAPAN 66 67------------------------------------------------------------ 68*/ 69 70#include "systemc.h" 71 72int 73sc_main( int, char*[] ) 74{ 75 int i; 76 int index0,index1; 77 sc_biguint<128> A; 78 sc_uint<16> B; 79 sc_biguint<128> Y; 80 81 A = 0; 82 Y = 0; 83 cout << "A = " << A.to_string(SC_HEX) << endl; 84 cout << "Y = " << Y.to_string(SC_HEX) << endl << endl; 85 86 // 1st Case 87 A = "0xffffffffffffffffffffffffffffffff"; 88 B = 0; 89 90 for(i=15;i>=0;i--) 91 { 92 index0 = 8*(i+1)-1; 93 index1 = 8* i; 94 if(B[i] == 0) { 95 Y.range(index0,index1) = A.range(index0,index1); 96 } 97 } 98 99 cout << "A = " << A.to_string(SC_HEX) << endl; 100 cout << "B = " << hex << B << endl; 101 cout << "Y = " << Y.to_string(SC_HEX) << endl << endl; 102 103 // 2nd Case 104 A = 0; 105 B = 0; 106 107 for(i=15;i>=0;i--) 108 { 109 index0 = 8*(i+1)-1; 110 index1 = 8* i; 111 if(B[i] == 0) { 112 Y.range(index0,index1) = A.range(index0,index1); 113 } 114 } 115 116 cout << "A = " << A.to_string(SC_HEX) << endl; 117 cout << "B = " << hex << B << endl; 118 cout << "Y = " << Y.to_string(SC_HEX) << endl << endl; 119 120 // 3rd Case 121 A = 0; 122 B = 0; 123 124 for(i=15;i>=0;i--) 125 { 126 index0 = 8*(i+1)-1; 127 index1 = 8* i; 128 if(B[i] == 0) { 129 Y.range(index0,index1) = (sc_biguint<8>)A.range(index0,index1); 130 } 131 } 132 133 cout << "A = " << A.to_string(SC_HEX) << endl; 134 cout << "B = " << hex << B << endl; 135 cout << "Y = " << Y.to_string(SC_HEX) << endl << endl; 136 137 return(0); 138} 139