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.com
4112855Sgabeblack@google.comint sc_main( int ac, char *av[] )
4212855Sgabeblack@google.com{
4312855Sgabeblack@google.com  sc_int_base a(8),b(8);
4412855Sgabeblack@google.com  int x;
4512855Sgabeblack@google.com
4612855Sgabeblack@google.com
4712855Sgabeblack@google.com
4812855Sgabeblack@google.com  x = 8;
4912855Sgabeblack@google.com  a = 8;
5012855Sgabeblack@google.com  sc_assert( x == a);
5112855Sgabeblack@google.com
5212855Sgabeblack@google.com  cout << "x + a = " << x + a << endl;
5312855Sgabeblack@google.com  cout << "++a = " << ++a << endl;
5412855Sgabeblack@google.com  cout << "a-- = " << a-- << endl;
5512855Sgabeblack@google.com
5612855Sgabeblack@google.com  // bit-select on L.H.S.
5712855Sgabeblack@google.com  a[0] = 1;
5812855Sgabeblack@google.com  cout << "a = " << a << endl;
5912855Sgabeblack@google.com
6012855Sgabeblack@google.com  // bitselect on R.H.S.
6112855Sgabeblack@google.com  cout << "a[3] = " << a[3] << endl;
6212855Sgabeblack@google.com
6312855Sgabeblack@google.com
6412855Sgabeblack@google.com  // part-select on R.H.S
6512855Sgabeblack@google.com  cout << "a.range(4,0) = " << a.range(4,0) << endl;
6612855Sgabeblack@google.com  cout << "a = " << a << endl;
6712855Sgabeblack@google.com
6812855Sgabeblack@google.com  sc_int_base c(5);
6912855Sgabeblack@google.com  c = a.range(4,0);
7012855Sgabeblack@google.com  cout << "c = " << c << endl;
7112855Sgabeblack@google.com
7212855Sgabeblack@google.com  // part-select on L.H.S.
7312855Sgabeblack@google.com  a.range(2,0) = 7;
7412855Sgabeblack@google.com  cout << "a = " << a << endl;
7512855Sgabeblack@google.com
7612855Sgabeblack@google.com  a.range(4,2) = 5;
7712855Sgabeblack@google.com  cout << "a = " << a << endl;
7812855Sgabeblack@google.com
7912855Sgabeblack@google.com  a.range(7,4) = 8;
8012855Sgabeblack@google.com  cout << "a = " << a << endl;
8112855Sgabeblack@google.com
8212855Sgabeblack@google.com  // concat on R.H.S.
8312855Sgabeblack@google.com  sc_int_base sx(4);
8412855Sgabeblack@google.com  sx = 1;
8512855Sgabeblack@google.com  sc_int_base sy(4);
8612855Sgabeblack@google.com  sy = 3;
8712855Sgabeblack@google.com  a = ( sx, sy );
8812855Sgabeblack@google.com
8912855Sgabeblack@google.com  cout << "a = " << a << endl;
9012855Sgabeblack@google.com
9112855Sgabeblack@google.com  sc_int_base sb(8);
9212855Sgabeblack@google.com  // concat of part-selects
9312855Sgabeblack@google.com  sb = ( a.range(7,4), a.range(3,0) );
9412855Sgabeblack@google.com
9512855Sgabeblack@google.com  cout << "sb = " << sb << endl;
9612855Sgabeblack@google.com
9712855Sgabeblack@google.com  ( sx, sy ) = 17;
9812855Sgabeblack@google.com
9912855Sgabeblack@google.com  cout << "sx = " << sx << endl;
10012855Sgabeblack@google.com  cout << "sy = " << sy << endl;
10112855Sgabeblack@google.com
10212855Sgabeblack@google.com  // concat and part-selects
10312855Sgabeblack@google.com  ( sx, sy ) = ( a.range(7,4), a.range(3,0) );
10412855Sgabeblack@google.com
10512855Sgabeblack@google.com  cout << "sx = " << sx << endl;
10612855Sgabeblack@google.com  cout << "sy = " << sy << endl;
10712855Sgabeblack@google.com
10812855Sgabeblack@google.com  sc_int_base  s5(5);
10912855Sgabeblack@google.com
11012855Sgabeblack@google.com  s5 = ( sx , a[4] );
11112855Sgabeblack@google.com
11212855Sgabeblack@google.com  cout << "s5 = " << s5 << endl;
11312855Sgabeblack@google.com
11412855Sgabeblack@google.com  s5 = (a[4],sx);
11512855Sgabeblack@google.com  cout << "s5 = " << s5 << endl;
11612855Sgabeblack@google.com
11712855Sgabeblack@google.com  sc_bv<8> sc8;
11812855Sgabeblack@google.com  sc_bv<4> sc4;
11912855Sgabeblack@google.com
12012855Sgabeblack@google.com  // ( sc8.range(7,4), sc4 ) = 17;
12112855Sgabeblack@google.com  ( sc8.range(7,4), sc4 ) = "00010001";
12212855Sgabeblack@google.com
12312855Sgabeblack@google.com  cout << "sc8 = " << sc8.to_int() << endl;
12412855Sgabeblack@google.com  cout << "sc4 = " << sc4.to_int() << endl;
12512855Sgabeblack@google.com
12612855Sgabeblack@google.com  sc_int_base sia(8);
12712855Sgabeblack@google.com
12812855Sgabeblack@google.com
12912855Sgabeblack@google.com  sc_uint_base u4(4);
13012855Sgabeblack@google.com
13112855Sgabeblack@google.com  // part-select on sc_uint
13212855Sgabeblack@google.com  u4 = sx.range(3,0);
13312855Sgabeblack@google.com
13412855Sgabeblack@google.com  cout << "u4 = " << u4 << endl;
13512855Sgabeblack@google.com
13612855Sgabeblack@google.com  u4[3] = sx[0];
13712855Sgabeblack@google.com
13812855Sgabeblack@google.com  cout << "u4 = " << u4 << endl;
13912855Sgabeblack@google.com
14012855Sgabeblack@google.com  sx = (u4.range(1,0), u4.range(3,2));
14112855Sgabeblack@google.com
14212855Sgabeblack@google.com  cout << "sx = " << sx << endl;
14312855Sgabeblack@google.com
14412855Sgabeblack@google.com  sc_bv<8> bva;
14512855Sgabeblack@google.com  sc_lv<8> lva;
14612855Sgabeblack@google.com
14712855Sgabeblack@google.com  // Mixing bv, lv on the RHS
14812855Sgabeblack@google.com
14912855Sgabeblack@google.com  bva = "10000000";
15012855Sgabeblack@google.com  lva = "10000001";
15112855Sgabeblack@google.com
15212855Sgabeblack@google.com  b = bva & "1010";
15312855Sgabeblack@google.com  cout << "b = " << b << endl;
15412855Sgabeblack@google.com
15512855Sgabeblack@google.com  // b = lva ^ bva;
15612855Sgabeblack@google.com  b = sc_bv<8>( lva ^ bva );
15712855Sgabeblack@google.com  cout << "b = " << b << endl;
15812855Sgabeblack@google.com
15912855Sgabeblack@google.com  //Mixing bv, lv on the LHS
16012855Sgabeblack@google.com
16112855Sgabeblack@google.com  bva = b;
16212855Sgabeblack@google.com  lva = b;
16312855Sgabeblack@google.com
16412855Sgabeblack@google.com  cout << "bva = " << bva << endl;
16512855Sgabeblack@google.com  cout << "lva = " << lva << endl;
16612855Sgabeblack@google.com
16712855Sgabeblack@google.com  bva = b & lva.to_int();
16812855Sgabeblack@google.com
16912855Sgabeblack@google.com  cout << "bva = " << bva << endl;
17012855Sgabeblack@google.com
17112855Sgabeblack@google.com
17212855Sgabeblack@google.com  //Mixing sc_signed on LHS
17312855Sgabeblack@google.com
17412855Sgabeblack@google.com  sc_signed ss8(8);
17512855Sgabeblack@google.com  ss8 = b;
17612855Sgabeblack@google.com  cout << "ss8 = " << ss8 << endl;
17712855Sgabeblack@google.com
17812855Sgabeblack@google.com  ss8 = u4;
17912855Sgabeblack@google.com  cout << "ss8 = " << ss8 << endl;
18012855Sgabeblack@google.com
18112855Sgabeblack@google.com  // Mixing sc_signed/sc_unsigned on RHS
18212855Sgabeblack@google.com  sc_unsigned su8(8);
18312855Sgabeblack@google.com
18412855Sgabeblack@google.com  su8 = 8;
18512855Sgabeblack@google.com  b = su8 + 1;
18612855Sgabeblack@google.com
18712855Sgabeblack@google.com  cout << "b = " << b << endl;
18812855Sgabeblack@google.com
18912855Sgabeblack@google.com  b = ss8 * su8;
19012855Sgabeblack@google.com  b = ss8 ^ su8;
19112855Sgabeblack@google.com  su8 = bva.to_int() | ss8;
19212855Sgabeblack@google.com
19312855Sgabeblack@google.com  cout << "b = " << b << endl;
19412855Sgabeblack@google.com
19512855Sgabeblack@google.com  // Having more than two concats
19612855Sgabeblack@google.com
19712855Sgabeblack@google.com  sc_int_base ai2(2);
19812855Sgabeblack@google.com  sc_int_base bi4(4);
19912855Sgabeblack@google.com  sc_int_base ci2(2);
20012855Sgabeblack@google.com  sc_int_base di2(2);
20112855Sgabeblack@google.com  sc_int_base ei8(8);
20212855Sgabeblack@google.com  sc_int_base ei10(10);
20312855Sgabeblack@google.com
20412855Sgabeblack@google.com  ai2 = 2;
20512855Sgabeblack@google.com  bi4 = 2;
20612855Sgabeblack@google.com  ci2 = 2;
20712855Sgabeblack@google.com  di2 = 2;
20812855Sgabeblack@google.com
20912855Sgabeblack@google.com  ei8 = (ai2, bi4, ci2 );
21012855Sgabeblack@google.com
21112855Sgabeblack@google.com  cout << "ei8 = " << ei8 << endl;
21212855Sgabeblack@google.com
21312855Sgabeblack@google.com  ei10 = (ai2, bi4, ci2 , di2);
21412855Sgabeblack@google.com
21512855Sgabeblack@google.com  cout << "ei10 = " << ei10 << endl;
21612855Sgabeblack@google.com
21712855Sgabeblack@google.com  // bit-true behavior
21812855Sgabeblack@google.com  sc_int_base bs4(4);
21912855Sgabeblack@google.com  sc_signed ds4(4);
22012855Sgabeblack@google.com
22112855Sgabeblack@google.com  bs4[3] = 1;
22212855Sgabeblack@google.com  bs4[2] = 0;
22312855Sgabeblack@google.com  bs4[1] = 0;
22412855Sgabeblack@google.com  bs4[0] = 0;
22512855Sgabeblack@google.com
22612855Sgabeblack@google.com  ds4[3] = 1;
22712855Sgabeblack@google.com  ds4[2] = 0;
22812855Sgabeblack@google.com  ds4[1] = 0;
22912855Sgabeblack@google.com  ds4[0] = 0;
23012855Sgabeblack@google.com
23112855Sgabeblack@google.com
23212855Sgabeblack@google.com  cout << "bs4  = " << bs4 << endl;
23312855Sgabeblack@google.com  cout << "ds4 =  " << ds4 << endl;
23412855Sgabeblack@google.com
23512855Sgabeblack@google.com  return 0;
23612855Sgabeblack@google.com
23712855Sgabeblack@google.com}
238