summaryrefslogtreecommitdiff
path: root/src/intersim/router.cpp
blob: 6a750a60eb0e66c6acace37e6dd65b3c05adb48f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "booksim.hpp"

#include <iostream>
#include <assert.h>

#include "router.hpp"
#include "iq_router.hpp"
#include "event_router.hpp"

Router::Router( const Configuration& config,
                Module *parent, string name, int id,
                int inputs, int outputs ) :
Module( parent, name ),
_id( id ),
_inputs( inputs ),
_outputs( outputs )
{
   _routing_delay    = config.GetInt( "routing_delay" );
   _vc_alloc_delay   = config.GetInt( "vc_alloc_delay" );
   _sw_alloc_delay   = config.GetInt( "sw_alloc_delay" );
   _st_prepare_delay = config.GetInt( "st_prepare_delay" );
   _st_final_delay   = config.GetInt( "st_final_delay" );
   _credit_delay     = config.GetInt( "credit_delay" );
   _input_speedup    = config.GetInt( "input_speedup" );
   _output_speedup   = config.GetInt( "output_speedup" );

   _input_channels = new vector<Flit **>;
   _input_credits  = new vector<Credit **>;

   _output_channels = new vector<Flit **>;
   _output_credits  = new vector<Credit **>;

   _channel_faults  = new vector<bool>;
}

Router::~Router( )
{
   delete _input_channels;
   delete _input_credits;
   delete _output_channels;
   delete _output_credits;
   delete _channel_faults;
}

Credit *Router::_NewCredit( int vcs )
{
   Credit *c;

   c = new Credit( vcs );
   return c;
}

void Router::_RetireCredit( Credit *c )
{
   delete c;
}

void Router::AddInputChannel( Flit **channel, Credit **backchannel )
{
   _input_channels->push_back( channel );
   _input_credits->push_back( backchannel );
}

void Router::AddOutputChannel( Flit **channel, Credit **backchannel )
{
   _output_channels->push_back( channel );
   _output_credits->push_back( backchannel );
   _channel_faults->push_back( false );
}

int Router::GetID( ) const
{
   return _id;
}

void Router::OutChannelFault( int c, bool fault )
{
   assert( ( c >= 0 ) && ( c < (int)_channel_faults->size( ) ) );

   (*_channel_faults)[c] = fault;
}

bool Router::IsFaultyOutput( int c ) const
{
   assert( ( c >= 0 ) && ( c < (int)_channel_faults->size( ) ) );

   return(*_channel_faults)[c];
}

Router *Router::NewRouter( const Configuration& config,
                           Module *parent, string name, int id,
                           int inputs, int outputs )
{
   Router *r;
   string type;

   config.GetStr( "router", type );

   if ( type == "iq" ) {
      r = new IQRouter( config, parent, name, id, inputs, outputs );
   } else if ( type == "event" ) {
      r = new EventRouter( config, parent, name, id, inputs, outputs );
   } else {
      cout << "Unknown router type " << type << endl;
   }

   return r;
}