actlib_dataflow_neuro/dataflow_neuro/treegates.act

289 lines
8.0 KiB
Plaintext
Raw Normal View History

2022-02-21 15:54:10 +01:00
/*************************************************************************
*
* This file is part of ACT dataflow neuro library
*
* Copyright (c) 2022 University of Groningen - Ole Richter
* Copyright (c) 2021 Rajit Manohar
*
* This source describes Open Hardware and is licensed under the CERN-OHL-W v2 or later
*
* You may redistribute and modify this documentation and make products
* using it under the terms of the CERN-OHL-W v2 (https:/cern.ch/cern-ohl).
* This documentation is distributed WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY, INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY
* AND FITNESS FOR A PARTICULAR PURPOSE. Please see the CERN-OHL-W v2
* for applicable conditions.
*
* Source location: https://git.web.rug.nl/bics/actlib_dataflow_neuro
*
* As per CERN-OHL-W v2 section 4.1, should You produce hardware based on
* these sources, You must maintain the Source Location visible in its
* documentation.
*
2022-02-21 16:44:08 +01:00
**************************************************************************/
import "../../dataflow_neuro/cell_lib_async.act";
import "../../dataflow_neuro/cell_lib_std.act";
2022-02-22 18:04:21 +01:00
import std::channel;
open std::channel;
2022-02-21 16:44:08 +01:00
namespace tmpl {
namespace dataflow_neuro {
2022-02-21 15:54:10 +01:00
/*
* Build an OR-gate tree (NOR/NAND/optional INV)
*/
2022-02-21 16:44:08 +01:00
export deftype power (bool?! vdd, vss) { }
2022-02-21 16:59:47 +01:00
2022-02-21 17:59:41 +01:00
export template<pint N>
defproc ortree (bool? in[N]; bool! out; power supply)
2022-02-21 15:54:10 +01:00
{
bool tout;
{ N > 0 : "What?" };
pint i, end, j;
i = 0;
end = N-1;
2022-02-21 16:59:47 +01:00
pint lenTree2Count, lenTree3Count;
2022-02-21 18:27:41 +01:00
lenTree2Count = 0;
lenTree3Count = 0;
/* Pre"calculate" the number of C cells required, look below if confused */
2022-02-21 16:59:47 +01:00
*[ i != end ->
j = 0;
*[ i < end ->
j = j + 1;
[ i+1 >= end ->
i = end;
lenTree2Count = lenTree2Count +1;
[] i+2 >= end ->
i = end;
lenTree3Count = lenTree3Count +1;
[] else ->
i = i + 2;
lenTree2Count = lenTree2Count +1;
]
]
/*-- update range that has to be combined --*/
i = end+1;
end = end+j;
j = 0;
]
/* array that holds ALL the nodes in the completion tree */
2022-02-21 18:27:41 +01:00
bool tmp[end+1];
2022-02-21 15:54:10 +01:00
(k:N:tmp[k] = in[k];)
2022-02-21 16:59:47 +01:00
/* array to hold the actual C-elments, either A2C or A3C */
OR2_X1 C2Els[lenTree2Count];
OR3_X1 C3Els[lenTree3Count];
2022-02-21 17:59:41 +01:00
(h:lenTree2Count:C2Els[h].vdd = supply.vdd;)
(h:lenTree3Count:C3Els[h].vdd = supply.vdd;)
(h:lenTree2Count:C2Els[h].vss = supply.vss;)
(h:lenTree3Count:C3Els[h].vss = supply.vss;)
2022-02-21 16:59:47 +01:00
/* Reset the variables we just stole lol */
i = 0;
end = N-1;
j = 0;
pint tree2Index = 0;
pint tree3Index = 0;
2022-02-21 15:54:10 +01:00
/* 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;
2022-02-21 16:59:47 +01:00
[ i+1 >= end ->
/*-- last piece: use either a 2 input C-element --*/
2022-02-21 18:27:41 +01:00
C2Els[tree2Index].a = tmp[i];
C2Els[tree2Index].b = tmp[i+1];
2022-02-21 16:59:47 +01:00
C2Els[tree2Index].y = tmp[end+j];
tree2Index = tree2Index +1;
i = end;
[] i+2 >= end ->
/*-- last piece: use either a 3 input C-element --*/
2022-02-21 18:27:41 +01:00
C3Els[tree3Index].a = tmp[i];
C3Els[tree3Index].b = tmp[i+1];
C3Els[tree3Index].c = tmp[i+2];
2022-02-21 16:59:47 +01:00
C3Els[tree3Index].y = tmp[end+j];
tree3Index = tree3Index +1;
2022-02-21 15:54:10 +01:00
i = end;
[] else ->
/*-- more to come; so use a two input C-element --*/
2022-02-21 18:27:41 +01:00
C2Els[tree2Index].a = tmp[i];
C2Els[tree2Index].b = tmp[i+1];
2022-02-21 16:59:47 +01:00
C2Els[tree2Index].y = tmp[end+j];
tree2Index = tree2Index +1;
2022-02-21 15:54:10 +01:00
i = i + 2;
]
]
/*-- update range that has to be combined --*/
i = end+1;
end = end+j;
j = 0;
]
out = tmp[end];
2022-02-21 15:54:10 +01:00
}
/*
* Build a completion tree using a combination of 2-input and 3-input
* C-elements
*/
2022-02-21 17:59:41 +01:00
export template<pint N>
2022-02-22 18:04:21 +01:00
defproc ctree (std::data::Mx1of2?<N> in; bool! out; power supply)
2022-02-21 15:54:10 +01:00
{
bool tout;
{ N > 0 : "What?" };
pint i, end, j;
i = 0;
end = N-1;
pint lenTree2Count, lenTree3Count;
lenTree2Count = 0;
lenTree3Count = 0;
2022-02-21 15:54:10 +01:00
/* Pre"calculate" the number of C cells required, look below if confused */
*[ i != end ->
j = 0;
*[ i < end ->
j = j + 1;
[ i+1 >= end ->
i = end;
lenTree2Count = lenTree2Count +1;
[] i+2 >= end ->
i = end;
lenTree3Count = lenTree3Count +1;
[] else ->
i = i + 2;
lenTree2Count = lenTree2Count +1;
]
]
/*-- update range that has to be combined --*/
i = end+1;
end = end+j;
]
/* array that holds ALL the nodes in the completion tree */
2022-02-21 18:27:41 +01:00
bool tmp[end+1];
2022-02-22 18:04:21 +01:00
// OR layer for making OR between true and false of in (they are then sent to Ctree)
OR2_X1 OR2_tf[N];
(l:N:
OR2_tf[l].a = in.d[l].t;
OR2_tf[l].b = in.d[l].f;
OR2_tf[l].y = tmp[l];
// OR2_tf[i].a = supply.vdd;
// OR2_tf[i].b = supply.vdd;
// OR2_tf[i].y = supply.vdd;
OR2_tf[l].vdd = supply.vdd;
OR2_tf[l].vss = supply.vss;
)
//(k:N:tmp[k] = in[k];)
2022-02-21 15:54:10 +01:00
/* array to hold the actual C-elments, either A2C or A3C */
A_2C_B_X1 C2Els[lenTree2Count];
A_3C_B_X1 C3Els[lenTree3Count];
2022-02-21 17:59:41 +01:00
(h:lenTree2Count:C2Els[h].vdd = supply.vdd;)
(h:lenTree3Count:C3Els[h].vdd = supply.vdd;)
(h:lenTree2Count:C2Els[h].vss = supply.vss;)
(h:lenTree3Count:C3Els[h].vss = supply.vss;)
2022-02-21 15:54:10 +01:00
/* Reset the variables we just stole lol */
i = 0;
end = N-1;
j = 0;
pint tree2Index = 0;
pint tree3Index = 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+1 >= end ->
/*-- last piece: use either a 2 input C-element --*/
2022-02-21 16:44:08 +01:00
C2Els[tree2Index].c1 = tmp[i];
C2Els[tree2Index].c2 = tmp[i+1];
C2Els[tree2Index].y = tmp[end+j];
2022-02-21 15:54:10 +01:00
tree2Index = tree2Index +1;
i = end;
[] i+2 >= end ->
/*-- last piece: use either a 3 input C-element --*/
2022-02-21 16:44:08 +01:00
C3Els[tree3Index].c1 = tmp[i];
C3Els[tree3Index].c2 = tmp[i+1];
C3Els[tree3Index].c3 = tmp[i+2];
C3Els[tree3Index].y = tmp[end+j];
2022-02-21 15:54:10 +01:00
tree3Index = tree3Index +1;
i = end;
[] else ->
/*-- more to come; so use a two input C-element --*/
2022-02-21 16:44:08 +01:00
C2Els[tree2Index].c1 = tmp[i];
C2Els[tree2Index].c2 = tmp[i+1];
C2Els[tree2Index].y = tmp[end+j];
2022-02-21 15:54:10 +01:00
tree2Index = tree2Index +1;
i = i + 2;
]
]
/*-- update range that has to be combined --*/
i = end+1;
end = end+j;
j = 0;
]
out = tmp[end];
2022-02-21 15:54:10 +01:00
}
export template<pint N>
2022-02-22 13:52:54 +01:00
defproc sigbuf (bool? in; bool! out[N]; power supply)
2022-02-21 15:54:10 +01:00
{
{ N >= 0 : "sigbuf: parameter error" };
{ N <= 43 : "sigbuf: parameter error, N too big" };
2022-02-22 13:52:54 +01:00
/* -- just use in sized driver here -- */
[ N <= 4 ->
BUF_X1 buf1 (.a = in, .y = out[0], .vdd = supply.vdd, .vss = supply.vss);
[] N >= 5 & N <= 7 ->
BUF_X2 buf2 (.a = in, .y = out[0], .vdd = supply.vdd, .vss = supply.vss);
[] N >= 8 & N <= 10 ->
BUF_X3 buf3 (.a = in, .y = out[0], .vdd = supply.vdd, .vss = supply.vss);
2022-02-21 15:54:10 +01:00
[] N >= 11 & N <= 14 ->
2022-02-22 13:52:54 +01:00
BUF_X4 buf4 (.a = in, .y = out[0], .vdd = supply.vdd, .vss = supply.vss);
2022-02-21 15:54:10 +01:00
[] N >= 15 & N <= 18 ->
2022-02-22 13:52:54 +01:00
BUF_X6 buf6 (.a = in, .y = out[0], .vdd = supply.vdd, .vss = supply.vss);
2022-02-21 15:54:10 +01:00
[] N >= 19 & N <= 29 ->
2022-02-22 13:52:54 +01:00
BUF_X8 buf8 (.a = in, .y = out[0], .vdd = supply.vdd, .vss = supply.vss);
2022-02-21 15:54:10 +01:00
[] N >= 30 & N <= 42 ->
2022-02-22 13:52:54 +01:00
BUF_X12 buf12 (.a = in, .y = out[0], .vdd = supply.vdd, .vss = supply.vss);
2022-02-21 15:54:10 +01:00
]
2022-02-22 18:04:21 +01:00
(i:1..N-1:out[i]=out[0];)
2022-02-21 15:54:10 +01:00
}
2022-02-21 16:44:08 +01:00
}}
2022-02-21 15:54:10 +01:00