From d0a2fff0966c6c28508bf06e417b215b9ee89e47 Mon Sep 17 00:00:00 2001 From: alexmadison Date: Thu, 3 Mar 2022 10:52:29 +0100 Subject: [PATCH] arbiter init with or2s --- dataflow_neuro/treegates.act | 112 +++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/dataflow_neuro/treegates.act b/dataflow_neuro/treegates.act index 991d79d..c1e8294 100644 --- a/dataflow_neuro/treegates.act +++ b/dataflow_neuro/treegates.act @@ -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 +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]; + +} + + + + + + }}