Parameterized design using templates

Template provides a good way to create a parameterized design framework which can be used to get customized design from a generic design based on user input. ACT supports templates to create parameterized types, channel, and processes.

Let’s revisit the ripple carry adder designed in previous example. Instead of designing adder with fixed bit-width, a generic N-bit adder can be created using template keyword as shown below:

import "adder.act";
template<pint N>
defproc adderNb (bool? a[N],b[N],ci; bool! s[N],co)
  bool c[N+1];
  fulladder fa[N];
  c[0] = ci;
  co = c[N];
  ( i : N : fa[i](a[i], b[i], c[i], s[i], c[i+1]);)  

This example imports adder.act which contains full adder and generates a ripple carry adder using loop. Note that parameter N is used here to specify bit-width of the adder.

As shown below, an arbitrary bit-width adder can be created by instantiating the process adderNb with different values of parameter N.

adderNb<8> fa8;

This creates an 8-bit adder with instance name fa8. Similarly, a 32-bit adder could be created by instantiating adder with parameter N = 32.