test05.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  test05.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// test of sc_uint's concat operators -- basic functionality, concat()
39
40#include "systemc.h"
41
42void
43test_concat( const sc_uint<8>& a )
44{
45    sc_uint<8> b;
46    sc_uint<4> c;
47    sc_uint<4> d;
48
49    cout << a << endl;
50
51    cout << "*** sc_uint_base" << endl;
52
53    concat( c, d ) = a;
54    cout << c << endl;
55    cout << d << endl;
56
57    b = concat( d, c );
58    cout << b << endl;
59
60    cout << "---" << endl;
61
62    concat( c, d[1] ) = a.range( 4, 0 );
63    cout << c << endl;
64    cout << d << endl;
65
66    b.range( 4, 0 ) = concat( c, d[1] );
67    cout << b << endl;
68
69    cout << "---" << endl;
70
71    concat( c, d.range( 1, 0 ) ) = a.range( 5, 0 );
72    cout << c << endl;
73    cout << d << endl;
74
75    b.range( 5, 0 ) = concat( c, d.range( 1, 0 ) );
76    cout << b << endl;
77
78    cout << "---" << endl;
79
80    concat( c, concat( d[0], d[1] ) ) = a.range( 5, 0 );
81    cout << c << endl;
82    cout << d << endl;
83
84    b.range( 5, 0 ) = concat( c, concat( d[0], d[1] ) );
85    cout << b << endl;
86
87    cout << "*** sc_uint_bitref" << endl;
88
89    concat( d[1], c ) = a.range( 4, 0 );
90    cout << c << endl;
91    cout << d << endl;
92
93    b.range( 4, 0 ) = concat( d[1], c );
94    cout << b << endl;
95
96    cout << "---" << endl;
97
98    concat( d[0], d[1] ) = a.range( 1,0 );
99    cout << d << endl;
100
101    b.range( 1, 0 ) = concat( d[1], d[0] );
102    cout << b << endl;
103
104    cout << "---" << endl;
105
106    concat( d[0], c.range( 3, 0 ) ) = a.range( 4, 0 );
107    cout << c << endl;
108    cout << d << endl;
109
110    b.range( 4, 0 ) = concat( d[0], c.range( 3, 0 ) );
111    cout << b << endl;
112
113    cout << "---" << endl;
114
115    concat( d[0], concat( concat( d[1], d[2] ), d[3] ) ) = a.range( 3, 0 );
116    cout << d << endl;
117
118    b.range( 3, 0 ) = concat( d[3], concat( concat( d[2], d[1] ), d[0] ) );
119    cout << b << endl;
120
121    cout << "*** sc_uint_subref" << endl;
122
123    concat( c.range( 3, 0 ), d ) = a;
124    cout << c << endl;
125    cout << d << endl;
126
127    b = concat( c.range( 3, 0 ), d );
128    cout << b << endl;
129
130    cout << "---" << endl;
131
132    concat( c.range( 3, 0 ), d[1] ) = a.range( 4, 0 );
133    cout << c << endl;
134    cout << d << endl;
135
136    b.range( 4, 0 ) = concat( c.range( 3, 0 ), d[1] );
137    cout << b << endl;
138
139    cout << "---" << endl;
140
141    concat( c.range( 3, 0 ), d.range( 3, 0 ) ) = a;
142    cout << c << endl;
143    cout << d << endl;
144
145    b = concat( d.range( 3, 0 ), c.range( 3, 0 ) );
146    cout << b << endl;
147
148    cout << "---" << endl;
149
150    concat( c.range( 3, 0 ), concat( d[0], d[1] ) ) = a.range( 5, 0 );
151    cout << c << endl;
152    cout << d << endl;
153
154    b.range( 5, 0 ) = concat( c.range( 3, 0 ), concat( d[1], d[0] ) );
155    cout << b << endl;
156
157    cout << "*** sc_uint_concat" << endl;
158
159    concat( concat( c[1], c[0] ), d ) = a.range( 5, 0 );
160    cout << c << endl;
161    cout << d << endl;
162
163    b.range( 5, 0 ) = concat( concat( c[0], c[1] ), d );
164    cout << b << endl;
165
166    cout << "---" << endl;
167
168    concat( concat( c[1], c[0] ), d[0] ) = a.range( 2, 0 );
169    cout << c << endl;
170    cout << d << endl;
171
172    b.range( 2, 0 ) = concat( concat( c[0], c[1] ), d[0] );
173    cout << b << endl;
174
175    cout << "---" << endl;
176
177    concat( concat( c[1], c[0] ), d.range( 3, 0 ) ) = a.range( 5, 0 );
178    cout << c << endl;
179    cout << d << endl;
180
181    b.range( 5, 0 ) = concat( concat( c[0], c[1] ), d.range( 3, 0 ) );
182    cout << b << endl;
183
184    cout << "---" << endl;
185
186    concat( concat( c[0], c[1] ), concat( c[2], c[3] ) ) = a.range( 3, 0 );
187    cout << c << endl;
188
189    b.range( 3, 0 ) = concat( concat( c[3], c[2] ), concat( c[1], c[0] ) );
190    cout << b << endl;
191}
192
193int
194sc_main( int, char*[] )
195{
196    sc_uint<8> a( 33 );
197
198    test_concat( a );
199
200    return 0;
201}
202