arbiter init with or2s

This commit is contained in:
alexmadison 2022-03-03 10:52:29 +01:00
parent 7f40b48b49
commit d0a2fff096
1 changed files with 112 additions and 0 deletions

View File

@ -416,5 +416,117 @@ defproc sigbuf (bool? in; bool! out[N]; power supply)
]
(i:1..N-1:out[i]=out[0];)
}
/*
* Build a completion tree using a combination of 2-input and 3-input
* arbiters
*/
export template<pint N>
defproc arbtree (bool? in[N]; bool! out; power supply)
{
bool tout;
{ N > 0 : "What?" };
pint i, end, j;
i = 0;
end = N-1;
pint arbCount;
arbCount = 0;
/* Pre"calculate" the number of C cells required, look below if confused */
*[ i != end ->
j = 0;
*[ i <= end ->
j = j + 1;
[i = end ->
i = end+1;
[] i+1 = end ->
i = end+1;
arbCount = arbCount +1;
[] else ->
i = i + 2;
arbCount = arbCount +1;
]
]
/*-- update range that has to be combined --*/
// i = end+1;
end = end+j;
]
/* array that holds ALL the nodes in the completion tree */
bool tmp[end+1];
// Connecting the first nodes to the input
(l:N:
tmp[l] = in[l];
)
/* array to hold the actual C-elments, either A2C or A3C */
[arbCount > 0 ->
OR2_X1 arbs[arbCount];
]
(h:arbCount:arbs[h].vdd = supply.vdd;)
(h:arbCount:arbs[h].vss = supply.vss;)
/* Reset the variables we just stole lol */
i = 0;
end = N-1;
j = 0;
pint arbIndex = 0;
/* Invariant: i <= end */
*[ i != end ->
/*
* Invariant: tmp[i..end] has the current signals that need to be
* combined together, and "isinv" specifies if they are the inverted
* sense or not
*/
j = 0;
*[ i <= end ->
/*-- there are still signals that need to be combined --*/
j = j + 1;
[ i = end ->
/*-- last piece: pipe input through to next layer --*/
tmp[end+j] = tmp[i];
i = end+1;
[] i+1 = end ->
/*-- last piece: use either a 2 input C-element --*/
arbs[arbIndex].a = tmp[i];
arbs[arbIndex].b = tmp[i+1];
arbs[arbIndex].y = tmp[end+j];
arbIndex = arbIndex +1;
i = end+1;
[] else ->
/*-- more to come; so use a two input C-element --*/
arbs[arbIndex].a = tmp[i];
arbs[arbIndex].b = tmp[i+1];
arbs[arbIndex].y = tmp[end+j];
arbIndex = arbIndex +1;
i = i + 2;
]
]
/*-- update range that has to be combined --*/
i = end+1;
end = end+j;
j = 0;
]
out = tmp[end];
}
}}