diff --git a/dataflow_neuro/coders.act b/dataflow_neuro/coders.act index 9e02382..087fde0 100644 --- a/dataflow_neuro/coders.act +++ b/dataflow_neuro/coders.act @@ -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,38 +234,96 @@ namespace tmpl { } - template - defproc encoder2D(a1of1 x[N]; a1of1 y[M] ;avMx1of2 addr; bool! out_a; power supply) - { - // Arbiters - a1of1 _out_arb_x,_out_arb_y; - a1of1 _x_temp[N]; - (i:N: - _x_temp[i].r = x[i].r; - ) - (i:M: - _y_temp[i].r = y[i].r; - ) - arbtree Xarb(.in = _x_temp,.out = _out_arb_X,.supply = supply); - arbtree Yarb(.in = _y_temp,.out = _out_arb_Y,.supply = supply); - sigbuf x_ack_arb[N]; - sigbuf y_ack_arb[M]; - (i:N: - x_ack_arb[i].in = _x_temp[i].a; - x_ack_arb[i].out[0] = x[i].a; - x_ack_arb[i].supply = supply; - ) - (i:M: - y_ack_arb[i].in = _y_temp[i].a; - y_ack_arb[i].out[0] = y[i].a; - y_ack_arb[i].supply = supply; - ) + // Generates the OR-trees required to go from + // N one-hot inputs to Nc dual rail binary encoding. + export template + defproc encoder(bool? in[N]; Mx1of2 out; power supply) { + {N <= 1< 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 + // defproc encoder2D(a1of1 x[N]; a1of1 y[M] ;avMx1of2 addr; bool! out_a; power supply) + // { + // // Arbiters + // a1of1 _out_arb_x,_out_arb_y; + // a1of1 _x_temp[N]; + // (i:N: + // _x_temp[i].r = x[i].r; + // ) + // (i:M: + // _y_temp[i].r = y[i].r; + // ) + // arbtree Xarb(.in = _x_temp,.out = _out_arb_X,.supply = supply); + // arbtree Yarb(.in = _y_temp,.out = _out_arb_Y,.supply = supply); + + // sigbuf x_ack_arb[N]; + // sigbuf y_ack_arb[M]; + // (i:N: + // x_ack_arb[i].in = _x_temp[i].a; + // x_ack_arb[i].out[0] = x[i].a; + // x_ack_arb[i].supply = supply; + // ) + // (i:M: + // y_ack_arb[i].in = _y_temp[i].a; + // y_ack_arb[i].out[0] = y[i].a; + // y_ack_arb[i].supply = supply; + // ) + + + // } + + } } \ No newline at end of file