Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
intro_example:loops [2022/05/13 13:20] rajitintro_example:loops [2025/05/18 14:51] (current) – [Array, loops and selection] rajit
Line 1: Line 1:
 ====== Array, loops and selection ====== ====== Array, loops and selection ======
 +
 +
  
 Complex datapath designs are often designed with array of simpler cells. The following example show how to create array of simple cells and connect them using loop constructs in ACT. Complex datapath designs are often designed with array of simpler cells. The following example show how to create array of simple cells and connect them using loop constructs in ACT.
Line 85: Line 87:
  
 Depending on the value of index ''i'', input ''x0''/''x1'' are connected to output ''y'' or ''z''. If ''i'' is even, ''x0'' is connected to ''y'' and ''x1'' is connected to ''z''. If ''i'' is odd, ''x0'' is connected to ''z'' and ''x1'' is connected to ''y''. Depending on the value of index ''i'', input ''x0''/''x1'' are connected to output ''y'' or ''z''. If ''i'' is even, ''x0'' is connected to ''y'' and ''x1'' is connected to ''z''. If ''i'' is odd, ''x0'' is connected to ''z'' and ''x1'' is connected to ''y''.
 +
 +====== General loops ======
 +
 +The parenthesis-based syntax is a compact way to describe simple loop-based replication. If a more complex approach is needed, then a generalized while loop syntax is also available. The selection example earlier could also be re-written as follows:
 +
 +<code act>
 +import "gates.act";
 +
 +defproc select (bool x0[8], x1[8]; bool y[8], z[8])
 +{
 +    pint i;
 +    i = 0;
 +    *[ i < 8 -> x0[i] = y[i]; x1[i] = z[i];
 +                x0[i+1] = z[i+1]; x1[i+1] = y[i+1];
 +                i = i + 2;
 +    ]
 +}                  
 +</code>