test01.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  test01.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 the bitwise binary operators of sc_proxy<X>
39
40#include "systemc.h"
41
42int
43sc_main( int, char*[] )
44{
45    sc_bv<32> bv = 10;
46    sc_bv<32> lv = 11;
47
48    int I = 12;
49    unsigned U = 12;
50
51    sc_bv<32> bv1;
52    sc_bv<32> bv2;
53    sc_lv<32> lv1;
54    sc_lv<32> lv2;
55
56    // &
57
58    bv1 = bv;
59    bv2 = bv;
60    bv1 &= I;
61    bv2 = bv2 & I;
62    sc_assert( bv1 == bv2 );
63
64    bv1 = bv;
65    bv2 = bv;
66    bv1 &= U;
67    bv2 = bv2 & U;
68    sc_assert( bv1 == bv2 );
69
70    lv1 = lv;
71    lv2 = lv;
72    lv1 &= I;
73    lv2 = lv2 & I;
74    sc_assert( lv1 == lv2 );
75
76    lv1 = lv;
77    lv2 = lv;
78    lv1 &= U;
79    lv2 = lv2 & U;
80    sc_assert( lv1 == lv2 );
81
82    // |
83
84    bv1 = bv;
85    bv2 = bv;
86    bv1 |= I;
87    bv2 = bv2 | I;
88    sc_assert( bv1 == bv2 );
89
90    bv1 = bv;
91    bv2 = bv;
92    bv1 |= U;
93    bv2 = bv2 | U;
94    sc_assert( bv1 == bv2 );
95
96    lv1 = lv;
97    lv2 = lv;
98    lv1 |= I;
99    lv2 = lv2 | I;
100    sc_assert( lv1 == lv2 );
101
102    lv1 = lv;
103    lv2 = lv;
104    lv1 |= U;
105    lv2 = lv2 | U;
106    sc_assert( lv1 == lv2 );
107
108    // ^
109
110    bv1 = bv;
111    bv2 = bv;
112    bv1 ^= I;
113    bv2 = bv2 ^ I;
114    sc_assert( bv1 == bv2 );
115
116    bv1 = bv;
117    bv2 = bv;
118    bv1 ^= U;
119    bv2 = bv2 ^ U;
120    sc_assert( bv1 == bv2 );
121
122    lv1 = lv;
123    lv2 = lv;
124    lv1 ^= I;
125    lv2 = lv2 ^ I;
126    sc_assert( lv1 == lv2 );
127
128    lv1 = lv;
129    lv2 = lv;
130    lv1 ^= U;
131    lv2 = lv2 ^ U;
132    sc_assert( lv1 == lv2 );
133
134    cout << "OK" << endl;
135
136    return 0;
137}
138