Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| intro_example:loops [2020/06/17 03:25] – created prafull | intro_example:loops [2025/08/24 16:48] (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. | ||
| - | < | + | < |
| import " | import " | ||
| Line 15: | Line 17: | ||
| ( i : 8 : fa[i](a[i], b[i], c[i], s[i], c[i+1]); | ( i : 8 : fa[i](a[i], b[i], c[i], s[i], c[i+1]); | ||
| } | } | ||
| + | </ | ||
| + | |||
| + | In this example we assume that '' | ||
| + | <code act> | ||
| + | defproc fulladder (bool? a, b, ci; bool! s, co) | ||
| + | { ... } | ||
| </ | </ | ||
| Line 21: | Line 29: | ||
| Here are different ways of writing the same loop using another variant of signal connection. | Here are different ways of writing the same loop using another variant of signal connection. | ||
| - | < | + | < |
| (i : 8 : fa[i].a=a[i]; | (i : 8 : fa[i].a=a[i]; | ||
| </ | </ | ||
| - | < | + | |
| + | This version makes all the connections to the ports explicitly using the connection syntax. Since it is common to connect a number of ports to the same circuit in close proximity in the ACT file, the following syntax is also supported. | ||
| + | |||
| + | < | ||
| (i : 8 : fa[i](.a=a[i], | (i : 8 : fa[i](.a=a[i], | ||
| </ | </ | ||
| An instance of this adder is then created in a separate file as: | An instance of this adder is then created in a separate file as: | ||
| - | < | + | < |
| import “adder8b.act”; | import “adder8b.act”; | ||
| Line 69: | Line 80: | ||
| The example below shows how selection statement is used for conditional execution. | The example below shows how selection statement is used for conditional execution. | ||
| - | < | + | < |
| import " | import " | ||
| Line 81: | Line 92: | ||
| </ | </ | ||
| - | Depending on the value of index '' | + | Depending on the value of index '' |
| - | ====== | + | ====== |
| - | For a hierarchical design with many imported libraries, it could be useful | + | The parenthesis-based syntax is a compact way to describe simple loop-based replication. If a more complex approach |
| - | < | + | < |
| - | $ adepend adder8b.act | + | import "gates.act"; |
| - | adder8b.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; | ||
| + | ] | ||
| + | } | ||
| </ | </ | ||
| - | Here, running adepend on '' | + | |