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  fsm.cpp --
2312855Sgabeblack@google.com
2412855Sgabeblack@google.com  Original Author: Rocco Jonack, Synopsys, Inc., 1999-10-25
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
3912855Sgabeblack@google.com#include "fsm.h"
4012855Sgabeblack@google.com
4112855Sgabeblack@google.comvoid fsm::entry(){
4212855Sgabeblack@google.com
4312855Sgabeblack@google.com  sc_biguint<4>   tmp1;
4412855Sgabeblack@google.com  sc_biguint<4>   tmp2;
4512855Sgabeblack@google.com  sc_biguint<4>   tmp3;
4612855Sgabeblack@google.com  sc_unsigned     out_tmp2(12);
4712855Sgabeblack@google.com  sc_unsigned     out_tmp3(12);
4812855Sgabeblack@google.com
4912855Sgabeblack@google.com  // reset_loop
5012855Sgabeblack@google.com  if (reset.read() == true) {
5112855Sgabeblack@google.com    out_value1.write(0);
5212855Sgabeblack@google.com    out_value2.write(0);
5312855Sgabeblack@google.com    out_value3.write(0);
5412855Sgabeblack@google.com    out_valid1.write(false);
5512855Sgabeblack@google.com    out_valid2.write(false);
5612855Sgabeblack@google.com    out_valid3.write(false);
5712855Sgabeblack@google.com    out_tmp3 = 0;
5812855Sgabeblack@google.com    wait();
5912855Sgabeblack@google.com  } else wait();
6012855Sgabeblack@google.com
6112855Sgabeblack@google.com  //
6212855Sgabeblack@google.com  // main loop
6312855Sgabeblack@google.com  //
6412855Sgabeblack@google.com  while(1) {
6512855Sgabeblack@google.com    do { wait(); } while  (in_valid == false);
6612855Sgabeblack@google.com
6712855Sgabeblack@google.com    //reading inputs
6812855Sgabeblack@google.com    tmp1 = in_value1.read();
6912855Sgabeblack@google.com    //easy, just a bunch of different waits
7012855Sgabeblack@google.com    out_valid1.write(true);
7112855Sgabeblack@google.com    wait();
7212855Sgabeblack@google.com    if (tmp1 == 4) {
7312855Sgabeblack@google.com      wait();
7412855Sgabeblack@google.com      wait();
7512855Sgabeblack@google.com      wait();
7612855Sgabeblack@google.com      wait();
7712855Sgabeblack@google.com      out_value1.write(3);
7812855Sgabeblack@google.com      wait();
7912855Sgabeblack@google.com    } else if (tmp1 == 3) {
8012855Sgabeblack@google.com      out_value1.write(2);
8112855Sgabeblack@google.com      wait();
8212855Sgabeblack@google.com      wait();
8312855Sgabeblack@google.com      wait();
8412855Sgabeblack@google.com    } else if (tmp1 == 2) {
8512855Sgabeblack@google.com      out_value1.write(1);
8612855Sgabeblack@google.com      wait();
8712855Sgabeblack@google.com      wait();
8812855Sgabeblack@google.com    } else {
8912855Sgabeblack@google.com      out_value1.write(tmp1);
9012855Sgabeblack@google.com      wait();
9112855Sgabeblack@google.com    };
9212855Sgabeblack@google.com    out_valid1.write(false);
9312855Sgabeblack@google.com    wait();
9412855Sgabeblack@google.com
9512855Sgabeblack@google.com    //the first branch should be pushed out in latency due to long delay
9612855Sgabeblack@google.com    tmp2 = in_value2.read();
9712855Sgabeblack@google.com    out_valid2.write(true);
9812855Sgabeblack@google.com    wait();
9912855Sgabeblack@google.com    if (tmp2<4) {
10012855Sgabeblack@google.com      //long operation should extent latency
10112855Sgabeblack@google.com      out_tmp2 = tmp2*tmp2*tmp2;
10212855Sgabeblack@google.com      wait();
10312855Sgabeblack@google.com    } else if (tmp2<8) {
10412855Sgabeblack@google.com      //short operation should not extent latency
10512855Sgabeblack@google.com      out_tmp2 = 4;
10612855Sgabeblack@google.com      wait();
10712855Sgabeblack@google.com    } else if (tmp2<12) {
10812855Sgabeblack@google.com      //wait statements should extent latency
10912855Sgabeblack@google.com      out_tmp2 = 1;
11012855Sgabeblack@google.com      wait();
11112855Sgabeblack@google.com      wait();
11212855Sgabeblack@google.com      wait();
11312855Sgabeblack@google.com    } else {
11412855Sgabeblack@google.com      wait();
11512855Sgabeblack@google.com    };
11612855Sgabeblack@google.com    wait();
11712855Sgabeblack@google.com
11812855Sgabeblack@google.com    out_value2.write( sc_biguint<4>( out_tmp2 ) );
11912855Sgabeblack@google.com    out_valid2.write(false);
12012855Sgabeblack@google.com    wait();
12112855Sgabeblack@google.com
12212855Sgabeblack@google.com     // if branch without else maybe check later
12312855Sgabeblack@google.com     tmp3 = in_value3.read();
12412855Sgabeblack@google.com     out_valid3.write(true);
12512855Sgabeblack@google.com//     wait();
12612855Sgabeblack@google.com//     if (tmp3<8) {
12712855Sgabeblack@google.com//       out_tmp3 = 4;
12812855Sgabeblack@google.com//       wait();
12912855Sgabeblack@google.com//     }
13012855Sgabeblack@google.com
13112855Sgabeblack@google.com    out_value3.write( sc_biguint<4>( out_tmp3 ) );
13212855Sgabeblack@google.com    wait();
13312855Sgabeblack@google.com    out_valid3.write(false);
13412855Sgabeblack@google.com  }
13512855Sgabeblack@google.com}
13612855Sgabeblack@google.com
13712855Sgabeblack@google.com// EOF
13812855Sgabeblack@google.com
139