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-07-22
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
41void balancing::entry(){
42
43  sc_biguint<4>   tmp1;
44  sc_biguint<4>   tmp2;
45  sc_biguint<4>   tmp3;
46  sc_unsigned     out_tmp2(12);
47  sc_unsigned     out_tmp3(12);
48
49  // reset_loop
50    if (reset.read() == true) {
51      out_value1.write(0);
52      out_value2.write(0);
53      out_value3.write(0);
54      out_valid1.write(false);
55      out_valid2.write(false);
56      out_valid3.write(false);
57      wait();
58    } else wait();
59
60  //
61  // main loop
62  //
63  while(1) {
64    do { wait(); } while  (in_valid == false);
65
66    //reading inputs
67    tmp1 = in_value1.read();
68
69    //easy, just a bunch of different waits
70    out_valid1.write(true);
71    if (tmp1 == 4) {
72      wait();
73      wait();
74      wait();
75      wait();
76      out_value1.write(3);
77      wait();
78    } else if (tmp1 == 3) {
79      out_value1.write(2);
80      wait();
81      wait();
82      wait();
83    } else if (tmp1 == 2) {
84      out_value1.write(1);
85      wait();
86      wait();
87    } else {
88      out_value1.write(tmp1);
89      wait();
90    };
91    out_valid1.write(false);
92    wait();
93
94    //the first branch should be pushed out in latency due to long delay
95    tmp2 = in_value2.read();
96    out_valid2.write(true);
97    wait();
98    if (tmp2<4) {
99      //long operation should extent latency
100      out_tmp2 = tmp2*tmp2*tmp2;
101      wait();
102    } else if (tmp2<8) {
103      //short operation should not extent latency
104      out_tmp2 = 4;
105      wait();
106    } else if (tmp2<12) {
107      //wait statements should extent latency
108      out_tmp2 = 1;
109      wait();
110      wait();
111      wait();
112    };
113    wait();
114
115    out_value2.write( sc_biguint<4>( out_tmp2 ) );
116    out_valid2.write(false);
117    wait();
118
119    //if branch without else
120    tmp3 = in_value3.read();
121    out_valid3.write(true);
122    wait();
123    if (tmp3<8) {
124      out_tmp3 = 4;
125      wait();
126    }
127
128    out_value3.write( sc_biguint<4>( out_tmp3 ) );
129    wait();
130    out_valid3.write(false);
131  }
132}
133
134// EOF
135
136