Compare commits

...

2 Commits

Author SHA1 Message Date
alexmadison
4a4c4eeb14 merged encoder 2022-03-04 14:27:38 +01:00
alexmadison
f55322bc7c encoder init 2022-03-04 14:10:15 +01:00

View File

@ -34,6 +34,14 @@ import "../../dataflow_neuro/primitives.act";
import std::channel;
open std::channel;
import std::data;
open std::data;
// import dev::channel;
// open dev::channel;
namespace tmpl {
namespace dataflow_neuro {
@ -226,6 +234,56 @@ namespace tmpl {
}
// Generates the OR-trees required to go from
// N one-hot inputs to Nc dual rail binary encoding.
export template<pint Nc, N>
defproc encoder(bool? in[N]; Mx1of2<Nc> out; power supply) {
{N <= 1<<Nc : "Num inputs too wide for encoding channel!"};
// For each output line, need to precalculate how big of an OR tree it needs
// since can't presume that N = 2**Nc
// First version however, just be hella lazy and presume N=2**Nc,
// connect extra nodes to ground (sorry)
pint _N; // N rounded up to a power of 2
_N = (1<<Nc);
ortree<_N/2> ors_t[Nc];
ortree<_N/2> ors_f[Nc];
(i:Nc:ors_t[i].supply = supply; ors_t[i].out = out.d[i].t;)
(i:Nc:ors_f[i].supply = supply; ors_f[i].out = out.d[i].f;)
pint num_connected_t; // Number of guys already connected to the current OR tree
pint num_connected_f;
TIELO_X1 tielo(.vdd = supply.vdd, .vss = supply.vss); // I'm sorry
pint bitval;
(i:0..Nc-1: // For each output line
num_connected_t = 0;
num_connected_f = 0;
(j:0.. _N-1:
bitval = (j & ( 1 << i )) >> i; // Get binary digit of integer j, column i
[bitval = 1 & j <= N-1->
ors_t[i].in[num_connected_t] = in[j];
num_connected_t = num_connected_t + 1;
[] bitval = 0 & j <= N-1->
ors_f[i].in[num_connected_f] = in[j];
num_connected_f = num_connected_f + 1;
[] bitval = 1 & j > N-1->
ors_t[i].in[num_connected_t] = tielo.y;
num_connected_t = num_connected_t + 1;
[] bitval = 0 & j > N-1->
ors_f[i].in[num_connected_f] = tielo.y;
num_connected_f = num_connected_f + 1;
]
)
)
}
template<pint N, pint M,pint address_size, pint ACK_STRENGTH>
defproc encoder2D(a1of1 x[N]; a1of1 y[M] ;avMx1of2<address_size> addr; power supply; bool reset_B) {
// Reset buffers
@ -352,12 +410,10 @@ namespace tmpl {
sigbuf_1output<4> addr_validity_x(.in = _addr_v,.out = addr.v);
addr_validity.supply = supply;
addr_validity_x.supply = supply;
}
}
}
}