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  test02.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 reduce methods in the sc_[u]int datatypes -- functional notation
39
40#include "systemc.h"
41
42int
43sc_main( int, char*[] )
44{
45    // 1) check the existence of the reduce methods
46
47    sc_int<42> a = 42;
48
49    // sc_int_base
50    cout << endl;
51    cout <<  and_reduce( a ) << endl;
52    cout <<   or_reduce( a ) << endl;
53    cout <<  xor_reduce( a ) << endl;
54    cout << nand_reduce( a ) << endl;
55    cout <<  nor_reduce( a ) << endl;
56    cout << xnor_reduce( a ) << endl;
57
58    // sc_int_subref
59    cout << endl;
60    cout <<  and_reduce( a( 7, 0 ) ) << endl;
61    cout <<   or_reduce( a( 7, 0 ) ) << endl;
62    cout <<  xor_reduce( a( 7, 0 ) ) << endl;
63    cout << nand_reduce( a( 7, 0 ) ) << endl;
64    cout <<  nor_reduce( a( 7, 0 ) ) << endl;
65    cout << xnor_reduce( a( 7, 0 ) ) << endl;
66
67    // sc_int_concref<T1,T2>
68    cout << endl;
69    cout <<  and_reduce( ( a( 7, 0 ), a( 15, 8 ) ) ) << endl;
70    cout <<   or_reduce( ( a( 7, 0 ), a( 15, 8 ) ) ) << endl;
71    cout <<  xor_reduce( ( a( 7, 0 ), a( 15, 8 ) ) ) << endl;
72    cout << nand_reduce( ( a( 7, 0 ), a( 15, 8 ) ) ) << endl;
73    cout <<  nor_reduce( ( a( 7, 0 ), a( 15, 8 ) ) ) << endl;
74    cout << xnor_reduce( ( a( 7, 0 ), a( 15, 8 ) ) ) << endl;
75
76    sc_uint<42> b = 42;
77
78    // sc_uint_base
79    cout << endl;
80    cout <<  and_reduce( b ) << endl;
81    cout <<   or_reduce( b ) << endl;
82    cout <<  xor_reduce( b ) << endl;
83    cout << nand_reduce( b ) << endl;
84    cout <<  nor_reduce( b ) << endl;
85    cout << xnor_reduce( b ) << endl;
86
87    // sc_uint_subref
88    cout << endl;
89    cout <<  and_reduce( b( 7, 0 ) ) << endl;
90    cout <<   or_reduce( b( 7, 0 ) ) << endl;
91    cout <<  xor_reduce( b( 7, 0 ) ) << endl;
92    cout << nand_reduce( b( 7, 0 ) ) << endl;
93    cout <<  nor_reduce( b( 7, 0 ) ) << endl;
94    cout << xnor_reduce( b( 7, 0 ) ) << endl;
95
96    // sc_uint_concref<T1,T2>
97    cout << endl;
98    cout <<  and_reduce( ( b( 7, 0 ), b( 15, 8 ) ) ) << endl;
99    cout <<   or_reduce( ( b( 7, 0 ), b( 15, 8 ) ) ) << endl;
100    cout <<  xor_reduce( ( b( 7, 0 ), b( 15, 8 ) ) ) << endl;
101    cout << nand_reduce( ( b( 7, 0 ), b( 15, 8 ) ) ) << endl;
102    cout <<  nor_reduce( ( b( 7, 0 ), b( 15, 8 ) ) ) << endl;
103    cout << xnor_reduce( ( b( 7, 0 ), b( 15, 8 ) ) ) << endl;
104
105    // 2) check the functionality of the reduce methods
106
107    sc_int<2> c2 = -1;
108    cout << endl;
109    cout << and_reduce( c2 ) << endl;
110    cout << xor_reduce( c2 ) << endl;
111
112    sc_int<3> c3 = -1;
113    cout << endl;
114    cout << and_reduce( c3 ) << endl;
115    cout << xor_reduce( c3 ) << endl;
116
117    sc_uint<2> d2 = sc_dt::uint_type( -1 );
118    cout << endl;
119    cout << and_reduce( d2 ) << endl;
120    cout << xor_reduce( d2 ) << endl;
121
122    sc_uint<3> d3 = sc_dt::uint_type( -1 );
123    cout << endl;
124    cout << and_reduce( d3 ) << endl;
125    cout << xor_reduce( d3 ) << endl;
126
127    sc_int<6> e;
128    sc_uint<6> f;
129    cout << endl;
130    for( int i = 0; i >= -10; -- i ) {
131        e = i;
132        f = i;
133        cout << xor_reduce( e ) << endl;
134        cout << xor_reduce( f ) << endl;
135    }
136
137    return 0;
138}
139