test12.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  test12.cpp -- Test that part selections are returning the proper values
23                when they are part of a concatenation. This tests is here
24                because the wrong width mask was being used in the 2.2
25                source.
26
27  Original Author: Andy Goodrich, Forte Design Systems, 03 Feb 2010
28
29 *****************************************************************************/
30
31/*****************************************************************************
32
33  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
34  changes you are making here.
35
36      Name, Affiliation, Date:
37  Description of Modification:
38
39 *****************************************************************************/
40
41
42#include "systemc.h"
43
44#define TEST(TARGET) \
45    expected = TARGET(high,low); \
46    result = (sc_uint<6>(0),TARGET(high,low)); \
47    if ( result != expected ) \
48    { \
49	cout << dec; \
50	cout << "Mismatch for " << #TARGET << "(" << high << "," << low << "):"\
51	     << endl; \
52	cout << "Expected " << hex << expected << " got " << result \
53	     << dec << endl; \
54    }
55
56int sc_main(int argc, char* argv[])
57{
58    sc_bigint<37>  bi37;
59    sc_biguint<37> bu37;
60    sc_int<37>     i37;
61    sc_uint<37>    u37;
62
63    bi37 = 0x1fc070000ULL;
64    bu37 = 0x1fc070000ULL;
65    i37 = 0x1fc070000ULL;
66    u37 = 0x1fc070000ULL;
67
68    // Test sc_int<W>:
69
70    cout << endl << "sc_int test" << endl;
71    cout << "i37 = " << hex << i37 << endl;
72    cout << "i37(33,0) = " << hex << i37(33,0) << endl;
73    cout << "(sc_uint<6>(0),i37(33,0)) = "
74         << hex << (sc_uint<6>(0),i37(33,0))
75         << endl;
76
77    // Test sc_uint<W>:
78
79    cout << endl << "sc_uint test" << endl;
80    cout << "u37 = " << hex << u37 << endl;
81    cout << "u37(33,0) = " << hex << u37(33,0) << endl;
82    cout << "(sc_uint<6>(0),u37(33,0)) = "
83         << hex << (sc_uint<6>(0),u37(33,0))
84         << endl;
85
86    // Test sc_bigint<W>:
87
88    cout << endl << "sc_bigint test" << endl;
89    cout << "bi37 = " << hex << bi37 << endl;
90    cout << "bi37(33,0) = " << hex << bi37(33,0) << endl;
91    cout << "(sc_uint<6>(0),bi37(33,0)) = "
92         << hex << (sc_uint<6>(0),bi37(33,0))
93         << endl;
94
95    // Test sc_biguint<W>:
96
97    cout << endl << "sc_biguint test" << endl;
98    cout << "bu37 = " << hex << bu37 << endl;
99    cout << "bu37(33,0) = " << hex << bu37(33,0) << endl;
100    cout << "(sc_uint<6>(0),bu37(33,0)) = "
101         << hex << (sc_uint<6>(0),bu37(33,0))
102         << endl;
103
104    sc_bigint<64>  bi64;
105    sc_biguint<64> bu64;
106    sc_uint<64>    expected;
107    sc_int<64>     i64;
108    sc_uint<64>    result;
109    sc_uint<64>    u64;
110
111    bi64 = -1;
112    bu64 = -1;
113    i64 = -1;
114    u64 = -1;
115    for ( size_t low = 0; low < 64; low++ )
116    {
117	for ( size_t high = low; high < 64; high++ )
118	{
119	    TEST(bi64);
120	    TEST(bu64);
121	    TEST(i64);
122	    TEST(u64);
123	}
124    }
125
126    bi64 = 0x6666666666666666ULL;
127    bu64 = 0x6aaaaaaaaaaaaaaaULL;
128    i64 = 0x6aaaaaaaaaaaaaaaULL;
129    u64 = 0x6aaaaaaaaaaaaaaaULL;
130    for ( size_t low = 0; low < 64; low++ )
131    {
132	for ( size_t high = low; high < 64; high++ )
133	{
134	    TEST(bi64);
135	    TEST(bu64);
136	    TEST(i64);
137	    TEST(u64);
138	}
139    }
140
141    bi64 = 0xaaaaaaaaaaaaaaaaULL;
142    bu64 = 0xaaaaaaaaaaaaaaaaULL;
143    i64 = 0xaaaaaaaaaaaaaaaaULL;
144    u64 = 0xaaaaaaaaaaaaaaaaULL;
145    for ( size_t low = 0; low < 64; low++ )
146    {
147	for ( size_t high = low; high < 64; high++ )
148	{
149	    TEST(bi64);
150	    TEST(bu64);
151	    TEST(i64);
152	    TEST(u64);
153	}
154    }
155
156
157    cout << endl << "Program completed" << endl;
158
159    return 0;
160}
161