balancing.cpp revision 12855:588919e0e4aa
16019SN/A/*****************************************************************************
26019SN/A
37102SN/A  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
47102SN/A  more contributor license agreements.  See the NOTICE file distributed
57102SN/A  with this work for additional information regarding copyright ownership.
67102SN/A  Accellera licenses this file to you under the Apache License, Version 2.0
77102SN/A  (the "License"); you may not use this file except in compliance with the
87102SN/A  License.  You may obtain a copy of the License at
97102SN/A
107102SN/A    http://www.apache.org/licenses/LICENSE-2.0
117102SN/A
127102SN/A  Unless required by applicable law or agreed to in writing, software
137102SN/A  distributed under the License is distributed on an "AS IS" BASIS,
147102SN/A  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
156019SN/A  implied.  See the License for the specific language governing
166019SN/A  permissions and limitations under the License.
176019SN/A
186019SN/A *****************************************************************************/
196019SN/A
206019SN/A/*****************************************************************************
216019SN/A
226019SN/A  balancing.cpp --
236019SN/A
246019SN/A  Original Author: Rocco Jonack, Synopsys, Inc., 1999-10-25
256019SN/A
266019SN/A *****************************************************************************/
276019SN/A
286019SN/A/*****************************************************************************
296019SN/A
306019SN/A  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
316019SN/A  changes you are making here.
326019SN/A
336019SN/A      Name, Affiliation, Date:
346019SN/A  Description of Modification:
356019SN/A
366019SN/A *****************************************************************************/
376019SN/A
386019SN/A
396019SN/A#include "balancing.h"
406019SN/A
416019SN/A
426019SN/Avoid balancing::entry(){
436019SN/A
446019SN/A  sc_biguint<4>   tmp1;
456019SN/A  sc_bigint<4>    tmp2;
466019SN/A  sc_biguint<4>   tmp3;
476019SN/A  unsigned int             tmpint;
486019SN/A  sc_unsigned     out_tmp2(12);
496019SN/A  sc_unsigned     out_tmp3(12);
506019SN/A
516019SN/A  // reset_loop
526310SN/A    if (reset.read() == true) {
537191Sgblack@eecs.umich.edu      out_value1.write(0);
547191Sgblack@eecs.umich.edu      out_value2.write(0);
557191Sgblack@eecs.umich.edu      out_value3.write(0);
566268SN/A      out_valid1.write(false);
576268SN/A      out_valid2.write(false);
586268SN/A      out_valid3.write(false);
596268SN/A      out_tmp2 = 0;
607161Sgblack@eecs.umich.edu      out_tmp3 = 0;
617206Sgblack@eecs.umich.edu      wait();
626019SN/A    } else wait();
637129Sgblack@eecs.umich.edu
646019SN/A  //
656268SN/A  // main loop
667139Sgblack@eecs.umich.edu  //
677161Sgblack@eecs.umich.edu  while(1) {
687161Sgblack@eecs.umich.edu    do { wait(); } while  (in_valid == false);
697203Sgblack@eecs.umich.edu
707344SAli.Saidi@ARM.com    //reading inputs
717344SAli.Saidi@ARM.com    tmp1 = in_value1.read();
727161Sgblack@eecs.umich.edu
737161Sgblack@eecs.umich.edu    //easy, just a bunch of different waits
747161Sgblack@eecs.umich.edu    out_valid1.write(true);
757195Sgblack@eecs.umich.edu    tmpint = tmp1.to_uint();
767401SAli.Saidi@ARM.com    switch (tmpint) {
776268SN/A    case 4 :
787161Sgblack@eecs.umich.edu      wait();
796268SN/A      wait();
806268SN/A      wait();
816268SN/A      wait();
826268SN/A      out_value1.write(3);
837139Sgblack@eecs.umich.edu      wait();
847418Sgblack@eecs.umich.edu    case 3 :
856268SN/A      out_value1.write(2);
867120Sgblack@eecs.umich.edu      wait();
876268SN/A      wait();
887120Sgblack@eecs.umich.edu      wait();
897161Sgblack@eecs.umich.edu    case 2 :
907194Sgblack@eecs.umich.edu      out_value1.write(1);
917210Sgblack@eecs.umich.edu      wait();
927161Sgblack@eecs.umich.edu      wait();
937255Sgblack@eecs.umich.edu    default :
946269SN/A      out_value1.write(tmp1);
956268SN/A      wait();
967134Sgblack@eecs.umich.edu    };
976268SN/A    out_valid1.write(false);
987152Sgblack@eecs.umich.edu    wait();
997152Sgblack@eecs.umich.edu
1006268SN/A    //the first branch should be pushed out in latency due to long delay
1016268SN/A    tmp2 = in_value2.read();
1027334Sgblack@eecs.umich.edu    tmp1 = tmp2;
1036268SN/A    out_valid2.write(true);
1046268SN/A    wait();
1056743SN/A    tmpint = tmp1.to_uint();
1066743SN/A    switch (tmpint) {
1077363Sgblack@eecs.umich.edu    case 0 :
1086743SN/A    case 1 :
1096743SN/A    case 2 :
1107321Sgblack@eecs.umich.edu    case 3 :
1117269Sgblack@eecs.umich.edu      //long operation should extent latency
1126743SN/A      out_tmp2 = tmp2*tmp2*tmp2;
1136743SN/A      wait();
1146743SN/A    case 4 :
1157199Sgblack@eecs.umich.edu    case 5 :
1166743SN/A    case 6 :
1176743SN/A    case 7 :
1186268SN/A      //short operation should not extent latency
1196268SN/A      out_tmp2 = 4;
1207191Sgblack@eecs.umich.edu      wait();
1216019SN/A    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