balancing.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  balancing.cpp --
23
24  Original Author: Rocco Jonack, Synopsys, Inc., 1999-10-25
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
39#include "balancing.h"
40
41
42void balancing::entry(){
43
44  sc_biguint<4>   tmp1;
45  sc_bigint<4>    tmp2;
46  sc_biguint<4>   tmp3;
47  unsigned int             tmpint;
48  sc_unsigned     out_tmp2(12);
49  sc_unsigned     out_tmp3(12);
50
51  // reset_loop
52    if (reset.read() == true) {
53      out_value1.write(0);
54      out_value2.write(0);
55      out_value3.write(0);
56      out_valid1.write(false);
57      out_valid2.write(false);
58      out_valid3.write(false);
59      out_tmp2 = 0;
60      out_tmp3 = 0;
61      wait();
62    } else wait();
63
64  //
65  // main loop
66  //
67  while(1) {
68    do { wait(); } while  (in_valid == false);
69
70    //reading inputs
71    tmp1 = in_value1.read();
72
73    //easy, just a bunch of different waits
74    out_valid1.write(true);
75    tmpint = tmp1.to_uint();
76    switch (tmpint) {
77    case 4 :
78      wait();
79      wait();
80      wait();
81      wait();
82      out_value1.write(3);
83      wait();
84    case 3 :
85      out_value1.write(2);
86      wait();
87      wait();
88      wait();
89    case 2 :
90      out_value1.write(1);
91      wait();
92      wait();
93    default :
94      out_value1.write(tmp1);
95      wait();
96    };
97    out_valid1.write(false);
98    wait();
99
100    //the first branch should be pushed out in latency due to long delay
101    tmp2 = in_value2.read();
102    tmp1 = tmp2;
103    out_valid2.write(true);
104    wait();
105    tmpint = tmp1.to_uint();
106    switch (tmpint) {
107    case 0 :
108    case 1 :
109    case 2 :
110    case 3 :
111      //long operation should extent latency
112      out_tmp2 = tmp2*tmp2*tmp2;
113      wait();
114    case 4 :
115    case 5 :
116    case 6 :
117    case 7 :
118      //short operation should not extent latency
119      out_tmp2 = 4;
120      wait();
121    case 8 | 9 | 10 | 11:
122      //wait statements should extent latency
123      out_tmp2 = 1;
124      wait();
125      wait();
126      wait();
127    };
128    wait();
129
130    out_value2.write( sc_biguint<4>( out_tmp2 ) );
131    out_valid2.write(false);
132    wait();
133
134    //the first branch should be pushed out in latency due to long delay
135    tmp3 = in_value3.read();
136    out_valid3.write(true);
137    wait();
138    tmpint = tmp3.to_uint();
139    switch (tmpint) {
140    case 0 :
141    case 1 :
142    case 2 :
143    case 3 :
144      //long operation should extent latency
145      out_tmp2 = tmp2*tmp2*tmp2;
146      wait();
147    case 4 :
148    case 5 :
149    case 6 :
150    case 7 :
151      //short operation should not extent latency
152      out_tmp2 = 4;
153    case 8 :
154    case 9 :
155    case 10 :
156    case 11 :
157      //wait statements should extent latency
158      out_tmp2 = 1;
159      wait();
160      wait();
161      wait();
162    };
163    wait();
164    out_value3.write( sc_biguint<4>( out_tmp3 ) );
165    wait();
166    out_valid3.write(false);
167  }
168}
169
170// EOF
171
172