-
Notifications
You must be signed in to change notification settings - Fork 0
/
electronicfoldedtorus_xy_routingpolicy.cpp
89 lines (72 loc) · 2.76 KB
/
electronicfoldedtorus_xy_routingpolicy.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* electronicfoldedtorus_xy_routingpolicy.cpp
* PhoenixSim
*
* Created by Johnnie Chan on 7/5/11.
* Copyright 2011 Johnnie Chan. All rights reserved.
*
*/
#include "electronicfoldedtorus_xy_routingpolicy.h"
using namespace std;
using namespace PhoenixSim;
void ElectronicFoldedTorus_XY_RoutingPolicy::SetRoutingParameters(RoutingParameters *p_parameters)
{
ElectronicFoldedTorus_XY_RoutingParameters* parameters = static_cast<ElectronicFoldedTorus_XY_RoutingParameters*>(p_parameters);
routingParameters.maxPacketSizeInCredits = parameters->maxPacketSizeInCredits;
routingParameters.numOfVirtualChannels = parameters->numOfVirtualChannels;
routingParameters.routerId = parameters->routerId;
routingParameters.networkSizeX = parameters->networkSizeX;
routingParameters.networkSizeY = parameters->networkSizeY;
routingParameters.bufferWidth = parameters->bufferWidth;
}
pair<int, int> ElectronicFoldedTorus_XY_RoutingPolicy::Route(ElectronicMessage* currentMessage, int inputPort, int inputVirtualChannel, const vector<int> &routerCredits)
{
int routerLocationX = routingParameters.routerId % routingParameters.networkSizeX;
int routerLocationY = routingParameters.routerId / routingParameters.networkSizeX;
int destinationX = currentMessage->destinationAddress.GetAddress(1) % routingParameters.networkSizeX;
int destinationY = currentMessage->destinationAddress.GetAddress(1) / routingParameters.networkSizeX;
int leftDistance = (routerLocationX + routingParameters.networkSizeX - destinationX) % routingParameters.networkSizeX;
int rightDistance = (destinationX + routingParameters.networkSizeX - routerLocationX) % routingParameters.networkSizeX;
int upDistance = (routerLocationY + routingParameters.networkSizeY - destinationY) % routingParameters.networkSizeY;
int downDistance = (destinationY + routingParameters.networkSizeY - routerLocationY) % routingParameters.networkSizeY;
int outputPort = -1;
int outputVirtualChannel = 0;
if(destinationX == routerLocationX)
{
if(destinationY == routerLocationY)
{
outputPort = 4 + currentMessage->destinationAddress.GetAddress(0);
}
else
{
if(upDistance < downDistance)
{
outputPort = 0;
}
else // upDistance >= downDistance
{
outputPort = 2;
}
}
}
else
{
if(leftDistance < rightDistance)
{
outputPort = 3;
}
else // leftDistance >= rightDistance
{
outputPort = 1;
}
}
// ensure bubble for dimension changes
if(inputPort >= 4 || ((inputPort == 1 || inputPort == 3) && (outputPort == 0 || outputPort == 2)))
{
if(routerCredits[outputPort] - ceil(currentMessage->messageSize / double(routingParameters.bufferWidth)) < routingParameters.maxPacketSizeInCredits)
{
outputPort = -1;
}
}
return make_pair(outputPort, outputVirtualChannel);
}