test08.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  test08.cpp --
23
24  Original Author: Andy Goodrich, Forte Design Systems, 9 November 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 concatenation uses that were reported not to work with SystemC 2.1.v1
39
40#include "systemc.h"
41
42int sc_main(int argc, char* argv[])
43{
44    {
45	    sc_uint<2> a = 1;
46	    sc_uint<2> b = 2;
47		sc_uint<10> f = 0 - (a,b);
48
49		// subtraction of a concat from 0.
50
51		if ( f != 0x3fa )
52		{
53			cout << __FILE__ << " " << __LINE__ << ": expected " << 0x3fa
54			     << " actual " << f << dec << endl;
55		}
56
57	    // subtraction of a concat from a concat if left < right.
58
59		f = (a,b) -  (b,a);
60		if ( f != 0x3fd )
61		{
62			cout << __FILE__ << " " << __LINE__ << ": expected " << 0x3fd
63			     << " actual " << f << dec << endl;
64		}
65
66    }
67	{ // multiplication times a negative integer.
68
69		sc_uint<4> a = 10;
70		int        b = 0xdd6283e4;
71	    sc_uint<2> c = 1;
72		sc_uint<40> e("0xfc7c016528");
73		sc_uint<40> f = (c,a)*b;
74		if ( f != e )
75        {
76			cout << __FILE__ << " " << __LINE__ << ": expected " << hex << e
77			     << " actual " << f << dec << endl;
78		}
79	}
80
81    { // divsion where dividend negative and of type int/long
82		sc_uint<4> a = 14;
83		int        b = 0xb292b9fe;
84        sc_uint<2> c = 3;
85		sc_uint<50> e = b / sc_biguint<6>(0x3e);
86        sc_uint<50> f = b / (c,a);
87
88		if ( f != e )
89        {
90			cout << __FILE__ << " " << __LINE__ << ": expected " << hex << e
91			     << " actual " << f << dec << endl;
92		}
93
94	}
95	{ // modulo for negative int % concat
96
97	    sc_uint<4> a = 10;
98		int        b = 0xbb6283e4;
99		sc_uint<2> c = 1;
100		sc_uint<50> e = b % sc_biguint<6>(0x1a);
101		sc_uint<50> f = b %(c,a);
102		if ( f != e )
103        {
104			cout << __FILE__ << " " << __LINE__ << ": expected " << hex << e
105			     << " actual " << f << dec << endl;
106		}
107	}
108
109	{ // Bitwise or and xor, when operands are concat and unsigned int
110
111		sc_uint<4> a = 6;
112		unsigned int b = 0xcc6690e6;
113		sc_uint<2> c = 3;
114		sc_uint<34> e;
115		sc_uint<34> f;
116		e = b | 0x36;
117		f = b | (c,a);
118		if ( f != e )
119        {
120			cout << __FILE__ << " " << __LINE__ << ": expected " << hex << e
121			     << " actual " << f << dec << endl;
122		}
123
124		e = b ^ 0x36;
125		f = b ^ (c,a);
126		if ( f != e )
127        {
128			cout << __FILE__ << " " << __LINE__ << ": expected " << hex << e
129			     << " actual " << f << dec << endl;
130		}
131	}
132
133	cout << "Program completed" << endl;
134	return 0;
135}
136