112855Sgabeblack@google.com/***************************************************************************** 212855Sgabeblack@google.com 312855Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412855Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512855Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612855Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712855Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812855Sgabeblack@google.com License. You may obtain a copy of the License at 912855Sgabeblack@google.com 1012855Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112855Sgabeblack@google.com 1212855Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312855Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412855Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512855Sgabeblack@google.com implied. See the License for the specific language governing 1612855Sgabeblack@google.com permissions and limitations under the License. 1712855Sgabeblack@google.com 1812855Sgabeblack@google.com *****************************************************************************/ 1912855Sgabeblack@google.com 2012855Sgabeblack@google.com/***************************************************************************** 2112855Sgabeblack@google.com 2212855Sgabeblack@google.com test_int.cpp -- 2312855Sgabeblack@google.com 2412855Sgabeblack@google.com Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 2512855Sgabeblack@google.com 2612855Sgabeblack@google.com *****************************************************************************/ 2712855Sgabeblack@google.com 2812855Sgabeblack@google.com/***************************************************************************** 2912855Sgabeblack@google.com 3012855Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3112855Sgabeblack@google.com changes you are making here. 3212855Sgabeblack@google.com 3312855Sgabeblack@google.com Name, Affiliation, Date: 3412855Sgabeblack@google.com Description of Modification: 3512855Sgabeblack@google.com 3612855Sgabeblack@google.com *****************************************************************************/ 3712855Sgabeblack@google.com 3812855Sgabeblack@google.com#include "systemc.h" 3912855Sgabeblack@google.com 4012855Sgabeblack@google.comint sc_main( int ac, char *av[] ) 4112855Sgabeblack@google.com{ 4212855Sgabeblack@google.com sc_int<8> a,b; 4312855Sgabeblack@google.com int x; 4412855Sgabeblack@google.com 4512855Sgabeblack@google.com 4612855Sgabeblack@google.com 4712855Sgabeblack@google.com x = 8; 4812855Sgabeblack@google.com a = 8; 4912855Sgabeblack@google.com sc_assert( x == a); 5012855Sgabeblack@google.com 5112855Sgabeblack@google.com cout << "x + a = " << x + a << endl; 5212855Sgabeblack@google.com cout << "++a = " << ++a << endl; 5312855Sgabeblack@google.com cout << "a-- = " << a-- << endl; 5412855Sgabeblack@google.com 5512855Sgabeblack@google.com // bit-select on L.H.S. 5612855Sgabeblack@google.com a[0] = 1; 5712855Sgabeblack@google.com cout << "a = " << a << endl; 5812855Sgabeblack@google.com 5912855Sgabeblack@google.com // bitselect on R.H.S. 6012855Sgabeblack@google.com cout << "a[3] = " << a[3] << endl; 6112855Sgabeblack@google.com 6212855Sgabeblack@google.com 6312855Sgabeblack@google.com // part-select on R.H.S 6412855Sgabeblack@google.com cout << "a.range(4,0) = " << a.range(4,0) << endl; 6512855Sgabeblack@google.com cout << "a = " << a << endl; 6612855Sgabeblack@google.com 6712855Sgabeblack@google.com sc_int<5> c = a.range(4,0); 6812855Sgabeblack@google.com cout << "c = " << c << endl; 6912855Sgabeblack@google.com 7012855Sgabeblack@google.com // part-select on L.H.S. 7112855Sgabeblack@google.com a.range(2,0) = 7; 7212855Sgabeblack@google.com cout << "a = " << a << endl; 7312855Sgabeblack@google.com 7412855Sgabeblack@google.com a.range(4,2) = 5; 7512855Sgabeblack@google.com cout << "a = " << a << endl; 7612855Sgabeblack@google.com 7712855Sgabeblack@google.com a.range(7,4) = 8; 7812855Sgabeblack@google.com cout << "a = " << a << endl; 7912855Sgabeblack@google.com 8012855Sgabeblack@google.com // concat on R.H.S. 8112855Sgabeblack@google.com sc_int<4> sx = 1; 8212855Sgabeblack@google.com sc_int<4> sy = 3; 8312855Sgabeblack@google.com a = ( sx, sy ); 8412855Sgabeblack@google.com 8512855Sgabeblack@google.com cout << "a = " << a << endl; 8612855Sgabeblack@google.com 8712855Sgabeblack@google.com sc_int<8> sb; 8812855Sgabeblack@google.com // concat of part-selects 8912855Sgabeblack@google.com sb = ( a.range(7,4), a.range(3,0) ); 9012855Sgabeblack@google.com 9112855Sgabeblack@google.com cout << "sb = " << sb << endl; 9212855Sgabeblack@google.com 9312855Sgabeblack@google.com ( sx, sy ) = 17; 9412855Sgabeblack@google.com 9512855Sgabeblack@google.com cout << "sx = " << sx << endl; 9612855Sgabeblack@google.com cout << "sy = " << sy << endl; 9712855Sgabeblack@google.com 9812855Sgabeblack@google.com // concat and part-selects 9912855Sgabeblack@google.com ( sx, sy ) = ( a.range(7,4), a.range(3,0) ); 10012855Sgabeblack@google.com 10112855Sgabeblack@google.com cout << "sx = " << sx << endl; 10212855Sgabeblack@google.com cout << "sy = " << sy << endl; 10312855Sgabeblack@google.com 10412855Sgabeblack@google.com sc_int<5> s5; 10512855Sgabeblack@google.com 10612855Sgabeblack@google.com s5 = ( sx , a[4] ); 10712855Sgabeblack@google.com 10812855Sgabeblack@google.com cout << "s5 = " << s5 << endl; 10912855Sgabeblack@google.com 11012855Sgabeblack@google.com s5 = (a[4],sx); 11112855Sgabeblack@google.com cout << "s5 = " << s5 << endl; 11212855Sgabeblack@google.com 11312855Sgabeblack@google.com sc_bv<8> sc8; 11412855Sgabeblack@google.com sc_bv<4> sc4; 11512855Sgabeblack@google.com 11612855Sgabeblack@google.com // ( sc8.range(7,4), sc4 ) = 17; 11712855Sgabeblack@google.com ( sc8.range(7,4), sc4 ) = "00010001"; 11812855Sgabeblack@google.com 11912855Sgabeblack@google.com cout << "sc8 = " << sc8.to_int() << endl; 12012855Sgabeblack@google.com cout << "sc4 = " << sc4.to_int() << endl; 12112855Sgabeblack@google.com 12212855Sgabeblack@google.com sc_int_base sia(8); 12312855Sgabeblack@google.com 12412855Sgabeblack@google.com 12512855Sgabeblack@google.com sc_uint<4> u4; 12612855Sgabeblack@google.com 12712855Sgabeblack@google.com // part-select on sc_uint 12812855Sgabeblack@google.com u4 = sx.range(3,0); 12912855Sgabeblack@google.com 13012855Sgabeblack@google.com cout << "u4 = " << u4 << endl; 13112855Sgabeblack@google.com 13212855Sgabeblack@google.com u4[3] = sx[0]; 13312855Sgabeblack@google.com 13412855Sgabeblack@google.com cout << "u4 = " << u4 << endl; 13512855Sgabeblack@google.com 13612855Sgabeblack@google.com sx = (u4.range(1,0), u4.range(3,2)); 13712855Sgabeblack@google.com 13812855Sgabeblack@google.com cout << "sx = " << sx << endl; 13912855Sgabeblack@google.com 14012855Sgabeblack@google.com sc_bv<8> bva; 14112855Sgabeblack@google.com sc_lv<8> lva; 14212855Sgabeblack@google.com 14312855Sgabeblack@google.com // Mixing bv, lv on the RHS 14412855Sgabeblack@google.com 14512855Sgabeblack@google.com bva = "10000000"; 14612855Sgabeblack@google.com lva = "10000001"; 14712855Sgabeblack@google.com 14812855Sgabeblack@google.com// #if ! defined( __GNUC__ ) 14912855Sgabeblack@google.com b = bva & "1010"; 15012855Sgabeblack@google.com cout << "b = " << b << endl; 15112855Sgabeblack@google.com// #endif 15212855Sgabeblack@google.com 15312855Sgabeblack@google.com // b = lva ^ bva; 15412855Sgabeblack@google.com b = sc_lv<8>( lva ^ bva ); 15512855Sgabeblack@google.com cout << "b = " << b << endl; 15612855Sgabeblack@google.com 15712855Sgabeblack@google.com //Mixing bv, lv on the LHS 15812855Sgabeblack@google.com 15912855Sgabeblack@google.com bva = b; 16012855Sgabeblack@google.com lva = b; 16112855Sgabeblack@google.com 16212855Sgabeblack@google.com cout << "bva = " << bva << endl; 16312855Sgabeblack@google.com cout << "lva = " << lva << endl; 16412855Sgabeblack@google.com 16512855Sgabeblack@google.com bva = b & lva.to_int(); 16612855Sgabeblack@google.com 16712855Sgabeblack@google.com cout << "bva = " << bva << endl; 16812855Sgabeblack@google.com 16912855Sgabeblack@google.com 17012855Sgabeblack@google.com //Mixing sc_signed on LHS 17112855Sgabeblack@google.com 17212855Sgabeblack@google.com sc_signed ss8(8); 17312855Sgabeblack@google.com ss8 = b; 17412855Sgabeblack@google.com cout << "ss8 = " << ss8 << endl; 17512855Sgabeblack@google.com 17612855Sgabeblack@google.com ss8 = u4; 17712855Sgabeblack@google.com cout << "ss8 = " << ss8 << endl; 17812855Sgabeblack@google.com 17912855Sgabeblack@google.com // Mixing sc_signed/sc_unsigned on RHS 18012855Sgabeblack@google.com sc_unsigned su8(8); 18112855Sgabeblack@google.com 18212855Sgabeblack@google.com su8 = 8; 18312855Sgabeblack@google.com b = su8 + 1; 18412855Sgabeblack@google.com 18512855Sgabeblack@google.com cout << "b = " << b << endl; 18612855Sgabeblack@google.com 18712855Sgabeblack@google.com b = ss8 * su8; 18812855Sgabeblack@google.com b = ss8 ^ su8; 18912855Sgabeblack@google.com su8 = bva.to_int() | ss8; 19012855Sgabeblack@google.com 19112855Sgabeblack@google.com cout << "b = " << b << endl; 19212855Sgabeblack@google.com 19312855Sgabeblack@google.com // Having more than two concats 19412855Sgabeblack@google.com 19512855Sgabeblack@google.com sc_int<2> ai2; 19612855Sgabeblack@google.com sc_int<4> bi4; 19712855Sgabeblack@google.com sc_int<2> ci2; 19812855Sgabeblack@google.com sc_int<2> di2; 19912855Sgabeblack@google.com sc_int<8> ei8; 20012855Sgabeblack@google.com sc_int<10> ei10; 20112855Sgabeblack@google.com 20212855Sgabeblack@google.com ai2 = 2; 20312855Sgabeblack@google.com bi4 = 2; 20412855Sgabeblack@google.com ci2 = 2; 20512855Sgabeblack@google.com di2 = 2; 20612855Sgabeblack@google.com 20712855Sgabeblack@google.com ei8 = (ai2, bi4, ci2 ); 20812855Sgabeblack@google.com 20912855Sgabeblack@google.com cout << "ei8 = " << ei8 << endl; 21012855Sgabeblack@google.com 21112855Sgabeblack@google.com ei10 = (ai2, bi4, ci2 , di2); 21212855Sgabeblack@google.com 21312855Sgabeblack@google.com cout << "ei10 = " << ei10 << endl; 21412855Sgabeblack@google.com 21512855Sgabeblack@google.com // bit-true behavior 21612855Sgabeblack@google.com sc_int<4> bs4; 21712855Sgabeblack@google.com sc_signed ds4(4); 21812855Sgabeblack@google.com 21912855Sgabeblack@google.com bs4[3] = 1; 22012855Sgabeblack@google.com bs4[2] = 0; 22112855Sgabeblack@google.com bs4[1] = 0; 22212855Sgabeblack@google.com bs4[0] = 0; 22312855Sgabeblack@google.com 22412855Sgabeblack@google.com ds4[3] = 1; 22512855Sgabeblack@google.com ds4[2] = 0; 22612855Sgabeblack@google.com ds4[1] = 0; 22712855Sgabeblack@google.com ds4[0] = 0; 22812855Sgabeblack@google.com 22912855Sgabeblack@google.com 23012855Sgabeblack@google.com cout << "bs4 = " << bs4 << endl; 23112855Sgabeblack@google.com cout << "ds4 = " << ds4 << endl; 23212855Sgabeblack@google.com 23312855Sgabeblack@google.com return 0; 23412855Sgabeblack@google.com 23512855Sgabeblack@google.com} 236