datawidth_int.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  datawidth_int.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#include "datawidth.h"
39#include "stimgen.h"
40
41                /*******************************************/
42                /* Implementation Filename:  datawidth.cc  */
43                /*******************************************/
44
45void
46datawidth::entry()
47{
48  int 	tmp_a;
49  int	tmp_b;
50  int  	tmp_result;
51
52  while (true) {
53
54    // HANDSHAKING
55    do { wait(); } while (ready == 0);
56
57    // COMPUTATION
58    tmp_a = in1.read();
59    tmp_b = in2.read();
60    tmp_result = tmp_a + tmp_b;
61
62    // WRITE OUTPUT
63    result.write(tmp_result);		// result = in1 + in2
64    wait();
65  }
66}
67                /*****************************************/
68                /* Implementation Filename:  stimgen.cc  */
69                /*****************************************/
70
71void
72stimgen::entry()
73{
74  int i;
75  int j;
76
77  ready.write(0);
78
79  for (i = 0; i < 64; i++) {		// integer in1 (6 bits of data)
80    for (j = 0; j < 64; j++) {		// integer in2 (6 bits of data)
81      in1.write(i);
82      in2.write(j);
83      ready.write(1);
84      wait();
85
86      ready.write(0);
87      wait();
88
89      cout << in1.read() << " + " << in2.read()
90	   << " = " << result.read() << endl;
91    }
92  }
93
94  sc_stop();
95}
96
97                /***************************************/
98                /* Main Filename:       main.cc        */
99                /***************************************/
100		/*				       */
101		/*	int = int + int		       */
102                /*                                     */
103                /*      Max addition is 63 + 63        */
104		/*				       */
105                /***************************************/
106
107int
108sc_main(int ac, char *av[])
109{
110
111// Signal Instantiation
112  sc_signal<int>   	  in1 		("in1");
113  sc_signal<int>   	  in2		("in2");
114  sc_signal<int>   	  result 	("result");
115  sc_signal<bool> 	  ready 	("ready");
116
117// Clock Instantiation
118  sc_clock clk( "clock", 10, SC_NS, 0.5, 0, SC_NS);
119
120// Process Instantiation
121  datawidth	D1 ("D1", clk, in1, in2, ready, result);
122
123  stimgen	T1 ("T1", clk, result, in1, in2, ready);
124
125// Simulation Run Control
126  sc_start();
127  return 0;
128}
129