-
Notifications
You must be signed in to change notification settings - Fork 0
/
reservationtable.cpp
75 lines (59 loc) · 1.92 KB
/
reservationtable.cpp
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
/*
* StarSim - the NoC Simulator
*
* (C) 2005-2010 by the University of Catania
* For the complete list of authors refer to file ../doc/AUTHORS.txt
* For the license applied to these sources refer to file ../doc/LICENSE.txt
*
* This file contains the implementation of the switch reservation table
*/
#include "reservationtable.h"
reservationtable::reservationtable()
{
clear();
}
void reservationtable::clear()
{
rtable.resize(DIRECTIONS + 1);
// note that NOT_VALID entries should remain untouched
for (int i = 0; i < DIRECTIONS + 1; i++)
if (rtable[i] != NOT_VALID)
rtable[i] = NOT_RESERVED;
}
bool reservationtable::isAvailable(const int port_out) const
{
assert(port_out >= 0 && port_out < DIRECTIONS + 1);
return ((rtable[port_out] == NOT_RESERVED));
}
void reservationtable::reserve(const int port_in, const int port_out)
{
// reservation of reserved/not valid ports is illegal. Correctness
// should be assured by StarSimReservationTable users
assert(isAvailable(port_out));
// check for previous reservation to be released
int port = getOutputPort(port_in);
if (port != NOT_RESERVED)
release(port);
rtable[port_out] = port_in;
}
void reservationtable::release(const int port_out)
{
assert(port_out >= 0 && port_out < DIRECTIONS + 1);
// there is a valid reservation on port_out
assert(rtable[port_out] >= 0 && rtable[port_out] < DIRECTIONS + 1);
rtable[port_out] = NOT_RESERVED;
}
int reservationtable::getOutputPort(const int port_in) const
{
assert(port_in >= 0 && port_in < DIRECTIONS + 1);
for (int i = 0; i < DIRECTIONS + 1; i++)
if (rtable[i] == port_in)
return i; // port_in reserved outport i
// semantic: port_in currently doesn't reserve any out port
return NOT_RESERVED;
}
// makes port_out no longer available for reservation/release
void reservationtable::invalidate(const int port_out)
{
rtable[port_out] = NOT_VALID;
}