test07.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  test07.cpp --
23
24  Original Author: Andy Goodrich, Forte Design Systems, 29 October 2007
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 various width concatenations for each major base type.
39
40#include "systemc.h"
41
42void checkout( const sc_unsigned* actual_p, const sc_unsigned* expected_p )
43{
44    cout << *actual_p <<" " << *expected_p << endl;
45	cout <<"another line" << endl;
46}
47
48#define TEST(LEFT,RIGHT) \
49{ \
50    const sc_unsigned* actual_p = &(LEFT,RIGHT).value(); \
51    const sc_unsigned* expected_p = &(high_int,low_int).value(); \
52	if ( *actual_p != *expected_p ) \
53	{ \
54	    checkout(actual_p, expected_p); \
55		cout << "!!! ERROR (" << #LEFT << "," << #RIGHT << "):" << endl; \
56		cout << "    expected:  " << hex << *expected_p  << endl; \
57		cout << "    actual:    " << hex << *actual_p << endl; \
58		cout << "    diff mask: " << hex << ((high_int,low_int) ^ (LEFT,RIGHT))  << endl; \
59	} \
60}
61
62int sc_main(int argc, char* argv[])
63{
64    for ( int cycle_i = 0; cycle_i < 3; cycle_i++ )
65	{
66		for ( int high_i = 64; high_i > 0; high_i-- )
67		{
68			for ( int low_i = 64; low_i > 0; --low_i )
69			{
70				sc_int_base  high_int(high_i);
71				sc_int_base  low_int(low_i);
72				sc_signed    high_signed(high_i);
73				sc_signed    low_signed(low_i);
74				sc_uint_base high_uint(high_i);
75				sc_uint_base low_uint(low_i);
76				sc_unsigned  high_unsigned(high_i);
77				sc_unsigned  low_unsigned(low_i);
78
79				switch ( cycle_i )
80				{
81				  case 0:
82					low_int =       "0xaaaaaaaa55555555";
83					low_signed =    "0xaaaaaaaa55555555";
84					low_uint =      "0xaaaaaaaa55555555";
85					low_unsigned =  "0xaaaaaaaa55555555";
86					high_int =      "0xfedcba9876543210";
87					high_signed =   "0xfedcba9876543210";
88					high_uint =     "0xfedcba9876543210";
89					high_unsigned = "0xfedcba9876543210";
90				    break;
91			      case 1:
92					low_int =       "0x0000000000000000";
93					low_signed =    "0x0000000000000000";
94					low_uint =      "0x0000000000000000";
95					low_unsigned =  "0x0000000000000000";
96					high_int =      "0xffffffffffffffff";
97					high_signed =   "0xffffffffffffffff";
98					high_uint =     "0xffffffffffffffff";
99					high_unsigned = "0xffffffffffffffff";
100					break;
101			      case 2:
102					low_int =       "0xffffffffffffffff";
103					low_signed =    "0xffffffffffffffff";
104					low_uint =      "0xffffffffffffffff";
105					low_unsigned =  "0xffffffffffffffff";
106					high_int =      "0x0000000000000000";
107					high_signed =   "0x0000000000000000";
108					high_uint =     "0x0000000000000000";
109					high_unsigned = "0x0000000000000000";
110					break;
111				}
112
113				cout << endl << dec << "[" << high_i << "," << low_i << "]:"
114					 << endl;
115
116				cout << hex << "  int      " << (high_int,low_int) << " <- (  "
117							<< high_int  << " , " << low_int << " )" << endl;
118
119				TEST(high_int,low_signed);
120				TEST(high_int,low_uint);
121				TEST(high_int,low_unsigned);
122
123				TEST(high_signed,low_int);
124				TEST(high_signed,low_signed);
125				TEST(high_signed,low_uint);
126				TEST(high_signed,low_unsigned);
127
128				TEST(high_uint,low_int);
129				TEST(high_uint,low_signed);
130				TEST(high_uint,low_uint);
131				TEST(high_uint,low_unsigned);
132
133				TEST(high_unsigned,low_int);
134				TEST(high_unsigned,low_signed);
135				TEST(high_unsigned,low_uint);
136				TEST(high_unsigned,low_unsigned);
137			}
138		}
139    }
140
141	cout << "Program completed" << endl;
142	return 0;
143}
144