test_int.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_int.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#include "systemc.h" 39 40int sc_main( int ac, char *av[] ) 41{ 42 sc_int<8> a,b; 43 int x; 44 45 46 47 x = 8; 48 a = 8; 49 sc_assert( x == a); 50 51 cout << "x + a = " << x + a << endl; 52 cout << "++a = " << ++a << endl; 53 cout << "a-- = " << a-- << endl; 54 55 // bit-select on L.H.S. 56 a[0] = 1; 57 cout << "a = " << a << endl; 58 59 // bitselect on R.H.S. 60 cout << "a[3] = " << a[3] << endl; 61 62 63 // part-select on R.H.S 64 cout << "a.range(4,0) = " << a.range(4,0) << endl; 65 cout << "a = " << a << endl; 66 67 sc_int<5> c = a.range(4,0); 68 cout << "c = " << c << endl; 69 70 // part-select on L.H.S. 71 a.range(2,0) = 7; 72 cout << "a = " << a << endl; 73 74 a.range(4,2) = 5; 75 cout << "a = " << a << endl; 76 77 a.range(7,4) = 8; 78 cout << "a = " << a << endl; 79 80 // concat on R.H.S. 81 sc_int<4> sx = 1; 82 sc_int<4> sy = 3; 83 a = ( sx, sy ); 84 85 cout << "a = " << a << endl; 86 87 sc_int<8> sb; 88 // concat of part-selects 89 sb = ( a.range(7,4), a.range(3,0) ); 90 91 cout << "sb = " << sb << endl; 92 93 ( sx, sy ) = 17; 94 95 cout << "sx = " << sx << endl; 96 cout << "sy = " << sy << endl; 97 98 // concat and part-selects 99 ( sx, sy ) = ( a.range(7,4), a.range(3,0) ); 100 101 cout << "sx = " << sx << endl; 102 cout << "sy = " << sy << endl; 103 104 sc_int<5> s5; 105 106 s5 = ( sx , a[4] ); 107 108 cout << "s5 = " << s5 << endl; 109 110 s5 = (a[4],sx); 111 cout << "s5 = " << s5 << endl; 112 113 sc_bv<8> sc8; 114 sc_bv<4> sc4; 115 116 // ( sc8.range(7,4), sc4 ) = 17; 117 ( sc8.range(7,4), sc4 ) = "00010001"; 118 119 cout << "sc8 = " << sc8.to_int() << endl; 120 cout << "sc4 = " << sc4.to_int() << endl; 121 122 sc_int_base sia(8); 123 124 125 sc_uint<4> u4; 126 127 // part-select on sc_uint 128 u4 = sx.range(3,0); 129 130 cout << "u4 = " << u4 << endl; 131 132 u4[3] = sx[0]; 133 134 cout << "u4 = " << u4 << endl; 135 136 sx = (u4.range(1,0), u4.range(3,2)); 137 138 cout << "sx = " << sx << endl; 139 140 sc_bv<8> bva; 141 sc_lv<8> lva; 142 143 // Mixing bv, lv on the RHS 144 145 bva = "10000000"; 146 lva = "10000001"; 147 148// #if ! defined( __GNUC__ ) 149 b = bva & "1010"; 150 cout << "b = " << b << endl; 151// #endif 152 153 // b = lva ^ bva; 154 b = sc_lv<8>( lva ^ bva ); 155 cout << "b = " << b << endl; 156 157 //Mixing bv, lv on the LHS 158 159 bva = b; 160 lva = b; 161 162 cout << "bva = " << bva << endl; 163 cout << "lva = " << lva << endl; 164 165 bva = b & lva.to_int(); 166 167 cout << "bva = " << bva << endl; 168 169 170 //Mixing sc_signed on LHS 171 172 sc_signed ss8(8); 173 ss8 = b; 174 cout << "ss8 = " << ss8 << endl; 175 176 ss8 = u4; 177 cout << "ss8 = " << ss8 << endl; 178 179 // Mixing sc_signed/sc_unsigned on RHS 180 sc_unsigned su8(8); 181 182 su8 = 8; 183 b = su8 + 1; 184 185 cout << "b = " << b << endl; 186 187 b = ss8 * su8; 188 b = ss8 ^ su8; 189 su8 = bva.to_int() | ss8; 190 191 cout << "b = " << b << endl; 192 193 // Having more than two concats 194 195 sc_int<2> ai2; 196 sc_int<4> bi4; 197 sc_int<2> ci2; 198 sc_int<2> di2; 199 sc_int<8> ei8; 200 sc_int<10> ei10; 201 202 ai2 = 2; 203 bi4 = 2; 204 ci2 = 2; 205 di2 = 2; 206 207 ei8 = (ai2, bi4, ci2 ); 208 209 cout << "ei8 = " << ei8 << endl; 210 211 ei10 = (ai2, bi4, ci2 , di2); 212 213 cout << "ei10 = " << ei10 << endl; 214 215 // bit-true behavior 216 sc_int<4> bs4; 217 sc_signed ds4(4); 218 219 bs4[3] = 1; 220 bs4[2] = 0; 221 bs4[1] = 0; 222 bs4[0] = 0; 223 224 ds4[3] = 1; 225 ds4[2] = 0; 226 ds4[1] = 0; 227 ds4[0] = 0; 228 229 230 cout << "bs4 = " << bs4 << endl; 231 cout << "ds4 = " << ds4 << endl; 232 233 return 0; 234 235} 236