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  hwsw.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.comstatic int randa[] = { 3278, 3420, 1349, 13491, 9234028, 234902,
4112855Sgabeblack@google.com                       13971, 1498710, 1348179, 1389810, 190101, 92384 };
4212855Sgabeblack@google.comstatic int randb[] = { 1349, 20893, 2090092, 8813, 87472, 73231,
4312855Sgabeblack@google.com                       59413, 42713, 3192, 45653, 565643, 78931, 573231 };
4412855Sgabeblack@google.comstatic int randc[] = { 3419, 82093, 9013, 1831, 74372, 233861,
4512855Sgabeblack@google.com                       421313, 47823, 3902192, 93245653, 77565643, 77234, 10192 };
4612855Sgabeblack@google.com
4712855Sgabeblack@google.comSC_MODULE( adder_sub )
4812855Sgabeblack@google.com{
4912855Sgabeblack@google.com  SC_HAS_PROCESS( adder_sub );
5012855Sgabeblack@google.com
5112855Sgabeblack@google.com  sc_in_clk clk;
5212855Sgabeblack@google.com
5312855Sgabeblack@google.com  sc_fifo<int>& Sa; //input
5412855Sgabeblack@google.com  sc_fifo<int>& Sb; //input
5512855Sgabeblack@google.com  sc_fifo<int>& Sc; //input
5612855Sgabeblack@google.com  sc_fifo<int>& Sd; //output
5712855Sgabeblack@google.com  sc_fifo<int>& Ssum; //output
5812855Sgabeblack@google.com
5912855Sgabeblack@google.com  // constructor
6012855Sgabeblack@google.com  adder_sub( sc_module_name NAME,
6112855Sgabeblack@google.com	     sc_clock& CLK,
6212855Sgabeblack@google.com	     sc_fifo<int>& SA,
6312855Sgabeblack@google.com	     sc_fifo<int>& SB,
6412855Sgabeblack@google.com	     sc_fifo<int>& SC,
6512855Sgabeblack@google.com	     sc_fifo<int>& SD,
6612855Sgabeblack@google.com	     sc_fifo<int>& SSUM )
6712855Sgabeblack@google.com    : Sa(SA), Sb(SB), Sc(SC), Sd(SD), Ssum(SSUM)
6812855Sgabeblack@google.com  {
6912855Sgabeblack@google.com    clk(CLK);
7012855Sgabeblack@google.com	SC_THREAD( entry );
7112855Sgabeblack@google.com	sensitive << clk.pos();
7212855Sgabeblack@google.com  }
7312855Sgabeblack@google.com
7412855Sgabeblack@google.com  // Process functionality in member function below
7512855Sgabeblack@google.com  void entry();
7612855Sgabeblack@google.com};
7712855Sgabeblack@google.com
7812855Sgabeblack@google.com
7912855Sgabeblack@google.comint add(int a, int b)
8012855Sgabeblack@google.com{
8112855Sgabeblack@google.com  return (a + b);
8212855Sgabeblack@google.com}
8312855Sgabeblack@google.com
8412855Sgabeblack@google.comvoid adder_sub::entry()
8512855Sgabeblack@google.com{
8612855Sgabeblack@google.com  int sum;
8712855Sgabeblack@google.com  int a, b, c, d;
8812855Sgabeblack@google.com
8912855Sgabeblack@google.com  while (true) {
9012855Sgabeblack@google.com    // Read inputs
9112855Sgabeblack@google.com    a = Sa.read();
9212855Sgabeblack@google.com    b = Sb.read();
9312855Sgabeblack@google.com    c = Sc.read();
9412855Sgabeblack@google.com
9512855Sgabeblack@google.com    // Perform the computation.
9612855Sgabeblack@google.com    sum = add(a, b);
9712855Sgabeblack@google.com    sum = add(sum, c);
9812855Sgabeblack@google.com    d = a - b;
9912855Sgabeblack@google.com
10012855Sgabeblack@google.com    // Write outputs
10112855Sgabeblack@google.com    Ssum.write(sum);
10212855Sgabeblack@google.com    Sd.write(d);
10312855Sgabeblack@google.com    // Loop back to do { wait(); } while .
10412855Sgabeblack@google.com  }
10512855Sgabeblack@google.com
10612855Sgabeblack@google.com} // end of entry function
10712855Sgabeblack@google.com
10812855Sgabeblack@google.comSC_MODULE( testbench )
10912855Sgabeblack@google.com{
11012855Sgabeblack@google.com  SC_HAS_PROCESS( testbench );
11112855Sgabeblack@google.com
11212855Sgabeblack@google.com  sc_in_clk clk;
11312855Sgabeblack@google.com
11412855Sgabeblack@google.com  sc_fifo<int>& Ssum; //input
11512855Sgabeblack@google.com  sc_fifo<int>& Sdiff; //input
11612855Sgabeblack@google.com  sc_fifo<int>& Sa; //output
11712855Sgabeblack@google.com  sc_fifo<int>& Sb; //output
11812855Sgabeblack@google.com  sc_fifo<int>& Sc; //output
11912855Sgabeblack@google.com
12012855Sgabeblack@google.com  // constructor
12112855Sgabeblack@google.com  testbench( sc_module_name NAME,
12212855Sgabeblack@google.com	     sc_clock& CLK,
12312855Sgabeblack@google.com	     sc_fifo<int>& SSUM,
12412855Sgabeblack@google.com	     sc_fifo<int>& SDIFF,
12512855Sgabeblack@google.com	     sc_fifo<int>& SA,
12612855Sgabeblack@google.com	     sc_fifo<int>& SB,
12712855Sgabeblack@google.com	     sc_fifo<int>& SC )
12812855Sgabeblack@google.com    : Ssum(SSUM), Sdiff(SDIFF), Sa(SA), Sb(SB), Sc(SC)
12912855Sgabeblack@google.com  {
13012855Sgabeblack@google.com    clk(CLK);
13112855Sgabeblack@google.com	SC_THREAD( entry );
13212855Sgabeblack@google.com	sensitive << clk.pos();
13312855Sgabeblack@google.com  }
13412855Sgabeblack@google.com
13512855Sgabeblack@google.com  // Process functionality in member function below
13612855Sgabeblack@google.com  void entry();
13712855Sgabeblack@google.com};
13812855Sgabeblack@google.com
13912855Sgabeblack@google.com
14012855Sgabeblack@google.comvoid testbench::entry()
14112855Sgabeblack@google.com{
14212855Sgabeblack@google.com  int a, b, c, d;
14312855Sgabeblack@google.com  int sum;
14412855Sgabeblack@google.com  int i;
14512855Sgabeblack@google.com  char buf[BUFSIZ];
14612855Sgabeblack@google.com
14712855Sgabeblack@google.com  for (i=0; i < 10; i++) {
14812855Sgabeblack@google.com    a = randa[i % (sizeof(randa)/sizeof(randa[0]))] & 0x0ff;
14912855Sgabeblack@google.com    b = randb[i % (sizeof(randb)/sizeof(randb[0]))] & 0x0ff;
15012855Sgabeblack@google.com    c = randc[i % (sizeof(randc)/sizeof(randc[0]))] & 0x0ff;
15112855Sgabeblack@google.com
15212855Sgabeblack@google.com    Sa.write(a);
15312855Sgabeblack@google.com    Sb.write(b);
15412855Sgabeblack@google.com    Sc.write(c);
15512855Sgabeblack@google.com    sum = Ssum.read();
15612855Sgabeblack@google.com    d = Sdiff.read();
15712855Sgabeblack@google.com    // printf("A = %d, B = %d, C = %d, D = %d, SUM = %d\n", a, b, c, d, sum);
15812855Sgabeblack@google.com    sprintf(buf, "A = %d, B = %d, C = %d, D = %d, SUM = %d\n", a, b, c, d, sum);
15912855Sgabeblack@google.com    cout << buf;
16012855Sgabeblack@google.com  }
16112855Sgabeblack@google.com  sc_stop();
16212855Sgabeblack@google.com
16312855Sgabeblack@google.com} // end of entry function
16412855Sgabeblack@google.com
16512855Sgabeblack@google.com// Main routine
16612855Sgabeblack@google.com
16712855Sgabeblack@google.comint sc_main(int ac, char *av[])
16812855Sgabeblack@google.com{
16912855Sgabeblack@google.com  sc_fifo<int> a;
17012855Sgabeblack@google.com  sc_fifo<int> b;
17112855Sgabeblack@google.com  sc_fifo<int> c;
17212855Sgabeblack@google.com  sc_fifo<int> d;
17312855Sgabeblack@google.com  sc_fifo<int> sum;
17412855Sgabeblack@google.com  sc_clock clock("Clock", 10, SC_NS, 0.5, 0, SC_NS, 0);
17512855Sgabeblack@google.com
17612855Sgabeblack@google.com  testbench T("TB", clock, sum, d, a, b, c);
17712855Sgabeblack@google.com  adder_sub AS("AS", clock, a, b, c, d, sum);
17812855Sgabeblack@google.com
17912855Sgabeblack@google.com  sc_start();
18012855Sgabeblack@google.com  return 0;
18112855Sgabeblack@google.com}
182