blob: c9fab7a3e28e00d33d029aa7410f988e6db2d3a2 (
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
|
#include "booksim.hpp"
#include <iostream>
#include "wavefront.hpp"
#include "random_utils.hpp"
Wavefront::Wavefront( const Configuration &config,
Module *parent, const string& name,
int inputs, int outputs ) :
DenseAllocator( config, parent, name, inputs, outputs )
{
// We need a square wavefront allocator, so take the max dimension
_square = ( _inputs > _outputs ) ? _inputs : _outputs;
// The diagonal with priority
_pri = 0;
}
Wavefront::~Wavefront( )
{
}
void Wavefront::Allocate( )
{
int input;
int output;
// Clear matching
for ( int i = 0; i < _inputs; ++i ) {
_inmatch[i] = -1;
}
for ( int j = 0; j < _outputs; ++j ) {
_outmatch[j] = -1;
}
// Loop through diagonals of request matrix
for ( int p = 0; p < _square; ++p ) {
output = ( _pri + p ) % _square;
// Step through the current diagonal
for ( input = 0; input < _inputs; ++input ) {
if ( ( output < _outputs ) &&
( _inmatch[input] == -1 ) &&
( _outmatch[output] == -1 ) &&
( _request[input][output].label != -1 ) ) {
// Grant!
_inmatch[input] = output;
_outmatch[output] = input;
}
output = ( output + 1 ) % _square;
}
}
// Round-robin the priority diagonal
_pri = ( _pri + 1 ) % _square;
}
|