112855Sgabeblack@google.com/*****************************************************************************
212855Sgabeblack@google.com
312855Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412855Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512855Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612855Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712855Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812855Sgabeblack@google.com  License.  You may obtain a copy of the License at
912855Sgabeblack@google.com
1012855Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112855Sgabeblack@google.com
1212855Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312855Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412855Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512855Sgabeblack@google.com  implied.  See the License for the specific language governing
1612855Sgabeblack@google.com  permissions and limitations under the License.
1712855Sgabeblack@google.com
1812855Sgabeblack@google.com *****************************************************************************/
1912855Sgabeblack@google.com
2012855Sgabeblack@google.com/*****************************************************************************
2112855Sgabeblack@google.com
2212855Sgabeblack@google.com  disaproc2.cpp --
2312855Sgabeblack@google.com
2412855Sgabeblack@google.com  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
2512855Sgabeblack@google.com
2612855Sgabeblack@google.com *****************************************************************************/
2712855Sgabeblack@google.com
2812855Sgabeblack@google.com/*****************************************************************************
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3112855Sgabeblack@google.com  changes you are making here.
3212855Sgabeblack@google.com
3312855Sgabeblack@google.com      Name, Affiliation, Date:
3412855Sgabeblack@google.com  Description of Modification:
3512855Sgabeblack@google.com
3612855Sgabeblack@google.com *****************************************************************************/
3712855Sgabeblack@google.com
3812855Sgabeblack@google.com#include "systemc.h"
3912855Sgabeblack@google.com
4012855Sgabeblack@google.comtypedef sc_signal<sc_bv<32> > sc_signal_bool_vector;
4112855Sgabeblack@google.com
4212855Sgabeblack@google.comint val1[17] = { 34329, 32492,  1034, 12000,  102, 12981,  1902, 19409,
4312855Sgabeblack@google.com                 10029,  2149, 12030, 20099,   90, 10009,  9345, 57483,
4412855Sgabeblack@google.com                 10903 };
4512855Sgabeblack@google.com
4612855Sgabeblack@google.comint val2[19] = {   239,   923,  1240,   129,  191,   101,  1010,   190,
4712855Sgabeblack@google.com                 19820,  2349, 24039, 34728, 5745, 78234, 17838, 37482,
4812855Sgabeblack@google.com                 17498,  1347,  3721 };
4912855Sgabeblack@google.com
5012855Sgabeblack@google.comSC_MODULE( aproc1 )
5112855Sgabeblack@google.com{
5212855Sgabeblack@google.com    SC_HAS_PROCESS( aproc1 );
5312855Sgabeblack@google.com
5412855Sgabeblack@google.com    const sc_signal_bool_vector& a;
5512855Sgabeblack@google.com    const sc_signal_bool_vector& b;
5612855Sgabeblack@google.com          sc_signal_bool_vector& c;
5712855Sgabeblack@google.com
5812855Sgabeblack@google.com    aproc1( sc_module_name NAME,
5912855Sgabeblack@google.com
6012855Sgabeblack@google.com            const sc_signal_bool_vector& A,
6112855Sgabeblack@google.com            const sc_signal_bool_vector& B,
6212855Sgabeblack@google.com                  sc_signal_bool_vector& C )
6312855Sgabeblack@google.com        : a(A), b(B), c(C)
6412855Sgabeblack@google.com    {
6512855Sgabeblack@google.com        SC_THREAD( entry );
6612855Sgabeblack@google.com        sensitive << a << b;
6712855Sgabeblack@google.com    }
6812855Sgabeblack@google.com    void entry();
6912855Sgabeblack@google.com};
7012855Sgabeblack@google.com
7112855Sgabeblack@google.comvoid
7212855Sgabeblack@google.comaproc1::entry()
7312855Sgabeblack@google.com{
7412855Sgabeblack@google.com    wait();
7512855Sgabeblack@google.com    wait();
7612855Sgabeblack@google.com    c = a.read().to_int() + b.read().to_int();
7712855Sgabeblack@google.com    cout << "c is (a + b)" << endl;
7812855Sgabeblack@google.com    wait();
7912855Sgabeblack@google.com    c = a.read().to_int() - b.read().to_int();
8012855Sgabeblack@google.com    cout << "c is (a - b)" << endl;
8112855Sgabeblack@google.com    wait();
8212855Sgabeblack@google.com    cout << name() << " is exiting." << endl;
8312855Sgabeblack@google.com}
8412855Sgabeblack@google.com
8512855Sgabeblack@google.com
8612855Sgabeblack@google.comSC_MODULE( aproc2 )
8712855Sgabeblack@google.com{
8812855Sgabeblack@google.com    SC_HAS_PROCESS( aproc2 );
8912855Sgabeblack@google.com
9012855Sgabeblack@google.com    const sc_signal_bool_vector& a;
9112855Sgabeblack@google.com    const sc_signal_bool_vector& b;
9212855Sgabeblack@google.com          sc_signal_bool_vector& d;
9312855Sgabeblack@google.com
9412855Sgabeblack@google.com    aproc2( sc_module_name NAME,
9512855Sgabeblack@google.com
9612855Sgabeblack@google.com            const sc_signal_bool_vector& A,
9712855Sgabeblack@google.com            const sc_signal_bool_vector& B,
9812855Sgabeblack@google.com                  sc_signal_bool_vector& D )
9912855Sgabeblack@google.com        : a(A), b(B), d(D)
10012855Sgabeblack@google.com    {
10112855Sgabeblack@google.com        SC_THREAD( entry );
10212855Sgabeblack@google.com        sensitive << a << b;
10312855Sgabeblack@google.com    }
10412855Sgabeblack@google.com    void entry();
10512855Sgabeblack@google.com};
10612855Sgabeblack@google.com
10712855Sgabeblack@google.comvoid
10812855Sgabeblack@google.comaproc2::entry()
10912855Sgabeblack@google.com{
11012855Sgabeblack@google.com    wait();
11112855Sgabeblack@google.com    int loops = 0;
11212855Sgabeblack@google.com    while (true) {
11312855Sgabeblack@google.com        wait();
11412855Sgabeblack@google.com        d = a.read().to_int() * b.read().to_int();
11512855Sgabeblack@google.com        cout << "d is (a * b)" << endl;
11612855Sgabeblack@google.com        wait();
11712855Sgabeblack@google.com        if (b.read().to_int() == 0) {
11812855Sgabeblack@google.com            d = a.read().to_int() / (b.read().to_int() + 1);
11912855Sgabeblack@google.com            cout << "d is (a / (b + 1))" << endl;
12012855Sgabeblack@google.com        } else {
12112855Sgabeblack@google.com            d = a.read().to_int() / b.read().to_int();
12212855Sgabeblack@google.com            cout << "d is (a / b)" << endl;
12312855Sgabeblack@google.com        }
12412855Sgabeblack@google.com        if (loops < 1) {
12512855Sgabeblack@google.com            // for (int i = 0; i < a.length(); ++i) {
12612855Sgabeblack@google.com            //     sc_assert( a[i].sensitive_aprocs_neg.size() == 2 );
12712855Sgabeblack@google.com            //     sc_assert( a[i].sensitive_aprocs.size() == 2 );
12812855Sgabeblack@google.com            // }
12912855Sgabeblack@google.com        }
13012855Sgabeblack@google.com        if (loops > 5) {
13112855Sgabeblack@google.com            // for (int i = 0; i < a.length(); ++i) {
13212855Sgabeblack@google.com            //     /* By this time aproc1 should have died. */
13312855Sgabeblack@google.com            //     sc_assert( a[i].sensitive_aprocs_neg.size() == 1 );
13412855Sgabeblack@google.com            //     sc_assert( a[i].sensitive_aprocs.size() == 1 );
13512855Sgabeblack@google.com            // }
13612855Sgabeblack@google.com        }
13712855Sgabeblack@google.com        loops++;
13812855Sgabeblack@google.com    }
13912855Sgabeblack@google.com}
14012855Sgabeblack@google.com
14112855Sgabeblack@google.comSC_MODULE( sync1 )
14212855Sgabeblack@google.com{
14312855Sgabeblack@google.com    SC_HAS_PROCESS( sync1 );
14412855Sgabeblack@google.com
14512855Sgabeblack@google.com    sc_in_clk clk;
14612855Sgabeblack@google.com
14712855Sgabeblack@google.com          sc_signal_bool_vector& a;
14812855Sgabeblack@google.com          sc_signal_bool_vector& b;
14912855Sgabeblack@google.com    const sc_signal_bool_vector& c;
15012855Sgabeblack@google.com    const sc_signal_bool_vector& d;
15112855Sgabeblack@google.com
15212855Sgabeblack@google.com    int count;
15312855Sgabeblack@google.com    sync1( sc_module_name NAME,
15412855Sgabeblack@google.com           sc_clock& CLK,
15512855Sgabeblack@google.com           sc_signal_bool_vector& A,
15612855Sgabeblack@google.com           sc_signal_bool_vector& B,
15712855Sgabeblack@google.com           const sc_signal_bool_vector& C,
15812855Sgabeblack@google.com           const sc_signal_bool_vector& D )
15912855Sgabeblack@google.com        :
16012855Sgabeblack@google.com          a(A), b(B), c(C), d(D)
16112855Sgabeblack@google.com
16212855Sgabeblack@google.com    {
16312855Sgabeblack@google.com        clk(CLK);
16412855Sgabeblack@google.com		SC_CTHREAD( entry, clk.pos() );
16512855Sgabeblack@google.com        count = 0;
16612855Sgabeblack@google.com    }
16712855Sgabeblack@google.com    void entry();
16812855Sgabeblack@google.com};
16912855Sgabeblack@google.com
17012855Sgabeblack@google.comvoid
17112855Sgabeblack@google.comsync1::entry()
17212855Sgabeblack@google.com{
17312855Sgabeblack@google.com    while (true) {
17412855Sgabeblack@google.com        a = (val1[count % (sizeof(val1)/sizeof(val1[0]))]);
17512855Sgabeblack@google.com        b = (val2[count % (sizeof(val2)/sizeof(val2[0]))]);
17612855Sgabeblack@google.com        count++;
17712855Sgabeblack@google.com        wait();
17812855Sgabeblack@google.com        cout << "  a =  " << a.read().to_int();
17912855Sgabeblack@google.com        cout << "  b =  " << b.read().to_int();
18012855Sgabeblack@google.com        cout << "  c =  " << c.read().to_int();
18112855Sgabeblack@google.com        cout << "  d =  " << d.read().to_int() << endl;
18212855Sgabeblack@google.com    }
18312855Sgabeblack@google.com}
18412855Sgabeblack@google.com
18512855Sgabeblack@google.com
18612855Sgabeblack@google.com
18712855Sgabeblack@google.comint
18812855Sgabeblack@google.comsc_main(int argc, char** argv)
18912855Sgabeblack@google.com{
19012855Sgabeblack@google.com    sc_clock clk("clk");
19112855Sgabeblack@google.com    sc_signal_bool_vector a("a");
19212855Sgabeblack@google.com    sc_signal_bool_vector b("b");
19312855Sgabeblack@google.com    sc_signal_bool_vector c("c");
19412855Sgabeblack@google.com    sc_signal_bool_vector d("d");
19512855Sgabeblack@google.com
19612855Sgabeblack@google.com    a = 0;
19712855Sgabeblack@google.com    b = 0;
19812855Sgabeblack@google.com    c = 0;
19912855Sgabeblack@google.com    d = 0;
20012855Sgabeblack@google.com
20112855Sgabeblack@google.com    aproc1 p1("p1", a, b, c);
20212855Sgabeblack@google.com    aproc2 p2("p2", a, b, d);
20312855Sgabeblack@google.com    sync1  s1("s1", clk, a, b, c, d);
20412855Sgabeblack@google.com
20512855Sgabeblack@google.com    sc_start(2000, SC_NS);
20612855Sgabeblack@google.com    return 0;
20712855Sgabeblack@google.com}
208