-
Notifications
You must be signed in to change notification settings - Fork 0
/
electronicmesh_xy_routingpolicy.cpp
59 lines (49 loc) · 1.71 KB
/
electronicmesh_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
/*
* electronicmesh_xy_routingpolicy.cpp
* PhoenixSim
*
* Created by Johnnie Chan on 6/24/11.
* Copyright 2011 Johnnie Chan. All rights reserved.
*
*/
#include "electronicmesh_xy_routingpolicy.h"
using namespace std;
using namespace PhoenixSim;
void ElectronicMesh_XY_RoutingPolicy::SetRoutingParameters(RoutingParameters *p_parameters)
{
ElectronicMesh_XY_RoutingParameters* parameters = static_cast<ElectronicMesh_XY_RoutingParameters*>(p_parameters);
routingParameters.routerId = parameters->routerId;
routingParameters.networkSizeX = parameters->networkSizeX;
routingParameters.networkSizeY = parameters->networkSizeY;
}
pair<int, int> ElectronicMesh_XY_RoutingPolicy::Route(ElectronicMessage* currentMessage, int inputPort, int inputVirtualChannel, const std::vector<int> &routerCredits)
{
// This routing policy implements vanilla dimension ordered routing for a 2-D mesh.
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;
if(destinationX < routerLocationX)
{
return make_pair(3,0);
}
else if(destinationX > routerLocationX)
{
return make_pair(1,0);
}
else // destinationX == routerLocationX
{
if(destinationY < routerLocationY)
{
return make_pair(0,0);
}
else if(destinationY > routerLocationY)
{
return make_pair(2,0);
}
else // destinationY == routerLocationY
{
return make_pair(4 + currentMessage->destinationAddress.GetAddress(0),0);
}
}
}