This is an old revision of the document!


Alternate Buffer

We start with the previous definition of a templated buffer:

template<pint N>
defproc buffer (chan?(int) L; chan!(int) R)
{
   one_place_buffer b[N];
   (i : N-1 : b[i].R = b[i+1].L;)
   b[0].L = L;
   b[N-1].R = R;
}

In this version, we used the = operation to connect channels to each other. There are other ways this can be done, and here we describe the syntax for a number of different options that achieve the same result in terms of creating a FIFO.

Using auxillary variables

We can create an array of size N-1 to correspond to the internal channels between the N buffers.

template<pint N>
defproc buffer (chan?(int) L; chan!(int) R)
{
   one_place_buffer b[N];
   chan(int) ch[N-1];
   (i : N-1 : b[i].R = ch[i];)
   (i : N-1 : b[i+1].L = ch[i];)
   b[0].L = L;
   b[N-1].R = R;
}

This can be re-written as follows:

template<pint N>
defproc buffer (chan?(int) L; chan!(int) R)
{
   one_place_buffer b[N];
   chan(int) ch[N-1];
   (i : 1 .. N-1 : b[i].L = ch[i-1]; b[i].R = ch[i]; )
   b[0].L = L; b[0].R = ch[0];
   b[N-1].L = ch[N-2]; b[N-1].R = R;
}