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